Need help with file object

U

Unix SA

Hello,

I am facing some issue when copying or moving file

f=open('/tmp/file1')
s=open('/tmp/file2')

for line in f:
if 'match' not in line:
s.write(line)

import shutil
shutil.move(s, f)

With above prog I am getting error
TypeError: coercing to Unicode: need sting or buffer, file found

What that means and how I can resolve it.

Regards,
Dj
 
J

John Gordon

In said:
f=open('/tmp/file1')
s=open('/tmp/file2')
for line in f:
if 'match' not in line:
s.write(line)
import shutil
shutil.move(s, f)
With above prog I am getting error
TypeError: coercing to Unicode: need sting or buffer, file found
What that means and how I can resolve it.

shutil.move() expects filename arguments, not open file objects.

Also, since your open() statements are missing the file mode ('r' or 'w'),
they will both open in the default read mode.

Also, it really helps if you post the real code and real error message.
Don't type them from memory.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top