[SOLVED] detecting newline character

2011-04-24 Thread Thomas 'PointedEars' Lahn
Daniel Geržo wrote: > On 23.4.2011 21:18, Thomas 'PointedEars' Lahn wrote: >> Daniel Geržo wrote: >>> [f = codecs.open(…, mode='rU', encoding='ascii') and f.newlines] >> >> […] >> The only reason I can think of for this not working ATM comes from the >> documentation, where it says that 'U' requir

Re: detecting newline character

2011-04-24 Thread Thomas 'PointedEars' Lahn
Daniel Geržo wrote: > Thomas 'PointedEars' Lahn wrote: >> It is clear now that codecs.open() would not support universal newlines >> from at least Python 2.6 forward as it is *documented* that it opens >> files in *binary mode* only. The source code that I have posted shows >> that it therefore a

Re: detecting newline character

2011-04-24 Thread Daniel Geržo
On 24.4.2011 11:19, Thomas 'PointedEars' Lahn wrote: It is clear now that codecs.open() would not support universal newlines from at least Python 2.6 forward as it is *documented* that it opens files in *binary mode* only. The source code that I have posted shows that it therefore actively remov

Re: detecting newline character

2011-04-24 Thread Thomas 'PointedEars' Lahn
Daniel Geržo wrote: > On 24.4.2011 9:05, jmfauth wrote: >> Use the io module. > > For the record, when I use io.open(file=self.path, mode="rt", > encoding=enc)) as fobj: > > my tests are passing and everything seems to work fine. > > That indicates there is a bug with codecs module and universa

Re: detecting newline character

2011-04-24 Thread Daniel Geržo
On 24.4.2011 9:05, jmfauth wrote: Use the io module. For the record, when I use io.open(file=self.path, mode="rt", encoding=enc)) as fobj: my tests are passing and everything seems to work fine. That indicates there is a bug with codecs module and universal newline support. -- S pozdrav

Re: detecting newline character

2011-04-24 Thread Daniel Geržo
On 23.4.2011 21:18, Thomas 'PointedEars' Lahn wrote: Daniel Geržo wrote: I need to detect the newline characters used in the file I am reading. For this purpose I am using the following code: def _read_lines(self): with contextlib.closing(codecs.open(self.path, "rU")) as fobj:

Re: detecting newline character

2011-04-24 Thread jmfauth
On 23 avr, 22:25, Daniel Geržo wrote: > > Well I am doing this on: > Python 2.7.1 (r271:86832, Mar  7 2011, 14:28:09) > [GCC 4.2.1 (Apple Inc. build 5664)] on darwin > > So what do you guys advise me to do? > > -- Use the io module. jmf -- http://mail.python.org/mailman/listinfo/python-list

Re: detecting newline character

2011-04-23 Thread Thomas 'PointedEars' Lahn
Daniel Geržo wrote: > Thomas 'PointedEars' Lahn wrote: >> Chris Rebert wrote: >>> Daniel Geržo wrote: [f.newlines is None after f.readlines() when f = codecs.open(…, mode='rU', encoding='ascii'), but not when f = codecs.open(…, mode='rU')] >>> >>> […] >>> I would speculate that th

Re: detecting newline character

2011-04-23 Thread Daniel Geržo
On 23.4.2011 21:33, Thomas 'PointedEars' Lahn wrote: Chris Rebert wrote: On Sat, Apr 23, 2011 at 11:09 AM, Daniel Geržo wrote: I need to detect the newline characters used in the file I am reading. For this purpose I am using the following code: def _read_lines(self): with contextlib.cl

Re: detecting newline character

2011-04-23 Thread Thomas 'PointedEars' Lahn
Chris Rebert wrote: > On Sat, Apr 23, 2011 at 11:09 AM, Daniel Geržo wrote: >> I need to detect the newline characters used in the file I am reading. >> For this purpose I am using the following code: >> >> def _read_lines(self): >> with contextlib.closing(codecs.open(self.path, "rU")) as fob

Re: detecting newline character

2011-04-23 Thread Thomas 'PointedEars' Lahn
Daniel Geržo wrote: > I need to detect the newline characters used in the file I am reading. > For this purpose I am using the following code: > > def _read_lines(self): > with contextlib.closing(codecs.open(self.path, "rU")) as fobj: > fobj.readlines() > if isinstance(fobj

Re: detecting newline character

2011-04-23 Thread Chris Rebert
On Sat, Apr 23, 2011 at 11:09 AM, Daniel Geržo wrote: > Hello guys, > > I need to detect the newline characters used in the file I am reading. For > this purpose I am using the following code: > > def _read_lines(self): >    with contextlib.closing(codecs.open(self.path, "rU")) as fobj: >        f

detecting newline character

2011-04-23 Thread Daniel Geržo
Hello guys, I need to detect the newline characters used in the file I am reading. For this purpose I am using the following code: def _read_lines(self): with contextlib.closing(codecs.open(self.path, "rU")) as fobj: fobj.readlines() if isinstance(fobj.newlines, tuple):