Re: EOF while scanning triple-quoted string literal

2010-10-16 Thread Grant Edwards
On 2010-10-16, Steven D'Aprano wrote: > On Fri, 15 Oct 2010 20:07:37 +, Grant Edwards wrote: > >> Nor I, which is why I was confused by the statement that in the "Unix >> world" a lot of programs misbehaved when presented with files whose >> names contained a null byte. > > That's not what I s

Re: EOF while scanning triple-quoted string literal

2010-10-16 Thread Steven D'Aprano
On Fri, 15 Oct 2010 20:07:37 +, Grant Edwards wrote: > Nor I, which is why I was confused by the statement that in the "Unix > world" a lot of programs misbehaved when presented with files whose > names contained a null byte. That's not what I said. I said, TRY to create a file with a null by

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Grant Edwards
On 2010-10-15, Martin Gregorie wrote: > On Fri, 15 Oct 2010 19:59:13 +, Grant Edwards wrote: > >> >> We're talking about Unix. >> We're not talking about CP/M, DOS, RSX-11m, Apple-SOS, etc. > > That's just your assumption. If you go back and look at my original posting in this thread, here's

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Martin Gregorie
On Fri, 15 Oct 2010 19:59:13 +, Grant Edwards wrote: > > We're talking about Unix. > We're not talking about CP/M, DOS, RSX-11m, Apple-SOS, etc. > That's just your assumption. Track back up the thread and you'll see that the OP didn't mention an OS. He merely said that he was using zlib, and

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Grant Edwards
On 2010-10-15, Chris Torek wrote: >>> On 2010-10-15, Grant Edwards wrote: How do you create a [Unix] file with a name that contains a NULL byte? > >>On 2010-10-15, Seebs wrote: >>> So far as I know, in canonical Unix, you don't -- the syscalls all work >>> with something like C strings unde

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Grant Edwards
On 2010-10-15, Seebs wrote: > On 2010-10-15, Grant Edwards wrote: >> Yes, all of the Unix syscalls use NULL-terminated path parameters >> (AKA "C strings"). What I don't know is whether the underlying >> filesystem code also uses NULL-terminated strings for filenames or if >> they have explicit

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Grant Edwards
On 2010-10-15, Martin Gregorie wrote: >> On 2010-10-15, Martin Gregorie wrote: >>> On Fri, 15 Oct 2010 17:02:07 +, Grant Edwards wrote: On 2010-10-15, Steven D'Aprano : > In the Unix world, which includes OS X, text tools tend to have > difficulty with tabs. Or try naming a

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Chris Torek
>> On 2010-10-15, Grant Edwards wrote: >>> How do you create a [Unix] file with a name that contains a NULL byte? >On 2010-10-15, Seebs wrote: >> So far as I know, in canonical Unix, you don't -- the syscalls all work >> with something like C strings under the hood, meaning that no matter what >

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Seebs
On 2010-10-15, Grant Edwards wrote: > Yes, all of the Unix syscalls use NULL-terminated path parameters (AKA > "C strings"). What I don't know is whether the underlying filesystem > code also uses NULL-terminated strings for filenames or if they have > explicit lengths. If the latter, there migh

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Martin Gregorie
On Fri, 15 Oct 2010 18:14:13 +, Grant Edwards wrote: > On 2010-10-15, Martin Gregorie wrote: >> On Fri, 15 Oct 2010 17:02:07 +, Grant Edwards wrote: >> >>> On 2010-10-15, Steven D'Aprano >>> wrote: >>> In the Unix world, which includes OS X, text tools tend to have difficulty

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Grant Edwards
On 2010-10-15, Seebs wrote: > On 2010-10-15, Grant Edwards wrote: >> On 2010-10-15, Steven D'Aprano wrote: >>> In the Unix world, which includes OS X, text tools tend to have >>> difficulty with tabs. Or try naming a file with a newline or carriage >>> return in the file name, or a NULL byte. >

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Seebs
On 2010-10-15, Grant Edwards wrote: > On 2010-10-15, Steven D'Aprano wrote: >> In the Unix world, which includes OS X, text tools tend to have >> difficulty with tabs. Or try naming a file with a newline or carriage >> return in the file name, or a NULL byte. > How do you create a file with a n

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Grant Edwards
On 2010-10-15, Martin Gregorie wrote: > On Fri, 15 Oct 2010 17:02:07 +, Grant Edwards wrote: > >> On 2010-10-15, Steven D'Aprano >> wrote: >> >>> In the Unix world, which includes OS X, text tools tend to have >>> difficulty with tabs. Or try naming a file with a newline or carriage >>> retu

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Martin Gregorie
On Fri, 15 Oct 2010 17:02:07 +, Grant Edwards wrote: > On 2010-10-15, Steven D'Aprano > wrote: > >> In the Unix world, which includes OS X, text tools tend to have >> difficulty with tabs. Or try naming a file with a newline or carriage >> return in the file name, or a NULL byte. > > How do

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Grant Edwards
On 2010-10-15, Steven D'Aprano wrote: > In the Unix world, which includes OS X, text tools tend to have > difficulty with tabs. Or try naming a file with a newline or carriage > return in the file name, or a NULL byte. How do you create a file with a name that contains a NULL byte? -- Grant E

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Ian
On Oct 14, 10:30 pm, Lawrence D'Oliveiro wrote: > In message , Rhodri James wrote: > > > ... frankly putting arbitrary binary into a literal string is rather > > asking for something like this to come and bite you. > > It normally works fine on sensible OSes. Which OSes would those be? It doesn'

Re: EOF while scanning triple-quoted string literal

2010-10-15 Thread Steven D'Aprano
On Fri, 15 Oct 2010 17:30:20 +1300, Lawrence D'Oliveiro wrote: > In message , Rhodri James wrote: > >> ... frankly putting arbitrary binary into a literal string is rather >> asking for something like this to come and bite you. > > It normally works fine on sensible OSes. What does it have to d

Re: EOF while scanning triple-quoted string literal

2010-10-14 Thread Lawrence D'Oliveiro
In message , Rhodri James wrote: > ... frankly putting arbitrary binary into a literal string is rather > asking for something like this to come and bite you. It normally works fine on sensible OSes. -- http://mail.python.org/mailman/listinfo/python-list

Re: EOF while scanning triple-quoted string literal

2010-10-11 Thread Ian Kelly
On Mon, Oct 11, 2010 at 3:59 PM, Rhodri James wrote: > On Mon, 11 Oct 2010 10:37:09 +0100, bussiere bussiere > wrote: > > > i've looked on the web and here but i didn't find an answer : here is my >> code >> >> zlib.decompress(""" >> xワᆳヤ=ラᄇHナs~Ʀᄑç\ムîà >> z...@ÑÁÔqÇlxÇÆïpp >> ~ýVãì゙M6ÛÐ|ê֭ᄁᄂヤ=)}

Re: EOF while scanning triple-quoted string literal

2010-10-11 Thread Rhodri James
On Mon, 11 Oct 2010 10:37:09 +0100, bussiere bussiere wrote: i've looked on the web and here but i didn't find an answer : here is my code zlib.decompress(""" xワᆳヤ=ラᄇHナs~Ʀᄑç\ムîà z...@ÑÁÔqÇlxÇÆïpp~ývãì゙m6ÛÐ|ê֭ᄁᄂヤ=)}éÓUe﬿ö3ᄎᄌú"}ʿïÿ÷1þ8ñ́U÷ᄏñíLÒVi:`ᄈᄎL!Ê҆p6-%Fë^ヘ÷à,Q.K!ユô`ÄA!ÑêweÌ ÊÚAロYøøÂjôóᅠÂcñ

Re: EOF problem with ENTER

2009-06-12 Thread Jean-Michel Pichavant
Prasoon wrote: I modified my code to #Euler Totient Function import sys from math import sqrt def etf(n): i,res =2,n while(i*i<=n): if(n%i==0): res-=res/i while(n%i==0): n/=i i+=1 if(n>1): res-=res/n return res def main(): while Tr

Re: EOF problem with ENTER

2009-06-12 Thread Prasoon
> You could do: > > while True: >    x = raw_input("Enter x=>") >    if x != "" : break # if you just press enter, raw_input returns an > empty string > > Note that this still leaves out the case when you type something which > is not a number. > To cover this case, supposing that you need a float

Re: EOF problem with ENTER

2009-06-12 Thread Francesco Bochicchio
On 12 Giu, 08:49, Prasoon wrote: > On Jun 12, 11:28 am, Chris Rebert wrote: > > > > > > > On Thu, Jun 11, 2009 at 11:17 PM, Prasoon wrote: > > > I am new to python > > > I have written the following program in python.It is the solution of > > > problem ETF in SPOJ. > > > > #Euler Totient

Re: EOF problem with ENTER

2009-06-11 Thread Prasoon
On Jun 12, 11:28 am, Chris Rebert wrote: > On Thu, Jun 11, 2009 at 11:17 PM, Prasoon wrote: > > I am new to python > > I have written the following program in python.It is the solution of > > problem ETF in SPOJ. > > > #Euler Totient Function > > > from math import sqrt > > def etf(n): > >

Re: EOF problem with ENTER

2009-06-11 Thread Prasoon
On Jun 12, 11:28 am, Chris Rebert wrote: > On Thu, Jun 11, 2009 at 11:17 PM, Prasoon wrote: > > I am new to python > > I have written the following program in python.It is the solution of > > problem ETF in SPOJ. > > > #Euler Totient Function > > > from math import sqrt > > def etf(n): > >

Re: EOF problem with ENTER

2009-06-11 Thread Chris Rebert
On Thu, Jun 11, 2009 at 11:17 PM, Prasoon wrote: > I am new to python > I have written the following program in python.It is the solution of > problem ETF in SPOJ. > > > #Euler Totient Function > > from math import sqrt > def etf(n): >   i,res =2,n >   while(i*i<=n): >      if(n%i==0): >  

Re: EOF

2008-08-24 Thread Anjanesh Lekshminarayanan
Thanks for the shutil.copyfileobj. Oddly, the EOFError didnt work though. Gabriel Genellina wrote: En Fri, 22 Aug 2008 16:53:58 -0300, Wojtek Walczak <[EMAIL PROTECTED]> escribió: On Fri, 22 Aug 2008 22:18:37 +0530, Anjanesh Lekshminarayanan wrote: Im trying to download a file from a

Re: EOF

2008-08-24 Thread Gabriel Genellina
En Fri, 22 Aug 2008 16:53:58 -0300, Wojtek Walczak <[EMAIL PROTECTED]> escribió: > On Fri, 22 Aug 2008 22:18:37 +0530, Anjanesh Lekshminarayanan wrote: > >> Im trying to download a file from a server. But how do I detect EOF ? > > Whenever read() method returns empty string/list. > > >> while f1:

Re: EOF

2008-08-22 Thread Eric Wertman
>> Im trying to download a file from a server. But how do I detect EOF ? Shouldn't this work as well? f1 = urllib2.urlopen('ftp://username:[EMAIL PROTECTED]/data.zip') f2 = file("data.zip", "wb") while f1: # When to stop ? try : f2.write(f1.read(1024)) except EOFError : b

Re: EOF

2008-08-22 Thread Wojtek Walczak
On Fri, 22 Aug 2008 22:18:37 +0530, Anjanesh Lekshminarayanan wrote: > Im trying to download a file from a server. But how do I detect EOF ? Whenever read() method returns empty string/list. > while f1: # When to stop ? retval = f1.read() if not retval: break f2.write(ret

Re: eof

2007-12-08 Thread jjnoakes
On Nov 24, 12:03 am, MonkeeSage <[EMAIL PROTECTED]> wrote: > > class open(file): > def __init__(self, name): > self.size = os.stat(name).st_size > file.__init__(self, name) > def eof(self): > return self.tell() == self.size > > f = open('tmp.py') > print f.eof() # False > f.read() >

Re: eof

2007-12-08 Thread jjnoakes
On Nov 22, 10:37 am, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > > def read(self, size=None): > if size is None: > val = file.read(self) > self.eof = True > else: > val = file.read(self, size) > if len(val) < size: > self.eof = True

Re: eof

2007-11-26 Thread Boris Borcic
ZeD wrote: > Grant Edwards wrote: > >> The user-defined xor is operates on "logical" boolean values. >> The one in the operator module is a bitwise operator. > > def xor(a, b): > return bool(a) ^ bool(b) > > seems more explicit to me. > maybe, to make "more" explicit (too much, onestly...) >

Re: eof

2007-11-26 Thread ZeD
Grant Edwards wrote: > The user-defined xor is operates on "logical" boolean values. > The one in the operator module is a bitwise operator. def xor(a, b): return bool(a) ^ bool(b) seems more explicit to me. maybe, to make "more" explicit (too much, onestly...) from operator import xor as b

Re: eof

2007-11-26 Thread Grant Edwards
On 2007-11-26, Boris Borcic <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: >> def xor(a, b): >> return a and not b or b and not a > > > >>> from operator import xor > >>> help(xor) > Help on built-in function xor in module operator: > > xor(...) > xor(a, b) -- Same as a ^ b. Which

Re: eof

2007-11-26 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > def xor(a, b): > return a and not b or b and not a >>> from operator import xor >>> help(xor) Help on built-in function xor in module operator: xor(...) xor(a, b) -- Same as a ^ b. -- http://mail.python.org/mailman/listinfo/python-list

setting attributes on external types (was Re: eof)

2007-11-24 Thread samwyse
On Nov 23, 2:06 am, greg <[EMAIL PROTECTED]> wrote: > There's a fair amount of overhead associated with providing > the ability to set arbitrary attributes on an object, which > is almost never wanted for built-in types, so it's not > provided by default. > > You can easily get it if you want it by

Re: eof

2007-11-23 Thread greg
Dennis Lee Bieber wrote: > Pascal I/O worked with a "one element preread", where what we'd > consider a read operation was performed by the open operation -- which > made console I/O a royal pain Yep. Later implementations reduced the pain somewhat by using a "lazy" scheme which deferred the

Re: eof

2007-11-23 Thread MonkeeSage
On Nov 23, 10:43 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > This is not the same as ISO C. f.tell could be equal to > File.size(f.path) and eof could be false. An extra read() is required. My bad. As you might have surmised, I'm not a genius when it comes to C. I thought that the eof f

Re: eof

2007-11-23 Thread [EMAIL PROTECTED]
On Nov 24, 2:24 am, MonkeeSage <[EMAIL PROTECTED]> wrote: > > Actually, to be a bit more technical, IO#eof acts like standard C eof > for File objects, it only blocks / requires a previous read() on > character devices and pipes and such. For files, it's the same as > checking the absolute position

Re: eof

2007-11-23 Thread MonkeeSage
On Nov 23, 10:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Ruby doesn't have the good ol' eof. Good old eof tests a single flag > and requires a pre read(). Ruby's eof blocks and does buffering (and > this is a very strong technical statement). Actually, to be a bit more technical, IO

Re: eof

2007-11-23 Thread [EMAIL PROTECTED]
On Nov 22, 1:17 pm, braver <[EMAIL PROTECTED]> wrote: > Ruby has iterators and generators too, but it also has my good ol' > f.eof(). I challenge the assumption here of some majectically Python- Ruby doesn't have the good ol' eof. Good old eof tests a single flag and requires a pre read(). Ruby'

Re: eof

2007-11-23 Thread MonkeeSage
On Nov 23, 6:56 pm, greg <[EMAIL PROTECTED]> wrote: > By not providing an eof() function, C -- and Python -- make > it clear that testing for eof is not a passive operation. > It's always obvious what's going on, and it's much harder to > make mistakes like the above. err...C has feof() in stdio

Re: eof

2007-11-23 Thread greg
braver wrote: > Historically, is it possible to trace the eof-related design decision > in stdlib? You seem to be assuming that someone started out with a design that included an eof() of the kind you want, and then decided to remove it. But I doubt that such a method was ever considered in the f

Re: eof

2007-11-23 Thread Neil Cerutti
On 2007-11-23, braver <[EMAIL PROTECTED]> wrote: > Can we say that f.eof() in fact can check for EOF right after > we've read all characters from a file, but before a failed > attempt to read beyond? In Python's idiom, > > for line lin file: ># look at a line ># we can tell eof occurs righ

Re: eof

2007-11-23 Thread braver
On Nov 22, 8:04 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > I think Python is well rid of such a seldomly useful source of > confusion. So all that code folks wrote in Algol-like languages, -- e.g. this works in Ada, -- while not End_of_File(f) loop -- end if; -- are confusing? Why not int

Re: eof

2007-11-23 Thread MonkeeSage
On Nov 22, 11:04 am, Neil Cerutti <[EMAIL PROTECTED]> wrote: > I think it's too low level, and so doesn't do what naive users > expect. It's really only useful, even in C, as part of the > forensic study of a stream in an error state, [...] Indeed. I just wrote a little implementation of an IPS p

Re: eof

2007-11-23 Thread greg
Hendrik van Rooyen wrote: > So he can't even help himself by setting his > own EOF attribute to False initially, and > to True when he sees an empty string. > > Is there a reason for this Bondage style? There's a fair amount of overhead associated with providing the ability to set arbitrary attri

Re: eof

2007-11-22 Thread Neil Cerutti
On 2007-11-22, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > "Diez B. Roggisch" <[EMAIL PROTECTED]> writes: > Language comparisons are sometimes good. They are best when they are free of FUD. >>> >>> So why Python's IO cannot yield f.eof() as easily as Ruby's can? :) >> >> Because that requ

Re: eof

2007-11-22 Thread Thomas Bellman
Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > I don't get it, Python's files are implemented on top of stdio FILE > objects, which do buffering and provide EOF checking (of the sort > where you can check if a previous read hit the EOF, but still). Why > not export that functionality? Alexy wants to

Re: eof

2007-11-22 Thread braver
On Nov 22, 6:40 pm, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote: > You yourself said that performance is a complaint of yours regarding Ruby, so > why claim that Ruby's way is clearly better in a case where it causes a known > performance hit? See Hrvoje's remark above -- we can have EOF and e

Re: eof

2007-11-22 Thread Hrvoje Niksic
braver <[EMAIL PROTECTED]> writes: > On Nov 22, 6:10 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> Granted, they aren't part of the stdlib - but then, lots >> of things aren't. > > As Hendrik noticed, I can't even add my own f.eof() if I want to > have buffering -- is that right? You can,

Re: eof

2007-11-22 Thread J. Clifford Dyer
On Thu, Nov 22, 2007 at 07:17:41AM -0800, braver wrote regarding Re: eof: > > On Nov 22, 6:08 pm, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote: > > > > So why Python's IO cannot yield f.eof() as easily as Ruby's can? :) > > > Because that&#x

Re: eof

2007-11-22 Thread Hrvoje Niksic
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes: >>> Language comparisons are sometimes good. They are best when >>> they are free of FUD. >> >> So why Python's IO cannot yield f.eof() as easily as Ruby's can? :) > > Because that requires buffering, something that affects speed. I don't get it, Py

Re: eof

2007-11-22 Thread braver
On Nov 22, 6:10 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Granted, they aren't part of the stdlib - but then, lots > of things aren't. As Hendrik noticed, I can't even add my own f.eof() if I want to have buffering -- is that right? The tradeoff between speed and convenience is somethin

Re: eof

2007-11-22 Thread braver
On Nov 22, 6:08 pm, "J. Clifford Dyer" <[EMAIL PROTECTED]> wrote: > > So why Python's IO cannot yield f.eof() as easily as Ruby's can? :) > Because that's not how you compare languages. You compare languages by > stating what you are actually trying to do, and figuring out the most natural >

Re: eof

2007-11-22 Thread Diez B. Roggisch
braver schrieb: > On Nov 22, 5:32 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: >>> There's nothing special about Python except indentation, which >>> gets screwed up between editors all the time. (It's much >>> easier to flip- flop between TextMate and Emacs with Ruby than >>> with Python, without

Re: eof

2007-11-22 Thread J. Clifford Dyer
On Thu, Nov 22, 2007 at 06:53:59AM -0800, braver wrote regarding Re: eof: > > > Language comparisons are sometimes good. They are best when > > they are free of FUD. > > So why Python's IO cannot yield f.eof() as easily as Ruby's can? :) Because that's

Re: eof

2007-11-22 Thread braver
On Nov 22, 5:32 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > > There's nothing special about Python except indentation, which > > gets screwed up between editors all the time. (It's much > > easier to flip- flop between TextMate and Emacs with Ruby than > > with Python, without setting your tabs

Re: eof

2007-11-22 Thread Boris Borcic
Duncan Booth wrote: > Nice, thank you. Welcome. > But why 'count(chunksize)' rather than just 'count()'? To number the first chunk 1, etc. using count() starts with 0. Matter of taste. > Does it make a difference anywhere? And I'd recommend using // rather than > / otherwise it breaks if you

Re: eof

2007-11-22 Thread Neil Cerutti
On 2007-11-22, braver <[EMAIL PROTECTED]> wrote: > On Nov 22, 10:37 am, Wayne Brehaut <[EMAIL PROTECTED]> wrote: >> As others have already pointed out, "because it's seldom >> necessary in Python". > > You know what? I've read this many times, and it's a lot of > self- congratulation. There's lot

Re: eof

2007-11-22 Thread Duncan Booth
Boris Borcic <[EMAIL PROTECTED]> wrote: > Duncan Booth wrote: >> import itertools >> def chunks(f, size): >> iterator = iter(f) >> def onechunk(line): >> yield line >> for line in itertools.islice(iterator, size-1): >> yield line >> for line in iterator: >>

Re: eof

2007-11-22 Thread Boris Borcic
> def chunked(chunksize,f) : > from itertools import count,groupby > counter=count(chunksize).next > return groupby(f,lambda _ : counter()/chunksize) And more to the point, no "yield" for Alexy to mock :) -- http://mail.python.org/mailman/listinfo/python-list

Re: eof

2007-11-22 Thread Boris Borcic
Duncan Booth wrote: > import itertools > def chunks(f, size): > iterator = iter(f) > def onechunk(line): > yield line > for line in itertools.islice(iterator, size-1): > yield line > for line in iterator: > yield onechunk(line) Quite simpler, and pro

Re: eof

2007-11-22 Thread braver
On Nov 22, 3:26 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > This sounds like a case for writing a generator. Try this one: [...] Thanks, Duncan! Really cool & useful. And yield is the Ruby way, too! (Wayne -- :P). Cheers, Alexy -- http://mail.python.org/mailman/listinfo/python-list

Re: eof

2007-11-22 Thread Duncan Booth
braver <[EMAIL PROTECTED]> wrote: > In many cases, you want to do this: > > for line in f: > > if line % 1000 == 0 or f.eof(): # eof() doesn't exist in Python > yet! > > > My control logic summarizes every 1000 lines of a file. I have to > issue the summary after each 1000 lin

Re: eof

2007-11-22 Thread braver
On Nov 22, 5:08 am, I V <[EMAIL PROTECTED]> wrote: > On Wed, 21 Nov 2007 17:06:15 -0800, braver wrote: > It looks like ruby internally buffers the stream itself, which is how > come it can support this. According to the docs: > > "Note that IO#eof? reads data to a input buffer." > > http://www.ruby

Re: eof

2007-11-22 Thread braver
On Nov 22, 10:37 am, Wayne Brehaut <[EMAIL PROTECTED]> wrote: > As others have already pointed out, "because it's seldom necessary in Python". You know what? I've read this many times, and it's a lot of self- congratulation. There's lot of things which can be useful in Python. This lack of EOF

Re: eof

2007-11-22 Thread Hendrik van Rooyen
"braver" <[EMAIL PROTECTED]> wrote: > Well folks compare scripting languages all the time, and surely Ruby > is closer to Python than C++. Since Ruby can do f.eof, which is > easily found in its references, and Python can't, or its EOF can't > easily be found -- the one *equivalent* to a semanti

Re: eof

2007-11-21 Thread Wayne Brehaut
On Wed, 21 Nov 2007 17:06:15 -0800 (PST), braver <[EMAIL PROTECTED]> wrote: >On Nov 22, 3:41 am, Wayne Brehaut <[EMAIL PROTECTED]> wrote: >> If you have PythonWin 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 >> 32 bit (Intel)] on win32.for example, using Help, Index, eof gives: >> 8< ===

Re: eof

2007-11-21 Thread Steven D'Aprano
On Wed, 21 Nov 2007 15:17:14 -0800, braver wrote: > I'd like to check, for a filehandle f, that EOF has been reached on it. > What's the way to do it? I don't want to try/except on EOF, I want to > check, after I read a line, that now we're in the EOF state. Why? For some file-like objects, the

Re: eof

2007-11-21 Thread I V
On Wed, 21 Nov 2007 17:06:15 -0800, braver wrote: > Why do I have to count sizes of lines read and compare it to some > filesize or do other weird tricks just to see, in a way not changing my > input stream, whether it's at the, well, EOF? Because you can't, generally, tell whether or not a stream

Re: eof

2007-11-21 Thread Neil Cerutti
On 2007-11-21, braver <[EMAIL PROTECTED]> wrote: > I'd like to check, for a filehandle f, that EOF has been reached on > it. What's the way to do it? I don't want to try/except on EOF, I > want to check, after I read a line, that now we're in the EOF state. > In Ruby it's f.eof: > > In Ruby: >>>

Re: eof

2007-11-21 Thread braver
On Nov 22, 3:41 am, Wayne Brehaut <[EMAIL PROTECTED]> wrote: > If you have PythonWin 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 > 32 bit (Intel)] on win32.for example, using Help, Index, eof gives: > > eof > Token used to determine end of file. This will be set to the empty > string ('')

Re: eof

2007-11-21 Thread Wayne Brehaut
Hi braver, On Wed, 21 Nov 2007 15:17:14 -0800 (PST), braver <[EMAIL PROTECTED]> wrote: >I'd like to check, for a filehandle f, that EOF has been reached on >it. What's the way to do it? I don't want to try/except on EOF, I >want to check, after I read a line, that now we're in the EOF state. I

Re: EOF error

2005-12-03 Thread Peter Otten
ash wrote: > hi, > when i try to unpickle a pickled file in binary format, i get this > error: > > E:\mdi>test.py > Traceback (most recent call last): > File "E:\mdi\qp.py", line 458, in OnReadButton > data=p.load(file("ques.dat","r")) > EOFError > > what is the reason? how do i overcome t

Re: EOF-file missing

2005-04-14 Thread infidel
You can use the Content-Length header to tell the server how long the string is. -- http://mail.python.org/mailman/listinfo/python-list

Re: EOF for binary?

2005-01-08 Thread flamesrock
ahh..that does make sense. But maybe getsize() should have a way of inferring what file is specified. I might actually submit a request.. -- http://mail.python.org/mailman/listinfo/python-list

Re: EOF for binary?

2005-01-08 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, flamesrock wrote: > os.path.getsize(infile) <= infile.tell() > > Because that returns the error: > # File "/usr/lib/python2.3/posixpath.py", line 142, in getsize > #return os.stat(filename).st_size > #TypeError: coercing to Unicode: need string or buffer, file found >

Re: EOF for binary?

2005-01-07 Thread flamesrock
Thanks! I don't know why, but the most innefficient and unmaintanable means of doing something usually pops into my head before anything else. I solved this by going elif len(header) < 8: break -- http://mail.python.org/mailman/listinfo/python-list

Re: EOF for binary?

2005-01-07 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "flamesrock" <[EMAIL PROTECTED]> wrote: > Hi, > > So if I understand correctly, there are NO eof characters in any binary > file. If so, is there an easier way to check for the end of the file > than: > > os.path.getsize(infile) <= infile.tell() How you detect E