簡體   English   中英

Python:文件換行

[英]Python: File new line

我有一個問題。 我想為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只是以字符串形式寫入。 請更正我的代碼,並告訴我我的錯誤:)

您可能要使用正確的轉義符

"\n"

代替

"/n"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM