繁体   English   中英

Python34语法错误?

[英]Python34 syntax error?

我在外壳中输入了python 它给我NameError:名称“ python”未定义

而且我已经阅读了readme.txt并找不到名为PCBuild /的目录,并且我也尝试着访问python网站,也许是目录问题,我非常确定它在我的C:\\Python34路径中,这个错误是结果

好的,我正在尝试完成我的ipad(学习编程:编码教程)上的课程,希望能获得证书,但是他显示的视频使用python 2.x,文档中缺少某些内容。 谁能帮我在2.x版和3.4版中输入python有什么区别,在3.4版中我也不能输入python,它表示语法无效

Python 3.4.0rc1 (v3.4.0rc1:5e088cea8660, Feb 11 2014, 05:54:25) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> python3.4
SyntaxError: invalid syntax
>>> set path=%path;C:\python34
SyntaxError: invalid syntax
>>> python
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module> python
NameError: name 'python' is not defined
>>> Python
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module> Python
NameError: name 'Python' is not defined

您实际上非常接近:您正在尝试在python shell中执行python解释器。 那不管用。

“ >>>”是python提示符(或python shell的提示符)。

您可以使用它执行python代码,但不能执行python解释器:-)

Python 3.3.2+ (default, Oct  9 2013, 14:50:09) 
[GCC 4.8.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello")
hello
>>> 

print("hello")是python代码的示例

NameError已经是来自python解释器的消息。

您可以像现在一样在交互模式下使用Python解释器,也可以使用脚本名称调用python interprteter,脚本将被执行:

python myscript.py

尝试

 set path=%path%;C:\python34 

(即一个额外的百分号)

pythonpython3.4等应在命令行 (而不是Python shell)中键入。 它们是Python Shell可执行文件的别名。

您将按以下方式使用它们(在Linux上):

$ python /home/path/to/script.py

上面的命令将执行Python脚本script.py

或者,您可以执行以下操作:

$ python

启动Python Shell本身。

您已经在python shell中。 现在,您应该开始执行有效的python命令。 不幸的是, python不是有效的python命令。

如果要键入exit() ,则应返回到开始时使用的shell。 然后,您可以重新输入python以返回python shell。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM