Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: TypeError: an integer is required

Reply
Thread Tools

Re: TypeError: an integer is required

 
 
MRAB
Guest
Posts: n/a
 
      11-22-2009
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()
 
Reply With Quote
 
 
 
 
Nobody
Guest
Posts: n/a
 
      11-22-2009
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I add an Integer to another Integer? Sebastian Stelzer Java 6 04-07-2010 07:03 PM
CType(x,Integer) vs. Integer.Parse(x) =?Utf-8?B?Sm9l?= ASP .Net 7 02-07-2006 02:30 AM
how do I make Class.forName("Integer") returning java.lang.Integer? Johannes Zellner Java 22 12-19-2005 11:22 AM
How do I add an Integer to another Integer? Sebastian Stelzer Java 2 10-15-2004 01:17 PM
No Math.min(Integer, Integer)? =?ISO-8859-1?Q?Thomas_Gagn=E9?= Java 0 07-29-2003 07:46 PM



Advertisments