繁体   English   中英

python脚本有什么问题?

[英]What's wrong in python script?

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

这是有关如何读取回溯的快速演练。 很简单

  • 查看您的代码,所有代码都在调用Python内置模块。 可以os.system地说,它们并不是引起错误的原因,所以剩下的唯一事情就是os.system调用。 果然,您正在通过上述调用来调用python (为什么不导入要调用的模块呢?)。

  • 追溯确认错误在于您正在调用的其他Python中:

     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 

您去了那里,错误在main.py第14行中,您应该在其中缩进但没有缩进。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM