切片并附加 python
Slice and appending with python
你好,我正在尝试将一个文档切片并将其附加到另一个文档,但我不确定我在做什么#wrong。请让我知道您认为问题出在哪里。
f = open("nameAddress.txt", "r")
g = open("name.txt", "a+")
line_count = 0
for line in f:
line_count += 1
for line in f:
firstSpace = line.find(' ')
newName = line(0, firstSpace)
g.write(newData)
f.close()
g.close()
应该这样做:
with open('nameAddress.txt','r') as f, open('name.txt','a') as g:
f = f.read().split('\n')
for line in f:
g.write(line.split(' ')[0])
你好,我正在尝试将一个文档切片并将其附加到另一个文档,但我不确定我在做什么#wrong。请让我知道您认为问题出在哪里。
f = open("nameAddress.txt", "r")
g = open("name.txt", "a+")
line_count = 0
for line in f:
line_count += 1
for line in f:
firstSpace = line.find(' ')
newName = line(0, firstSpace)
g.write(newData)
f.close()
g.close()
应该这样做:
with open('nameAddress.txt','r') as f, open('name.txt','a') as g:
f = f.read().split('\n')
for line in f:
g.write(line.split(' ')[0])