Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试运行程序时出现语法错误?_Python - Fatal编程技术网

Python 尝试运行程序时出现语法错误?

Python 尝试运行程序时出现语法错误?,python,Python,python新手。当我使用教程中的命令时,我经常遇到这种语法错误 >>> ls Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'ls' is not defined >>> python cupp.py -i File "<stdin>", line

python新手。当我使用教程中的命令时,我经常遇到这种语法错误

>>> ls
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'ls' is not defined
>>> python cupp.py -i
  File "<stdin>", line 1
    python cupp.py -i
           ^
SyntaxError: invalid syntax
>>> ls
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'ls' is not defined
>>> print("Books")
Books
>>ls
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
NameError:未定义名称“ls”
>>>python-cupp.py-i
文件“”,第1行
python-cupp.py-i
^
SyntaxError:无效语法
>>>ls
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
NameError:未定义名称“ls”
>>>印刷品(“书籍”)
书

“打印”命令可以工作,但除此之外没有其他功能。我已经在谷歌上搜索了这个错误的一些解释,但没有用。有什么建议或教程链接我应该遵循?谢谢。

您正在运行的shell命令(
ls
)不是python命令。要在python中列出目录,请执行以下操作: `导入操作系统

os.listdir(路径)
`

Shell命令在python Shell中不起作用。Python代码会的。我想教程给我的是shell命令,而不是Python命令。在什么上下文中可以使用shell命令?我想运行程序cupp.py,教程说只需键入“python cupp.py”就行了,但它不起作用。请将python shell与常规shell(终端)分开。ls或python cups.py等命令是从终端运行的。Python代码是从Python shell或.py文件运行的,在终端中使用
Python file.py
命令谢谢,我正在阅读有关Python shell的内容。关于如何将pythonshell与常规shell分离,您有什么信息吗?或者,如果你能指导我如何做,这将是非常感激的教程,谢谢你的终端是默认的外壳。所有的命令都在那里使用。当您在终端中键入
Python
时,pythonshell将启动,并且通常会显示>>>,而终端不会显示。这是一种了解您当前正在编写哪个shell的简单方法