473,379 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

type error on porting outfile.write

I ported my code from the development to
application platform, I found a "type error"
on a fileout statement:

outfile.write(object.id +",")

Object.id is provided by a library routine
that is installed on both machines.

How do I fix this ?

Thanks,
Phil Miller

Dec 20 '05 #1
3 2929
pm*****@gnf.org wrote:
I ported my code from the development to
application platform, I found a "type error"
on a fileout statement: outfile.write(object.id +",")


What is the type of object.id? I'm guessing an integer. The exception
should tell you, e.g.:

TypeError: unsupported operand type(s) for +: 'int' and 'str'

If I'm right, you can do this:

outfile.write("%d," % (object.id))

Though probably the better solution is to find out what code is
assigning an unexpected value to object.id.

Dec 21 '05 #2
On Tue, 20 Dec 2005 22:11:01 -0500 in comp.lang.python, Eric McCoy
<ct******@comcast.net> wrote:
pm*****@gnf.org wrote:
I ported my code from the development to
application platform, I found a "type error"
on a fileout statement:

outfile.write(object.id +",")


What is the type of object.id? I'm guessing an integer. The exception
should tell you, e.g.:

TypeError: unsupported operand type(s) for +: 'int' and 'str'

If I'm right, you can do this:

outfile.write("%d," % (object.id))


Or, more generally,

outfile.write("%s, " % object.id)

or even (closer to the original code)

outfile.write(str(object.id)+", ")

Regards,
-=Dave

--
Change is inevitable, progress is not.
Dec 21 '05 #3
Dave Hansen wrote:
or even (closer to the original code)

outfile.write(str(object.id)+", ")


That was going to be my suggestion too, but that can mask the underlying
bug since a lot of types have __str__ methods. Not only could those
types theoretically return a valid stringified integer by coincidence,
if they don't you know nothing except "something went wrong." Getting a
TypeError would be much more useful for tracking down the bug.

Basically it would be shorthand for:

assert(isinstance(object.id, int))
outfile.write(str(object.id) + ", ")

Although I guess in his case, where the bug may be in a library over
which he has no control, it would be better to do:

assert(isinstance(object.id, int) or isinstance(object.id, str))
outfile.write("%s, " % (object.id))

since that code will run unmodified on both platforms he's using and
still give him error checking.

Dec 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: darrel | last post by:
What does that MEAN? I'm working on a VS project with another person. We keep our DLLs and files in sync with each other. Last week I hit a snag where i kept getting the 'could not load type'...
0
by: Curtiss | last post by:
I receive "could not load type" error message when trying to load aspx page. The DLL is built and is located in the correct bin directory. The type name in the "inherits" attribute matches the...
0
by: pmiller | last post by:
I ported my code from the development to application platform, I found a "type error" on a fileout statement: outfile.write(object.id +",") Object.id is provided by a library routine that is...
3
by: Alden Pierre | last post by:
Hello, I'm having a hard time trying to figure why my code will not compile. When I try to compile the code, I get the non-aggregate type error. Any ideas on what I'm doing wrong? ...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
13
by: imutate | last post by:
Hi, I am migrating some std::vectors to use a template instead, but I get an incomplete type error in a struct declaration. #include <vector> template < typename T > class Vec : public...
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
2
by: unclefester | last post by:
I have two classes: Test1 and Test2. Test1 has a field of data type Test2, & vice versa. I need some help in avoiding the incomplete type error ("Error: field has incomplete type"). Test1.h ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.