python 3.x - Writing cp1252/uft-8/latin-1 ??? from python3 -


i have data special accent characters i'm reading in fine, , processing fine. if print them, , can , copy/paste results console output -- i'd rather write results file read later. example:

data = ''' <imdb> lego movie (2014) - pg <imdb> [lemony snicket's] series of unfortunate events (2004) - pg <imdb> les misérables (1998) - pg-13 <imdb> les misérables (2012) - pg-13 <imdb> les misérables in concert (1995) - nr <imdb> license wed (2007) - pg-13 <imdb> life know (2010) - pg-13 <imdb> life of pi (2012) - pg ''' tgt = open('output.txt','w',encoding='utf-8') x in data.split('\n'):     res = lookupimdbindex(x)     print(res)     tgt.write(res)     tgt.write('\n') 

the console output looks like:

<tt1490017> lego movie (2014) - pg <tt0339291> [lemony snicket's] series of unfortunate events (2004) - pg <tt0119683> les misérables (1998) - pg-13 <tt1707386> les misérables (2012) - pg-13 <tt0113637> les misérables in concert (1995) - nr <tt0762114> license wed (2007) - pg-13 <tt1055292> life know (2010) - pg-13 <tt0454876> life of pi (2012) - pg 

while contents of output.txt like:

<tt1490017> lego movie (2014) - pg <tt0339291> [lemony snicket's] series of unfortunate events (2004) - pg <tt0119683> les misérables (1998) - pg-13 <tt1707386> les misérables (2012) - pg-13 <tt0113637> les misérables in concert (1995) - nr <tt0762114> license wed (2007) - pg-13 <tt1055292> life know (2010) - pg-13 <tt0454876> life of pi (2012) - pg 

this has unicode magic or something, i'm sure, can't seem figure out. i've searched here , internet in general , haven't found -- perhaps it's obvious, it's plum evading me.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -