0
f = open("open","rw")
w = open("write","w")

def fonk():
    c = ""
    a = f.readline().decode('utf-8')
    for line in f:
        b = line.decode('utf-8')
        splitted = line.split()     
        w.write("'"+splitted[4:]+"'"+",")

fonk()

I want to read words of file called "open" and write it to another file called "write". I can write the 4th character but I want to write 4 and more in this case I get the error on the title. What should I do?

1
  • "'" string, splitted[4:] list. try w.write("'"+''.join(splitted[4:])+"'"+",") Commented Mar 18, 2015 at 12:01

1 Answer 1

2

Try this:

w.write("'"+''.join(splitted[4:])+"'"+",")

Because you are trying string and list concatanation. This is not allowed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.