Re: TypeError: an integer is required

Discussion in 'Python' started by MRAB, Nov 22, 2009.

  1. MRAB

    MRAB Guest

    Lutfi Oduncuoglu wrote:
    > Hello,
    >
    > I am a newbie on oython and I am taking the error at subject my code is
    > below, I am trying to develop a qgis plugin and lines begin with # is
    > the thing that I tried. Thus sys.stdout gives the type error. When I
    > comment that line it turns an error like below. What may be the problem?
    > thanks for help:)
    >
    > ...\ReadData.py", line 128, in run
    > print "%d %s" %(k, attr.toString())
    > IOError: [Errno 9] Bad file descriptor
    >
    >

    [snip]
    >
    > for (k,attr) in attrs.iteritems():
    > sys.stdout =
    > os.open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" )
    > print "%d %s" %(k, attr.toString())
    >

    I think the problem is that you're binding a low-level file id to
    sys.stdout instead of a file object. Try:

    sys.stdout =
    open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" )

    Actually, changing sys.stdout just to use print a single string is a bad
    idea. Try this instead:

    log_file =
    open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" )
    print >> log_file, "%d %s" %(k, attr.toString())
    log_file.close()
    MRAB, Nov 22, 2009
    #1
    1. Advertising

  2. MRAB

    Nobody Guest

    On Sun, 22 Nov 2009 18:29:25 +0000, MRAB wrote:

    >> os.open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" )


    > open("C://Users//lutfi//Documents//tezzzz//log.txt" , "a" )


    Backslashes need to be doubled; forward slashes don't.
    Nobody, Nov 22, 2009
    #2
    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. Andi Clemens
    Replies:
    8
    Views:
    647
    Tim Heaney
    Sep 17, 2006
  2. Iain Adams
    Replies:
    2
    Views:
    358
    bukzor
    Jun 9, 2008
  3. jeni
    Replies:
    3
    Views:
    899
    Ulrich Eckhardt
    Jun 16, 2009
  4. jakecjacobson
    Replies:
    4
    Views:
    907
    Gabriel Genellina
    Jul 28, 2009
  5. Dave Angel

    Re: TypeError: an integer is required

    Dave Angel, Nov 22, 2009, in forum: Python
    Replies:
    0
    Views:
    1,889
    Dave Angel
    Nov 22, 2009
Loading...

Share This Page