【发布时间】:2011-10-23 06:03:32
【问题描述】:
python 脚本有什么问题?
代码:
import os
import shutil
import getpass
os.mkdir("C:\\dtmp")
shutil.copy("C:\\path\\to\\bb-freeze-script.py","C:\\dtmp")
os.chdir("C:\\dtmp")
shutil.copy("C:\\path\\to\\main.py","C:\\dtmp")
os.system("python bb-freeze-script.py main.py")
os.mkdir("C:\\Program Files\\Directories v0.6")
os.chdir("C:\\")
shutil.rmtree("C:\\dtmp")
print getpass.getuser()
错误:
Traceback (most recent call last):
File "bb-freeze-script.py", line 8, in <module>
load_entry_point('bbfreeze==0.97.3', 'console_scripts', 'bb-freeze')()
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\__init__.py", line 24, in main
f.addScript(x)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\freezer.py", line 410, in addScript
s = self.mf.run_script(path)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\modulegraph\modulegraph.py", line 241, in run_script
co = compile(file(pathname, READ_MODE).read()+'\n', pathname, 'exec')
File "C:\dtmp\main.py", line 14
^
IndentationError: expected an indented block
操作系统 -- Windows XP
【问题讨论】:
-
main.py 脚本中出现错误(缩进错误)。可以发一下代码吗?
-
是的,这是 main.py 脚本中的错误
-
代码: import os, sys class Directory(): def Create(self): dir = raw_input("Folder name: ") os.mkdir(dir) print "Created" def Delete(self) : dir = raw_input("文件夹名称:") os.rmdir(dir) print "Deleted" def exit():
-
仅供参考,将冷冻机脚本编写为可从命令行调用的 Python 模块会更好/更好/更好,因为那时您可以
import bb_freeze并使用您将编写的 API那里。从 Python 代码调用 Python 代码实际上不应该通过os.system来完成。 -
您不应在路径中使用反斜杠(正斜杠适用于包括 Windows 在内的所有系统)。如果你想保留它们,至少使用原始字符串 (´r'C:\something'´) 而不是转义狂欢 (´'C:\\something'´)
标签: python windows-xp main indentation