Python:文件new lin

2024-04-29 04:36:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我有个问题。我想为python编写一个自动编译器,但我对python太陌生了,以至于我甚至不知道如何编写多行文件。 我试过了:

import os
pythonversion = str(input("Pythonversion [no '.']:"))
exename = str(input("Programname:"))
exeversion = str(input("Programversion:"))
exedescription = str(input ("Programdescription:"))
exeoldname = str(input("Programs python file [name.py]:"))
content1 = "from cx_Freeze import setup, Executable"
content2 = 'setup( name = "'+exename+'" , version = "'+exeversion+'", description ="'+exedescription+'" , executables = [Executable("'+exeoldname+'")] , )'
file = open("c:\Python"+pythonversion+"\setup.py","w")
file.write(str(content1))
file.write("/n")
file.write(str(content2))
file.close()

但是它没有工作,/n只是作为字符串写入。请更正我的代码,并告诉我我的错误:)


Tags: namepyimportinputsetupfilewriteexecutable