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()
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to