Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python Shell中使用2to3?_Python_Python 2to3 - Fatal编程技术网

如何在Python Shell中使用2to3?

如何在Python Shell中使用2to3?,python,python-2to3,Python,Python 2to3,我想在shell中导入2to3.py,但它一直在说SyntaxError >>> site.addsitedir('/Python27/Tools/Scripts/') >>> sys.path ['C:\\Senti\\ltpservice', 'C:\\Python27\\Lib\\idlelib', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\li

我想在shell中导入2to3.py,但它一直在说SyntaxError

>>> site.addsitedir('/Python27/Tools/Scripts/')
>>> sys.path
['C:\\Senti\\ltpservice', 'C:\\Python27\\Lib\\idlelib', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\Tools\\Scripts']
>>> import 2to3
SyntaxError: invalid syntax

我该怎么办?

您正在尝试导入以数字开头的内容:

>>> import 1sdjkhl
  File "<stdin>", line 1
    import 1sdjkhl
           ^
SyntaxError: invalid syntax
>>> 

要使用2to3,如果您是windows用户,只需在DOS命令提示符下转到-\python27\2.7\Tools\Scripts>。在提示符处,键入:“python2to3.py”、“-w”,然后键入文件所在的目录。例如:C:\Users\Leeman\python27\2.7\Tools\Scripts>python2to3.py C:/practice/py2folder/py2file.py。如果将2to3.py添加到环境变量的路径中,则键入的内容可能会缩短为:python 2to3.py-w c:/practice/py2folder/py2file.py。如果要转换整个文件夹和子文件夹,请键入:python 2to3.py-w c:/practice/py2folder/

谁说该模块称为“2to3”?这是生成的脚本的名称。模块不能以数字字符开头。调用了
2to3
后面的库,但在python程序中使用它应该没有太多理由。另外,它的API是不稳定的。thx,但我仍然有一个问题。在cmd行中,我仍然有一个语法错误。$^2to3 example1.py语法错误:无效syntax@user2870222不是在交互式解释器中,而是在shell(即在cmd行中键入
python
)中,我得到了我想要的结果,“python2to3.py-wc:\python27\example.py”。但是,我仍然不知道如何在Python Shell中调用2to3。我是否需要只键入“$2to3 example1.py”而不导入任何其他模块?@user2870222只需键入
2to3 example1.py
我在答案中输入的
$
就可以显示您在shell中键入它
$ 2to3 myscript.py