Re: [Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 7:56 PM, Sander Sweers wrote: > On Tue, 2009-09-22 at 18:04 -0400, Kent Johnson wrote: >> > def reader(fobject, encoding='UTF-8'): >> >    '''Read a fileobject with specified encoding, defaults UTF-8.''' >> >    r = codecs.getreader(encoding) >> >    data = r(fobject) >> >

Re: [Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Sander Sweers
On Tue, 2009-09-22 at 18:04 -0400, Kent Johnson wrote: > > def reader(fobject, encoding='UTF-8'): > >'''Read a fileobject with specified encoding, defaults UTF-8.''' > >r = codecs.getreader(encoding) > >data = r(fobject) > >return data > > > > I would call it like reader(urllib2.url

Re: [Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Kent Johnson
On Tue, Sep 22, 2009 at 5:04 PM, Sander Sweers wrote: > Hello Tutors, Because a website was giving me issues with unicode > character I created a function to force the encoding. I am not sure it > is the correct way to handle these things. > > def reader(fobject, encoding='UTF-8'): >    '''Read a

[Tutor] urllib2, read data with specific encoding

2009-09-22 Thread Sander Sweers
Hello Tutors, Because a website was giving me issues with unicode character I created a function to force the encoding. I am not sure it is the correct way to handle these things. def reader(fobject, encoding='UTF-8'): '''Read a fileobject with specified encoding, defaults UTF-8.''' r = co