0
Iam試圖編寫一個python腳本,它可以讓我直接將C代碼寫入文本文件並將其擴展名更改爲「.c」,而無需手動創建。這是我到目前爲止..通過在python中輸入將多行寫入文本文件?
import time as t
from os import path
def create_C(dest):
date=t.localtime(t.time()) #getting current system date
name=raw_input("Enter file name:")+"%d_%d_%d"%(date[0],date[1],date[2])+".c"
#User enters the filename
if not(path.isfile(dest+name)): #checks if the file already exists
f=open(dest+name,"w")
f.write(raw_input("Start Writting:\n"))
f.close()
if __name__=='__main__':
destination='C:\\Users\\Dell\\Desktop\\Puru\
\\python\\intermediate\\createCfile\\'
create_C(destination)
raw_input("done")
但是,這隻寫1行。 我怎樣才能得到它寫多行?
謝謝,你能還解釋一點點在這裏發生** file_content ='\ n'.join(iter(raw_input,''))** – purudpd 2014-12-06 10:51:44
我添加了一個解釋。 @PurusharthDwivedi – 2014-12-06 11:40:54