1

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

Traceback (most recent call last):
 File "/home/user/android-imx-sources/.repo/repo/main.py", line 40, in <module>
from subcmds.version import Version
File "/home/user/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

4

1 回答 1

3

那应该是:

raise SyntaxError('%s/%s does not define class %s' % (__name__, py, clsn))
于 2013-06-29T09:45:44.187 回答