f.seek() unwanted output

Discussion in 'Python' started by thomasvangurp@gmail.com, Jan 5, 2009.

  1. Guest

    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
     
    , Jan 5, 2009
    #1
    1. Advertising

  2. Tim Chase Guest

    > 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
     
    Tim Chase, Jan 5, 2009
    #2
    1. Advertising

  3. Guest

    Re: f.seek() unwanted output

    Hi Tim,
    works! thanx a lot
    Thomas
     
    , Jan 5, 2009
    #3
  4. Guest

    Re: f.seek() unwanted output

    On Jan 5, 8:52 am, "" <>
    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)
     
    , Jan 5, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maki

    seek trough files in vhdl

    Maki, Jan 24, 2005, in forum: VHDL
    Replies:
    0
    Views:
    994
  2. Jeff Calico
    Replies:
    3
    Views:
    1,366
    Joe Kesselman
    Feb 9, 2006
  3. CI
    Replies:
    2
    Views:
    975
  4. Captain 3-Putt

    Unwanted character "^@" in perl output

    Captain 3-Putt, Jun 23, 2006, in forum: Perl Misc
    Replies:
    3
    Views:
    108
    Alan J. Flavell
    Jun 24, 2006
  5. Replies:
    3
    Views:
    143
    Andreas Perstinger
    May 14, 2013
Loading...

Share This Page