Problem writing some strings (UnicodeEncodeError)
Paulo da Silva
p_s_d_a_s_i_l_v_a at netcabo.pt
Sun Jan 12 10:36:11 EST 2014
Hi!
I am using a python3 script to produce a bash script from lots of
filenames got using os.walk.
I have a template string for each bash command in which I replace a
special string with the filename and then write the command to the bash
script file.
Something like this:
shf=open(bashfilename,'w')
filenames=getfilenames() # uses os.walk
for fn in filenames:
...
cmd=templ.replace("<fn>",fn)
shf.write(cmd)
For certain filenames I got a UnicodeEncodeError exception at
shf.write(cmd)!
I use utf-8 and have # -*- coding: utf-8 -*- in the source .py.
How can I fix this?
Thanks for any help/comments.
More information about the Python-list
mailing list