0
最近,我試着去熟悉打開和寫入功能。我遇到了如下問題:我使用一個腳本在名爲「config.py」的文件中寫入email = [email protected]
。這是使用下面的代碼完成:(所有敏感信息已被取代)導入和打印變量的問題
email = raw_input("What is your email? ")
f = open("config.py","w") #opens file
f.write("email = '{}'".format(email))
f.close() #This needs to be here else the file won't save
然後我嘗試在一個單獨的腳本,看起來像這樣導入和開放config.py:
import config
print email
然而,我收到此錯誤信息:
Traceback (most recent call last):
File "/Users/MyUser/Desktop/untitled folder/Savetests/savetest_loading.py", line 1, in <module>
import config
File "/Users/MyUser/Desktop/untitled folder/Savetests/config.py", line 1
email = [email protected]
^
SyntaxError: invalid syntax
我試過用引號編寫文件,但是這會與.format()產生衝突。我正在使用python 2.7
我的問題是我該怎麼做?
謝謝
用戶