【发布时间】:2014-12-06 09:43:47
【问题描述】:
我正在尝试编写一个 python 脚本,它可以让我将 C 代码直接写入文本文件并将其扩展名更改为“.c”,而无需我手动创建一个。这就是我到目前为止所做的..
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 行。 我怎样才能让它写多行?
【问题讨论】:
标签: python python-2.7 input text-files raw-input