我想从一个文件中复制文本并将文本写入另一个fi

2024-09-27 23:16:15 发布

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

fob = open("LISA designshpe.txt", "r+")

foc = open ("n.txt","w+")
s = fob.readlines()

fob.close()

for a in s :

    line =foc.write( a )

foc.close()

Tags: intxtforcloselineopenwritelisa
2条回答

只需使用writelines()

foc.writelines(s)

应与Python 2.7及更高版本配合使用:

with open("infilename") as infile, open("outfilename", 'w') as outfile:
  # outfile.write(infile.read()) # read entire file at once
  outfile.writelines(line for line in infile) # read file line by line

或者只是复制文件:

^{pr2}$

参考文献:

相关问题 更多 >

    热门问题