例如,我的程序的settings.ini文件包含:
theme=white
SaveDirectory=C:\Screenshots
我是这样读的:
with open("settings.ini", "r") as settings:
setting = settings.readlines()
theme = setting[0]
theme = theme[len("theme="):].strip()
bg = theme
print(theme)
SaveDirectory = setting[1]
SaveDirectory = SaveDirectory[len("SaveDirectory="):].strip()
print(SaveDirectory)
settings.close()
但是我知道当我的.ini变长时,这很糟糕且风险很大。我需要一个用它们的开头读取行的函数。喜欢:function("theme=")
。 python3有类似的东西吗?