这是为什么发生?为什么意外缩进?
def LoadPackageList():
try:
#Attempts to load package list... Adds each neccessary attribute into array
print("Loading Package List... please wait")
packages = []
packagelisturl = os.getcwd() + "packages.list"
dom = minidom.parse(urllib.urlopen(packagelisturl))
try:
for eachattributeofpkglist in dom.GetElementsByTagNameNS(packagelist, 'packages'):
packages.append({
'title': node.getAttribute('title'),
'shortname': node.getAttribute('shortname'),
'dlurl': node.getAttributes('dlurl'),
'description': node.getAttributes('description'),
'tags': node.getAttributes('tags'),
'infopage': node.getAttributes('infopage'),
'quality': node.getAttributes('quality'),
'id': node.getAttributes('id')
})
except LoadPackageListFailed:
print("Loading Package List failed... try again soon or manually update this release!")
Write2ErrorLog(LoadPackageListFailed)
#Indent Here Fails
def Usage():
#prints usage and closes
print ("Invalid Argument Specified, please retry using the format stated below\n")
print ("*** Simtho Usage Parameters ***\n")
print ("-i Installs Local App, include full path")
print ("-u Uninstalls Installed App,include ID or Name")
print ("-l Lists all installed Apps and their ID")
print ("-a Lists All Apps in Repository")
print ("-s Downloads and Installs App from repository, enter the title or id number")
print ("-w Downloads and Installs Single App from a full link")
print ("-r Removes All Packages installed\n")
print ("*** End of Simtho Usage ***")
os._exit(1)
return;
缩进的位置究竟是什么?你能展示实际的产出和你的期望吗? – Rory
尝试通过显示空白的东西运行它。在* nix机器上,使用'od -c yourfile.py'来查看字符。这可能是有用的,虽然可能有更好的方法来做到这一点。 – Ibrahim
如果您还没有弄清楚,请复制上面的代码并粘贴到您自己的代码上面,它应该可以解决问题。如果没有,问题不在上面的代码中,而是在相邻的地方,正如〜unutbu建议的那样。 –