首页 > 解决方案 > 尝试在第 71 行运行 reindent.py 时出错

问题描述

尝试从 Windows 10 命令提示符运行 reindent 命令时,出现以下错误:

C:\Users\ianpo\renpy-7.3.5-sdk\projects\test\game>python -m reindent script.rpy
Traceback (most recent call last):
  File "C:\Users\ianpo\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 184, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\Users\ianpo\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 154, in _get_module_details
    code = loader.get_code(mod_name)
  File "<frozen importlib._bootstrap_external>", line 916, in get_code
  File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\ianpo\AppData\Local\Programs\Python\Python38\lib\site-packages\reindent.py", line 71
    except getopt.error, msg:
                       ^
SyntaxError: invalid syntax

任何关于这里发生的事情的线索都将非常感激。我对 Python 和 Windows 很陌生,所以请像我是个傻瓜一样回答。我尝试使用 pip 重新安装并确保添加了选项标志。第七行导致错误。

def main():
    import getopt
    global verbose, recurse, dryrun, makebackup
    try:
        opts, args = getopt.getopt(sys.argv[1:], "drnvh",
                        ["dryrun", "recurse", "nobackup", "verbose", "help"])
    except getopt.error, msg:
        usage(msg)
        return
    for o, a in opts:
        if o in ('-d', '--dryrun'):
            dryrun += 1
        elif o in ('-r', '--recurse'):
            recurse += 1
        elif o in ('-n', '--nobackup'):
            makebackup = False
        elif o in ('-v', '--verbose'):
            verbose += 1
        elif o in ('-h', '--help'):
            usage()
            return
    if not args:
        r = Reindenter(sys.stdin)
        r.run()
        r.write(sys.stdout)
        return
    for arg in args:
        check(arg)

标签: pythonwindows

解决方案


所以问题与 pip 安装的 reindent 版本过时有关,该版本与当前的 python 不兼容。如果其他人遇到同样的问题,请转到此处获取文件的最新版本。


推荐阅读