我想将数据附加到我的file.config
。我还使用linux,它将请求对文件的任何配置的权限。在终端中,我可以写入sudo nano file.config
并进行更改。
期望值:my file.cofig看起来像这样
#
#info ...
#
#
[Section]
#info
I want to append data right here to the end of the file
我尝试使用configparser
模块:
configparser = configparser.ConfigParser()
configparser['Section'] = {'data':'123'}
configFilePath = '/etc/file.conf'
with open(configFilePath, 'a') as file_conf:
configparser.write(file_conf)
这会将信息添加为字典,而不是常规文件.txt
#
#info ...
#
#
[Section]
#info
[Section]
data = 123
按照评论中的要求:需要sudo python3 file.py(visual studio未处于su模式)
目前没有回答
相关问题 更多 >
编程相关推荐