我已经分别使用notepad ++和text-wrangler在win pc和mac osx上建立了我的编程环境。在这两台计算机上,我都设置了python34-> lib-> site-packages的快捷方式/别名,这样我就可以从解释器提示符中快速导入我的程序。在获胜的PC我已经包含在环境变量路径这一行:python程序导入并运行后,变量持续存在于IDLE但不是在cmd(win)或终端(osx)
C:\ Python34; C:\ Python34 \ Scripts中; C:\ Python34 \ LIB \站点包
这使我的访问蟒蛇3.4从CMD 在OSX终端我只需输入python3启动解释
这一切的伟大工程运行,我在教科书努力通过,但为什么它在进口模块中的变量似乎是小的代码示例只是暂时的?而在IDLE中,如果我打开相同的文件并运行 变量仍然可以识别。
例如
test.py
word = 'pizza'
print(
'''
Slicing "Cheat Sheet"
0 1 2 3 4 5
+---+---+----+----+----+
| p | i | z | z | a |
+---+---+----+---+-----+
-5 -4 -3 -2 -1
'''
)
print ('Enter the beginning and ending index for your slice of "pizza".')
print ('Press the enter key at the "Begin" to exit.')
start = ''
while start == '':
start = (input('\nStart: '))
if start:
start = int(start)
finish = int(input('Finish: '))
print('word [', start, ':', finish, '] is', end=' ')
print(word[start:finish])
input ('\n\nPress the enter key to exit.')
在CMD或终端导入此运行的代码。但给
nameerror名称在提示输入变量单词后比萨饼‘“word'is不处于空闲模块已经在可变字将得到分配表达运行打字后定义
而’。为什么是这样?
您应该使用'python -i test.py'来运行脚本,然后在Python的shell中与结果进行交互。 – eryksun
另外,从'PATH'中删除'site-packages'目录。在该目录中不应该有脚本,只有通过Python的sys.path找到的模块。 – eryksun
python -i test.py不起作用。返回'无法打开文件test.py:[Errno 2]没有这样的文件或目录。 –