python命令行模式的用法及流程

作者:小妮浅浅 时间:2022-05-01 17:31:13 

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 代码却不会。

来源:https://www.py.cn/jishu/jichu/33622.html

标签:python,命令行模式
0
投稿

猜你喜欢

  • 基于Jquery+Ajax+Json的高效分页实现代码

    2024-05-21 10:12:19
  • python中requests模块的使用方法

    2021-12-27 23:16:29
  • PyTorch深度学习模型的保存和加载流程详解

    2023-07-10 04:58:33
  • Python3读取UTF-8文件及统计文件行数的方法

    2022-06-03 15:02:45
  • 浅谈Python xlwings 读取Excel文件的正确姿势

    2021-10-15 23:33:36
  • python模拟登录百度贴吧(百度贴吧登录)实例

    2023-11-20 14:30:56
  • Python 函数装饰器应用教程

    2022-08-17 05:53:24
  • python自定义线程池控制线程数量的示例

    2022-12-25 15:16:13
  • 浅谈python numpy中nonzero()的用法

    2021-09-23 00:06:01
  • 详解Python 装饰器执行顺序迷思

    2023-12-30 23:55:23
  • switchery按钮的使用方法

    2024-04-29 13:40:44
  • 用js判断页面刷新或关闭的方法(onbeforeunload与onunload事件)

    2024-04-30 08:55:07
  • python flask搭建web应用教程

    2023-05-14 14:16:17
  • 英文罚抄引发的艺术创意

    2008-05-13 12:02:00
  • 用Python采集《雪中悍刀行》弹幕做成词云实例

    2021-05-04 15:24:28
  • tensorflow 查看梯度方式

    2022-11-07 12:46:22
  • Vue登录拦截 登录后继续跳转指定页面的操作

    2024-05-28 15:48:14
  • 如何将HTML字符转换为DOM节点并动态添加到文档中详解

    2023-08-23 12:26:39
  • Python实现简单的语音识别系统

    2022-09-11 04:44:15
  • Python实现自动发消息自定义内容的操作代码

    2023-10-17 18:01:53
  • asp之家 网络编程 m.aspxhome.com