0

hello I'm trying to slice one document and append it to another and i'm unsure as to what I'm doing #wrong. Please let me know what you think the problem is.

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()
K.Mat
  • 1,341
  • 11
  • 17
Edison
  • 3
  • 1

1 Answers1

1

This should do it:

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])