【发布时间】:2020-03-13 14:43:01
【问题描述】:
我想在另一个文件中更改字典中的值。 File1.py 包含编辑字典的代码,File2.py 包含字典本身。
File1.py 正在生成代码以仅替换 BTOK 值。
文件1.py:
with open('file2.py', 'r') as file :
filedata = file.read()
print (filedata.str(BTK['btk1']))
for line in filedata:
line['btk1'] = BTok
with open('file2.py', 'w') as file:
file.write(line)
文件2.py:
c = {
'id' : 'C80e3ce43c3ea3e8d1511ec',
'secret' : 'c10c371b4641010a750073925b0857'
}
rk = {
't1' : 'ZTkwMGE1MGEt',
}
BTK = {
'BTok' : '11eyJhbGc'
}
【问题讨论】:
-
问题不清楚,能否详细说明?想要将
11eyJhbGc替换为 file2.py 中的其他值吗? -
抱歉,我只想在 file2 中替换 BTok 的值。所以我的 file1 我有一些代码可以生成一个新密钥,然后我想在 BTOK 密钥下替换 file2 中的那个密钥
标签: python python-3.x python-3.7