f.seek() unwanted output

Tim Chase python.list at tim.thechases.com
Mon Jan 5 15:13:30 CET 2009


> I'm having trouble with a script that is printing the output of f.seek
> () 
[snip]
> I have a file in memory.
> when i try f.seek(0) #or any other value in f.tell()
> it gives me 0 as output:
> 
> the following script illustrates my 'problem'
>>>> for a in range(10):
> 	f.seek(a)
> 
> 
> 0
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9

You're seeing an artifact of the command-line (evidenced by your 
">>>" before your command).  Just like

   int("42")

returns output...the Python console prints the output while a 
script (saved to the disk) doesn't.

Try putting your test in foo.py and running that -- you'll notice 
that it doesn't echo back the numbers as you describe.

The behavior seems to vary.  In my Python2.4, seek() for 
file/cStringIO/StringIO objects returns None with each. 
Whichever version (or object-type) you're using seems to return 
its input offset as its output.

-tkc







More information about the Python-list mailing list