我在ipynb
文件中有密码作为变量。
如何在python的帮助下以编程方式为新密码更改此密码?
我已经尝试了以下方法,但是没有用:
with open("file.ipynb", "r") as initial_file:
text = initial_file.read()
text.replace('passwordone', 'passwordtwo')
with open("file.ipynb", "w") as new_file:
new_file.write(text)
答案 0 :(得分:1)
将文本变量分配为新值
with open("file.ipynb", "r") as initial_file:
text = initial_file.read()
text = text.replace('passwordone', 'passwordtwo')
with open("file.ipynb", "w") as new_file:
new_file.write(text)