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
我的问题是我该怎么做?
谢谢
用户