我不能 运行 在 windows 10 的 cmd 中或在 kali linux 的终端中的 .py 文件
I cannot run a .py file in cmd on windows 10, or in the terminal in kali linux
让我们首先说我是 python 和编程的完全新手,但我真的很想学习,所以如果您可以尝试使用初学者会理解的术语,那将对我有很大帮助。
好的 在谷歌搜索如何在 kali Linux 中使用 python 无法 运行 那里的文件变得非常沮丧之后,我在我的 Windows 10 OS 上下载了它然后我做了一个基本的脚本,看起来像
#! /usr/bin/python
a = 122
b = 344
print a + b
很简单吧。将其保存为 math.py 并进入 cmd 提示符(因为 wikki 如何告诉我)然后输入数学 py 的位置:
cd C:\Users\Mitchel\Documents
我在这里看到了一个问题,告诉我使用 cd 来输入位置。 python 回复:
File "<stdin>", line 1
cd C:\Users\Mitchel\Documents
^
语法错误:语法无效
所以我决定无论如何都要尝试下一步,然后输入
python math.py
并得到同样的错误。我尝试双击该文件,尝试 "open with" 并单击 python。我想知道我可以在记事本或记事本++中键入代码并在开始之前对其进行测试,因为在命令提示符本身中实际编写代码真的很难。
这些是在系统命令提示符下输入的命令,但您是在 Python 解释器中输入它们。大多数教程都假定您知道如何绕过系统的终端。请参阅下面的演示。
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\TigerhawkT3>cd
C:\Users\TigerhawkT3
C:\Users\TigerhawkT3>cd ..
C:\Users>py -c "print(1+2)"
3
C:\Users>py
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> cd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cd' is not defined
>>> cd ..
File "<stdin>", line 1
cd ..
^
SyntaxError: invalid syntax
>>> py -c "print(1+2)"
File "<stdin>", line 1
py -c "print(1+2)"
^
SyntaxError: invalid syntax
>>> print(1+2)
3
>>>
让我们首先说我是 python 和编程的完全新手,但我真的很想学习,所以如果您可以尝试使用初学者会理解的术语,那将对我有很大帮助。 好的 在谷歌搜索如何在 kali Linux 中使用 python 无法 运行 那里的文件变得非常沮丧之后,我在我的 Windows 10 OS 上下载了它然后我做了一个基本的脚本,看起来像
#! /usr/bin/python
a = 122
b = 344
print a + b
很简单吧。将其保存为 math.py 并进入 cmd 提示符(因为 wikki 如何告诉我)然后输入数学 py 的位置:
cd C:\Users\Mitchel\Documents
我在这里看到了一个问题,告诉我使用 cd 来输入位置。 python 回复:
File "<stdin>", line 1
cd C:\Users\Mitchel\Documents
^
语法错误:语法无效
所以我决定无论如何都要尝试下一步,然后输入
python math.py
并得到同样的错误。我尝试双击该文件,尝试 "open with" 并单击 python。我想知道我可以在记事本或记事本++中键入代码并在开始之前对其进行测试,因为在命令提示符本身中实际编写代码真的很难。
这些是在系统命令提示符下输入的命令,但您是在 Python 解释器中输入它们。大多数教程都假定您知道如何绕过系统的终端。请参阅下面的演示。
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\TigerhawkT3>cd
C:\Users\TigerhawkT3
C:\Users\TigerhawkT3>cd ..
C:\Users>py -c "print(1+2)"
3
C:\Users>py
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> cd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cd' is not defined
>>> cd ..
File "<stdin>", line 1
cd ..
^
SyntaxError: invalid syntax
>>> py -c "print(1+2)"
File "<stdin>", line 1
py -c "print(1+2)"
^
SyntaxError: invalid syntax
>>> print(1+2)
3
>>>