Need help with file object

Christopher Welborn cjwelborn at live.com
Fri Dec 13 05:54:13 CET 2013


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 <cjwelborn at live.com>
   http://welbornprod.com




More information about the Python-list mailing list