Re: Need help with file object
On 12/12/2013 11:29 PM, Unix SA wrote: ... With above prog I am getting error TypeError: coercing to Unicode: need sting or buffer, file found In future please copy and paste the entire traceback. It appears that you typed in just one line of it. In this case the line raising the exception was obvious, but often it is not. -- https://mail.python.org/mailman/listinfo/python-list
Re: Need help with file object
On 12/12/2013 10:29 PM, Unix SA wrote: 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 You are sending the actual file objects to shutil.move, it is expecting a string. Actually, strings containing the path to move and the destination. Like this: shutil.move('/tmp/file2', '/tmp/file1') -- - Christopher Welborn cjwelb...@live.com http://welbornprod.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Need help with file object
On Friday, December 13, 2013 9:59:25 AM UTC+5:30, Unix SA wrote: s=open('/tmp/file2') snipped s.write(line) Among other things you are missing a write mode (2nd optional argument to open) http://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files -- https://mail.python.org/mailman/listinfo/python-list
Re: Need help with file object
In mailman.4047.1386908972.18130.python-l...@python.org Unix SA d.josh...@gmail.com writes: 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. -- John Gordon Imagine what it must be like for a real medical doctor to gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'. -- https://mail.python.org/mailman/listinfo/python-list