当我在解释器中运行这些命令时,我得到了我想要的结果。但是,当我尝试使用.py文件运行它时,我并不这样做。我是个编程新手,在我的脑海里,我不明白为什么这个代码不能工作。
在解释器中:
>>> a = 'This dinner is not that bad!'
>>> n = a.find('not')
>>> b = a.find('bad')
>>> if n < b:
a.replace(a[n:], 'good')
'This
from subprocess import *
test = subprocess.Popen('ls')
print test
当我尝试运行这段简单的代码时,我得到一个错误窗口,提示:
WindowsError: [Error 2] The system cannot find the file specified
我不知道为什么我不能让这个简单的代码工作,这是令人沮丧的,任何帮助都会非常感谢!