我正在使用py_compile
将python文件(.py)转换为.pyc
文件
py_compile.compile(py_src_file, doraise=True)
python脚本包含同时具有python版本2.7和3.8语法的代码。
与python 3.8版本一起使用时py_compile
会为相应的2.7语法生成错误。有没有办法在编译代码时检查python版本,并只编译相应的指令
例如:
if python_version == 2.7:
# py_compile should see 2.7 code
else:
# py_compile should see 3.8 code
在这个答案中我得到了一些帮助:How would you do the equivalent of preprocessor directives in Python?,但不知道如何在我的案例中准确使用。 谢谢你的帮助
目前没有回答
相关问题 更多 >
编程相关推荐