[Discuss] A question for the Python gurus

Brian Quinlan brian at sweetapp.com
Mon Jul 31 14:42:32 PDT 2006


Adam Parkin wrote:
> Exact entire Python script:
> 
> [snipped]

OK, I didn't realize that it was a toy program that didn't have a large 
number of required semantics. That being said, I would write the program 
(not semantically identical, but more logical IMHO):

while 1:
     try:
         line = raw_input("Enter a line: ")
     except EOFError:
         break
     print "You entered %r" % line


I'd probably also display instructions in the prompt text on how to 
break out and make a more user-friendly way than hitting ctrl-D/Z.

>> What is the length of your line? 100 characters, 1000? So you are 
>> incurring ~3K of overhead. Oh no!
> 
> Okay, I'll bite and play devils advocate: what if you're processing a 
> very large file where each line is 50 MB long, then now you're incurring 
> 100MB of overhead. =8-p
 >
> Thoughts like "lines will never be more than X bytes long" are awfully 
> close to "640K will be enough for anybody" and we all remember the 
> implications of that assumption in the DOS world right?

Actually, I assumed that you actually knew the maximum line length. If 
you don't (and this weren't a toy problem) then reading a complete line 
would we stupid in any language. Maybe Python would only accommodate 
200MB lines while C would accommodate 600MB lines (in some other
example - in this example they would have the same memory limitations).

Cheers,
Brian


More information about the Discuss mailing list