How to detect if code is python 3 compatible

后端 未结 5 994
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 16:55

I\'m doing static code analysis using openstack/bandit. Do have a lot of repositories, some of those are in python 2 other in python 3. How can I detect if code is syntactically

5条回答
  •  北荒
    北荒 (楼主)
    2021-02-01 17:42

    You can use the "compileall" module like so:

    python3.6 -m compileall -q .
    

    Modify appropriately for the python version you want to use.

    Python3 (since 3.something) puts compiled modules into a __pycache__ directory, with a arch-specific extension, so they won't conflict with Python2 or other Python3 versions.

    The given command will just show errors, and will recurse from the current directory. Use python3.6 -m compileall --help to reveal ALL the OPTIONS.

提交回复
热议问题