如何使用 python 命令执行 Python 脚本 [英] How to execute Python scripts with python command

查看:49
本文介绍了如何使用 python 命令执行 Python 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用来自 IDLE Python GUI 的 python 命令运行 Python 脚本.
该文件的位置是 C:\Users\DELL\Desktop\Hello.py
当我使用 Windows 命令提示符运行 python C:\Users\DELL\Desktop\Hello.py 时,它可以工作.但是,当我尝试使用 IDLE Python GUI 和 Python(命令行)时,它不起作用并给我一条消息 SyntaxError: invalid syntax
捕获

解决方案

在 python shell 中,你可以import 模块.这样,一旦你导入它,你就可以在shell上看到Hello".

<预><代码>>>>导入系统>>>sys.path.append('C:\Users\DELL\Desktop')>>>导入你好你好"

I want to run the Python Script by using python command from IDLE Python GUI.
The location of the file is C:\Users\DELL\Desktop\Hello.py
When I run python C:\Users\DELL\Desktop\Hello.py with Windows command promt, it works. However, when I try with IDLE Python GUI and Python (command line), it does not work and gives me a message SyntaxError: invalid syntax
Capture

解决方案

inside python shell, you can import the module. This way, you can see "Hello" printed on shell once u import it.

>>> import sys
>>> sys.path.append('C:\Users\DELL\Desktop')
>>> import Hello
"Hello"

这篇关于如何使用 python 命令执行 Python 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆