检查版本似乎不适用于Python2.7

时间:2019-12-02 02:09:46

标签: python-3.x python-2.7 compatibility

我正在修改一些python,因此编写了这个小程序,但是sys.version_info[0]似乎不适用于Python2并给我一个错误

程序:

import sys
import pdb

pdb.set_trace()

method = "first"
print "This is the " + method + " way to print stuff\n"

method = "second"
print ("This is the " + method + " way to print stuff\n")

method = "third"
print ("This is the ", method, " way to print stuff\n")

if (sys.version_info[0] > 2):
    method = "fourth"
    print(f"This is the {method} way to print stuff")

它引发的错误是:

  

回溯(最近一次通话最后一次):文件“ /usr/lib/python2.7/pdb.py”,   主线1314       pdb._runscript(mainpyfile)文件“ /usr/lib/python2.7/pdb.py”,第1233行,在_runscript中       self.run(statement)运行中的文件“ /usr/lib/python2.7/bdb.py”,第400行       exec cmd in globals,locals文件“”,第1行,文件“ WaysToPrint.py”,第17行       print(f“这是打印内容的{method}方法”)

可能是什么问题?该怎么办?

0 个答案:

没有答案