您当前的位置:首页 > IT编程 > python
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:python命令行模式的用法及流程

51自学网 2021-10-30 22:13:02
  python
这篇教程python命令行模式的用法及流程写得很实用,希望能帮到您。

1、使用cmd打开命令行窗口。

2、在输入python时,进入python交互模式。

3、输入exit(),退出交互模式,在命令行模式下运行.py程序。

实例

C:/Users/86178>python
Python 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> edit
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'edit' is not defined
>>> exit()

C:/Users/86178>python
Python 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> hello.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'hello' is not defined
>>> exit()

C:/Users/86178>python hello.pu
python: can't open file 'hello.pu': [Errno 2] No such file or directory

C:/Users/86178>python hello.py
python: can't open file 'hello.py': [Errno 2] No such file or directory

C:/Users/86178>cd /d
文件名、目录名或卷标语法不正确。

C:/Users/86178>cd /d D:

D:/>python hello.py
hello
D:/>python
Python 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> hello.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'hello' is not defined
>>>

知识点扩充:

命令行模式与python交互模式

1.在命令行模式下,可以执行 python 进入 Python 交互式环境,也可以执

行 python hello.py 运行一个.py 文件。

2.在 Python 交互式环境下,只能输入 Python 代码并立刻执行。

3.Python 交互式环境会把每一行 Python 代码的结果自动打印出来,但是,直接运行 Python 代码却不会。

到此这篇关于python命令行模式的用法及流程的文章就介绍到这了,更多相关python命令行模式的使用流程内容请搜索51zixue.net以前的文章或继续浏览下面的相关文章希望大家以后多多支持51zixue.net!


Python heapq库案例详解
Python实现堆排序案例详解
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。