简体   繁体   中英

Python raise SyntaxError

I'm cloning a repo for a specific tablet under Android and to get the sources, I've to execute a python script. When I execute it I've got this error message :

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

Full code of the script :


    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

那应该是:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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