f.seek() unwanted output

T

thomasvangurp

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

Tim Chase

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

pruebauno

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:
dummy=f.seek(a)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top