Python 3.4.2 语法错误

0 投票
1 回答
930 浏览
提问于 2025-05-01 16:20

我正在尝试在Python上构建一个分发文件。
这是我的代码:

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

>>> def print_list( AList ):
        for item in AList:
           if ( isinstance( item, list )):
               print_list( item )
           else:
               print( item )

这是我的设置文件:

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

>>> from distutils.core import setup
>>> setup(name='nester', version='1.0.0', py_modules=['nester'], author='Leo')

我实际上是按照这些步骤操作的:

  1. 打开命令提示符(CMD)
  2. 进入我的文件夹:"cd c:\users......\nester"(nester是我的文件夹)
  3. 输入"c:\python34\python.exe setup.py sdist"

然后它给我抛出了一个错误:

文件 "setup.py" 第1行
Python3.4.2 (v3.4.2:ab2c023a9423, 2014年10月6日, 22:15:05) [MSC v.1600 32位 (Intel)] 在win32上
语法错误:无效的语法

所以我尝试删除了我两个文件中代码的第一行和第二行,但错误依然存在。

有人知道发生了什么吗?

谢谢你的帮助!

暂无标签

1 个回答

4

你把从Python解释器里复制的代码粘贴到了你的setup.py文件里,这样就带了一些多余的内容(解释器的状态信息)过来了:

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

请把这些多余的内容和>>>标记从你的setup.py文件里删掉。以后请注意,不能直接从解释器复制粘贴到.py文件里。

撰写回答