Re: Converting text file to different encoding.

2015-04-17 Thread Peter Otten
Chris Angelico wrote: > On Sat, Apr 18, 2015 at 12:26 AM, wrote: >> I tried to do as follows, > import codecs > sourceEncoding = "iso-8859-1" > targetEncoding = "utf-8" > source = open("source1","w") > string1="String type" > str1=str(string1) > source.write(str1) >>>

Re: Converting text file to different encoding.

2015-04-17 Thread Dave Angel
On 04/17/2015 10:48 AM, Dave Angel wrote: On 04/17/2015 09:19 AM, subhabrata.bane...@gmail.com wrote: >>> target = open("target", "w") It's not usually a good idea to use the same variable for both the file name and the opened file object. What if you need later to print the name, as in

Re: Converting text file to different encoding.

2015-04-17 Thread Marko Rauhamaa
Chris Angelico : > Here's how I'd do it. > > $ python3 with open("source1", encoding="iso-8859-1") as source, >> open("target", "w", encoding="utf-8") as target: > ... target.write(source.read()) You might run out of memory. How about: ===

Re: Converting text file to different encoding.

2015-04-17 Thread Dave Angel
On 04/17/2015 09:19 AM, subhabrata.bane...@gmail.com wrote: I am having few files in default encoding. I wanted to change their encodings, preferably in "UTF-8", or may be from one encoding to any other encoding. You neglected to specify what Python version this is for. Other information tha

Re: Converting text file to different encoding.

2015-04-17 Thread Chris Angelico
On Sat, Apr 18, 2015 at 12:26 AM, wrote: > I tried to do as follows, import codecs sourceEncoding = "iso-8859-1" targetEncoding = "utf-8" source = open("source1","w") string1="String type" str1=str(string1) source.write(str1) source.close() target = op

Re: Converting text file to different encoding.

2015-04-17 Thread subhabrata . banerji
On Friday, April 17, 2015 at 7:36:46 PM UTC+5:30, Oscar Benjamin wrote: > wrote: > > On Friday, April 17, 2015 at 6:50:08 PM UTC+5:30, wrote: > >> I am having few files in default encoding. I wanted to change their > >> encodings, > >> preferably in "UTF-8", or may be from one encoding to any ot

Re: Converting text file to different encoding.

2015-04-17 Thread Oscar Benjamin
On 17 April 2015 at 14:51, wrote: > On Friday, April 17, 2015 at 6:50:08 PM UTC+5:30, subhabrat...@gmail.com > wrote: >> I am having few files in default encoding. I wanted to change their >> encodings, >> preferably in "UTF-8", or may be from one encoding to any other encoding. >> >> I was try

Re: Converting text file to different encoding.

2015-04-17 Thread subhabrata . banerji
On Friday, April 17, 2015 at 6:50:08 PM UTC+5:30, subhabrat...@gmail.com wrote: > I am having few files in default encoding. I wanted to change their > encodings, > preferably in "UTF-8", or may be from one encoding to any other encoding. > > I was trying it as follows, > >>>> import codec

Re: Converting text file to different encoding.

2015-04-17 Thread Rustom Mody
On Friday, April 17, 2015 at 6:50:08 PM UTC+5:30, subhabrat...@gmail.com wrote: > I am having few files in default encoding. I wanted to change their > encodings, > preferably in "UTF-8", or may be from one encoding to any other encoding. > > I was trying it as follows, > >>>> import codec

Converting text file to different encoding.

2015-04-17 Thread subhabrata . banerji
I am having few files in default encoding. I wanted to change their encodings, preferably in "UTF-8", or may be from one encoding to any other encoding. I was trying it as follows, >>> import codecs >>> sourceEncoding = "iso-8859-1" >>> targetEncoding = "utf-8" >>> source = open("so