python打印图形为什么会空一行_python在写入fi时在第一行打印空行

我不明白为什么我的代码在向文件写入文本之前要打印一个空行。我正在做的是从一个压缩文件夹中读取两个文件,并将文本写入一个新的文本文件。我在文件中得到了预期的结果,除了文件的第一行有一个空行。def test():

if zipfile.is_zipfile(r'C:\Users\test\Desktop\Zip_file.zip'):

zf = zipfile.ZipFile(r'C:\Users\test\Desktop\Zip_file.zip')

for filename in zf.namelist():

with zf.open(filename, 'r') as f:

words = io.TextIOWrapper(f)

new_file = io.open(r'C:\Users\test\Desktop\new_file.txt', 'a')

for line in words:

new_file.write(line)

new_file.write('\n')

else:

pass

zf.close()

words.close()

f.close()

new_file.close()

在新的_文件中输出(在第一个“这是测试行…”之前有一个空行)This is a test line...

This is a test line...

this is test #2

this is test #2

有什么想法吗?

谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值