简体   繁体   English

Python:文件换行

[英]Python: File new line

I've got a problem. 我有一个问题。 I want to write an auto compiler for python, but im so fresh at python, that i dont even know how to write a file multilined. 我想为python写一个自动编译器,但是我在python上是如此新鲜,我什至不知道如何写一个多行文件。 I tried that: 我尝试过:

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()

But it didnt work, and /n got just written as string to. 但这没有用,并且/ n只是以字符串形式写入。 pls correct my code, and tell me bout my mistake :) 请更正我的代码,并告诉我我的错误:)

You may want to use the correctly escaped 您可能要使用正确的转义符

"\n"

instead of 代替

"/n"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM