Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > f.seek() unwanted output

Reply
Thread Tools

f.seek() unwanted output

 
 
thomasvangurp@gmail.com
Guest
Posts: n/a
 
      01-05-2009
I'm having trouble with a script that is printing the output of f.seek
() whereas in the documentation it is quoted not to have any output:

----
file.seek(offset[, whence])¶

Set the file’s current position, like stdio‘s fseek. The whence
argument is optional and defaults to os.SEEK_SET or 0 (absolute file
positioning); other values are os.SEEK_CUR or 1 (seek relative to the
current position) and os.SEEK_END or 2 (seek relative to the file’s
end). There is no return value.
--------------

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
>>>


I don't want python to produce output when setting the file pointer.
Any help woul be appreciated.
Kind regards,
Thomas
 
Reply With Quote
 
 
 
 
Tim Chase
Guest
Posts: n/a
 
      01-05-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




 
Reply With Quote
 
 
 
 
thomasvangurp@gmail.com
Guest
Posts: n/a
 
      01-05-2009
Hi Tim,
works! thanx a lot
Thomas
 
Reply With Quote
 
pruebauno@latinmail.com
Guest
Posts: n/a
 
      01-05-2009
On Jan 5, 8:52*am, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> I'm having trouble with a script that is printing the output of f.seek
> () whereas in the documentation it is quoted not to have any output:
>
> ----
> file.seek(offset[, whence])¶
>
> * * Set the file’s current position, like stdio‘s fseek. The whence
> argument is optional and defaults to os.SEEK_SET or 0 (absolute file
> positioning); other values are os.SEEK_CUR or 1 (seek relative to the
> current position) and os.SEEK_END or 2 (seek relative to the file’s
> end). There is no return value.
> --------------
>
> 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
>
>
>
> I don't want python to produce output when setting the file pointer.
> Any help woul be appreciated.
> Kind regards,
> Thomas


You can also avoid the output by assigning the output to something:

>>> for a in range(10):

dummy=f.seek(a)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unwanted empty xmlns string in the output. CI XML 2 03-20-2007 03:34 PM
Unwanted character "^@" in perl output Captain 3-Putt Perl Misc 3 06-24-2006 03:26 PM
unwanted blank lines in output when using xalan Jeff Calico XML 3 02-09-2006 01:33 AM
Is Fuji S3000 3.2m/pixel output, or 6 m/pixel interpolated output? Peter H Digital Photography 43 12-04-2003 02:35 PM
Output / Debug window output bug? John Bentley ASP .Net 0 09-10-2003 07:38 AM



Advertisments