2013-06-29 49 views
1

我在Android下克隆特定平板電腦的回購並獲取源代碼,我必須執行一個python腳本。當我執行它,我已經得到了這個錯誤信息:Python raise SyntaxError

Traceback (most recent call last): 
File "/home/p1rox/android-imx-sources/.repo/repo/main.py", line 40, in <module> 
from subcmds.version import Version 
File "/home/p1rox/android-imx-sources/.repo/repo/subcmds/__init__.py", line 41 
raise SyntaxError, '%s/%s does not define class %s' % (
       ^
SyntaxError: invalid syntax 

腳本的全碼:


    import os 

    all_commands = {} 

    my_dir = os.path.dirname(__file__) 
    for py in os.listdir(my_dir): 
     if py == '__init__.py': 
     continue 

     if py.endswith('.py'): 
     name = py[:-3] 

     clsn = name.capitalize() 
     while clsn.find('_') > 0: 
      h = clsn.index('_') 
      clsn = clsn[0:h] + clsn[h + 1:].capitalize() 

     mod = __import__(__name__, 
         globals(), 
         locals(), 
         ['%s' % name]) 
     mod = getattr(mod, name) 
     try: 
      cmd = getattr(mod, clsn)() 
     except AttributeError: 
      raise SyntaxError, '%s/%s does not define class %s' % (
          __name__, py, clsn) 

     name = name.replace('_', '-') 
     cmd.NAME = name 
     all_commands[name] = cmd 

    if 'help' in all_commands: 
     all_commands['help'].commands = all_commands 

回答

3

這應該是:

raise SyntaxError('%s/%s does not define class %s' % (__name__, py, clsn))