脚本不想从python sh运行

2024-04-23 18:11:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我打开C:\Python27\python.exe,我打字很干净_索引.py(这是一个位于C:\Python27中的文件)我得到:

>>> clean_index.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'clean_index' is not defined

这是怎么回事? I键入C:\Python27\clean_索引.py,同样的道理。你知道吗


Tags: 文件inpycleanmostindexstdinline
1条回答
网友
1楼 · 发布于 2024-04-23 18:11:37

使用execfile

>>>execfile('clean_index.py')

或者直接运行它(不在python shell中):

$ python clean_index.py

假设您的路径中有python。你知道吗

或者,在python shell中使用import

>>>import fibo
>>>fibo.fib(1000)
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987

the docs获取的模块导入示例。文件名是fibo.py。你知道吗

因为您可能只是想运行文件,所以我建议您使用second选项。你知道吗

相关问题 更多 >