python文件读写,不报错,没有输出结果,为什么这个可用,但另一个不可用?
这个能输出withopen(r'C:\nnn.txt')asreader,open(r'C:\new.txt','w')aswriter:forlineinreader:...
这个能输出
with open(r'C:\nnn.txt') as reader, open(r'C:\new.txt', 'w') as writer:
for line in reader:
items = line.strip().split()
print(' '.join(items[1:]), file=writer)
这个就输出不出来,只是处理了一下条件语句,是items[]不能用吗?也不报错
with open(r'C:\new.txt') as reader, open(r'C:\new2.feat', 'w') as writer:
for line in reader:
items = line.strip().split()
if (items[0]==1 or items[1]==1 or items[2]==1):
print(' '.join(items[0:]), file=writer) 展开
with open(r'C:\nnn.txt') as reader, open(r'C:\new.txt', 'w') as writer:
for line in reader:
items = line.strip().split()
print(' '.join(items[1:]), file=writer)
这个就输出不出来,只是处理了一下条件语句,是items[]不能用吗?也不报错
with open(r'C:\new.txt') as reader, open(r'C:\new2.feat', 'w') as writer:
for line in reader:
items = line.strip().split()
if (items[0]==1 or items[1]==1 or items[2]==1):
print(' '.join(items[0:]), file=writer) 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询