下面的Python代码3.6.x的上失败的Atom但不能在IDLE
问题描述:
免责声明:我是一个新的Python程序员(几小时到初级课程)下面的Python代码3.6.x的上失败的Atom但不能在IDLE
我创建了Python的3.6.3 IDLE限幅器例子并且按照预期运行。那就是:
*email = input("What's your email address ? ").strip()
user = email[:email.find("@")]
user = user.capitalize()
domain = email[email.find("@") + 1:]
domain = domain.capitalize()
output = "Your username is {} and your domain is {}".format(user,domain)
print(output)*
但是,试图在Atom中运行它时,脚本亚军包给了我以下错误:
*What's your email address ? [email protected]
Traceback (most recent call last):
File "/Users/**user**/Desktop/Scripts/MyPyScripts/slicer.py", line 9, in <module>
email = input("What's your email address ? ").strip()
File "<string>", line 1
[email protected]*
^
SyntaxError: invalid syntax
Exited with status 1 after 10.893 seconds
有没有人有一个想法?谢谢!
答
看起来Atom使用的是Python 2.x,而不是3.x. Python 2上的input
评估输入的字符串,例如字符串2+3
返回5
。在Python 2上使用raw_input
只读取一个字符串而不进行评估。
>>> input('enter email: ')
enter email: [email protected]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
[email protected]
^
SyntaxError: invalid syntax
>>> raw_input('enter email: ')
enter email: [email protected]
'[email protected]'