Python引发了SyntaxError

时间:2013-06-29 09:30:21

标签: android python

我正在为Android下的特定平板电脑克隆一个repo并获取源代码,我将执行一个python脚本。当我执行它时,我收到此错误消息:

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

1 个答案:

答案 0 :(得分:3)

应该是:

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