Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: TypeError: an integer is required (http://www.velocityreviews.com/forums/t706208-re-typeerror-an-integer-is-required.html)

MRAB 11-22-2009 06:29 PM

Re: TypeError: an integer is required
 
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()

Nobody 11-22-2009 08:41 PM

Re: TypeError: an integer is required
 
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.




All times are GMT. The time now is 12:32 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.