Doesn't know what it wants

T

Tim Rau

Traceback (most recent call last):
File "C:\Documents and Settings\Owner\My Documents\NIm's code\sandbox
\sandbox.py", line 242, in <module>
player = ship()
File "C:\Documents and Settings\Owner\My Documents\NIm's code\sandbox
\sandbox.py", line 121, in __init__
self.phyInit()
File "C:\Documents and Settings\Owner\My Documents\NIm's code\sandbox
\sandbox.py", line 147, in phyInit
moi = cp.cpMomentForCircle(self.mass, .2, 0, vec2d((0,0)))
ArgumentError: argument 4: <type 'exceptions.TypeError'>: expected
vec2d instance instead of vec2d

As far as I can tell, It's getting a vec2d, and it wants a vec2d. I't
seems like it doesn't know what it wants, but I thought only teenagers
did that, no programming languages. clearly, Im missing something.

Line 147 reads:
moi = cp.cpMomentForCircle(self.mass, .2, 0, vec2d((0,0)))
 
J

Jeroen Ruigrok van der Werven

-On [20080126 06:26] said:
Line 147 reads:
moi = cp.cpMomentForCircle(self.mass, .2, 0, vec2d((0,0)))

I think it expects something like:

# badly named variable, pick something better depending on context
temp = vec2d(0, 0)
cp.cpMomentForCircle(self.mass, .2, 0, temp)

I am curious about your use of double braces for vec2d though. Why ((0,0)) and
not (0, 0)?
 
J

John Machin

Traceback (most recent call last):
File "C:\Documents and Settings\Owner\My Documents\NIm's code\sandbox
\sandbox.py", line 242, in <module>
player = ship()
File "C:\Documents and Settings\Owner\My Documents\NIm's code\sandbox
\sandbox.py", line 121, in __init__
self.phyInit()
File "C:\Documents and Settings\Owner\My Documents\NIm's code\sandbox
\sandbox.py", line 147, in phyInit
moi = cp.cpMomentForCircle(self.mass, .2, 0, vec2d((0,0)))
ArgumentError: argument 4: <type 'exceptions.TypeError'>: expected
vec2d instance instead of vec2d

As far as I can tell, It's getting a vec2d, and it wants a vec2d. I't
seems like it doesn't know what it wants, but I thought only teenagers
did that, no programming languages.

It possibly means that it is expecting an instance of a class whose
name is "vec2d" but you have given it an instance of some *other*
class whose name just happens to be "vec2d".
clearly, Im missing something.

Yes, some information:
1. what is vec2d, class or function?
2. what do you believe vec2d((0, 0)) should return?
3. what is this belief based on?
4. what has it actually returned this time?
5. what do you believe that cp.cpMomentForCircle expects as argument
4?
6. what is this belief based on?

The ArgumentError exception is raised by ctypes "when a foreign
function call cannot convert one of the passed arguments". Based on
guessin'n'googlin' the cp thing is a set of Python bindings to a
library written in C++ ... have you considered asking the author of
the bindings?
 
T

Tim Rau

-On [20080126 06:26] said:
Line 147 reads:
moi = cp.cpMomentForCircle(self.mass, .2, 0, vec2d((0,0)))

I think it expects something like:

# badly named variable, pick something better depending on context
temp = vec2d(0, 0)
cp.cpMomentForCircle(self.mass, .2, 0, temp)

I am curious about your use of double braces for vec2d though. Why ((0,0)) and
not (0, 0)?

the double parens are a tuple being passed as an argument. vec2d is
not a constructor that cares whether it gets a tuple or a pair of
ints. I choose tuple for consistency with the rest of my code. Isn't
what it gets the value returned by the constructor, no matter whether
you assign it to an intermediate value first? I tried it, and the
result is the same.
 
T

Tim Rau

It possibly means that it is expecting an instance of a class whose
name is "vec2d" but you have given it an instance of some *other*
class whose name just happens to be "vec2d".


Yes, some information:
1. what is vec2d, class or function?
2. what do you believe vec2d((0, 0)) should return?
3. what is this belief based on?
4. what has it actually returned this time?
5. what do you believe that cp.cpMomentForCircle expects as argument
4?
6. what is this belief based on?

The ArgumentError exception is raised by ctypes "when a foreign
function call cannot convert one of the passed arguments". Based on
guessin'n'googlin' the cp thing is a set of Python bindings to a
library written in C++ ... have you considered asking the author of
the bindings?

1. vec2d is a class, designed to hold and manipulte 2d vectors
2. it should return a vector with x=0 and y=0
3. That's what it's done before.
4. trying it in the interpreter seems to show that it returns a vec2d
with zero length. as it should.
5.cp.cpMomentForCircle seems to expect a vec2d. I'm baseing that on a
functioning demo that uses the exact same line.

I guess that the vec2d I've got is not the one it wants. How do I tell
the difference? I'll go look at all the imports.
 
J

John Machin

-On [20080126 06:26] said:
Line 147 reads:
moi = cp.cpMomentForCircle(self.mass, .2, 0, vec2d((0,0)))

I think it expects something like:

# badly named variable, pick something better depending on context
temp = vec2d(0, 0)
cp.cpMomentForCircle(self.mass, .2, 0, temp)

That *cannot* give a different result in Python. The called function
will be presented with *exactly* the same object as the OP's code
does.
 
S

Steven D'Aprano

-On [20080126 06:26] said:
Line 147 reads:
moi = cp.cpMomentForCircle(self.mass, .2, 0, vec2d((0,0)))

I think it expects something like:

# badly named variable, pick something better depending on context
temp = vec2d(0, 0)
cp.cpMomentForCircle(self.mass, .2, 0, temp)

That *cannot* give a different result in Python. The called function
will be presented with *exactly* the same object as the OP's code does.

Not quite. Look carefully at the difference.

The OP's code calls vec2d with a single tuple argument (0,0). Jeroen's
version calls vec2d with two int arguments, 0 and 0.

We don't know whether vec2d will treat those two things the same or not.

Personally, my bet is that the OP has shadowed vec2d, and has got two
different classes floating around with the same class.__name__.

Either that, or a bug in cp.cpMomentForCircle. I'd really like to see the
code of that function in phyInit. I'm suspicious about the exception
raised:

ArgumentError: argument 4: <type 'exceptions.TypeError'>: expected vec2d
instance instead of vec2d

What's with the TypeError in there? I'm guessing it's not a hard coded
string.
 
J

John Machin

-On [20080126 06:26], Tim Rau ([email protected]) wrote:
Line 147 reads:
moi = cp.cpMomentForCircle(self.mass, .2, 0, vec2d((0,0)))
I think it expects something like:
# badly named variable, pick something better depending on context
temp = vec2d(0, 0)
cp.cpMomentForCircle(self.mass, .2, 0, temp)
That *cannot* give a different result in Python. The called function
will be presented with *exactly* the same object as the OP's code does.

Not quite. Look carefully at the difference.

The OP's code calls vec2d with a single tuple argument (0,0). Jeroen's
version calls vec2d with two int arguments, 0 and 0.

We don't know whether vec2d will treat those two things the same or not.

That was Jeroen's 2nd problem; I was addressing his first problem
(thinking that introducing a temp variable would work some magic).

Google is your friend:
"""
class vec2d(ctypes.Structure):
"""2d vector class, supports vector and scalar operators,
and also provides a bunch of high level functions
"""
__slots__ = ['x', 'y']

def __init__(self, x_or_pair, y = None):

if y == None:
self.x = x_or_pair[0]
self.y = x_or_pair[1]
else:
self.x = x_or_pair
self.y = y
"""
 
M

marek.rocki

class vec2d(ctypes.Structure):
"""2d vector class, supports vector and scalar operators,
and also provides a bunch of high level functions
"""
__slots__ = ['x', 'y']

def __init__(self, x_or_pair, y = None):

if y == None:
self.x = x_or_pair[0]
self.y = x_or_pair[1]
else:
self.x = x_or_pair
self.y = y

I may be way off here, but why does vec2d inherit from
ctypes.Structure if it doesn't observe the protocol for Structures
(they're supposed to have _fields_, not __slots__)?
 
J

Jeroen Ruigrok van der Werven

-On [20080126 08:31] said:
The OP's code calls vec2d with a single tuple argument (0,0). Jeroen's
version calls vec2d with two int arguments, 0 and 0.

Yes, but it was not what I intended at all.

I guess I am just a bit too used to tacking on a , to denote a tuple since in
almost every other language seeing (()) is just an additional layer of braces.
I had totally forgotten Python would make it a tuple.

And I guess my head was still stuck with some other languages as well when I
made my other suggestion. Mea culpa.
 
R

rzed

(e-mail address removed).
com:
1. vec2d is a class, designed to hold and manipulte 2d vectors
2. it should return a vector with x=0 and y=0
3. That's what it's done before.
4. trying it in the interpreter seems to show that it returns a
vec2d with zero length. as it should.
5.cp.cpMomentForCircle seems to expect a vec2d. I'm baseing that
on a functioning demo that uses the exact same line.

I guess that the vec2d I've got is not the one it wants. How do
I tell the difference? I'll go look at all the imports.

Are you passing the class or an instance of the class? I'd bet the
former, but it should be the latter.
 
T

Tim Rau

On Jan 26, 5:32 pm, Jeroen Ruigrok van der Werven <asmo...@in-
nomine.org> wrote:
-On [20080126 06:26], Tim Rau ([email protected]) wrote:
Line 147 reads:
moi = cp.cpMomentForCircle(self.mass, .2, 0, vec2d((0,0)))
I think it expects something like:
# badly named variable, pick something better depending on context
temp = vec2d(0, 0)
cp.cpMomentForCircle(self.mass, .2, 0, temp)
That *cannot* give a different result in Python. The called function
will be presented with *exactly* the same object as the OP's code does.
Not quite. Look carefully at the difference.
The OP's code calls vec2d with a single tuple argument (0,0). Jeroen's
version calls vec2d with two int arguments, 0 and 0.
We don't know whether vec2d will treat those two things the same or not.

That was Jeroen's 2nd problem; I was addressing his first problem
(thinking that introducing a temp variable would work some magic).

Google is your friend:
"""
class vec2d(ctypes.Structure):
"""2d vector class, supports vector and scalar operators,
and also provides a bunch of high level functions
"""
__slots__ = ['x', 'y']

def __init__(self, x_or_pair, y = None):

if y == None:
self.x = x_or_pair[0]
self.y = x_or_pair[1]
else:
self.x = x_or_pair
self.y = y
"""

Ok, so apparently, it needs a different vec2d, one which is
specifically modified vec2d to work with the library Chipmunk, which
is a c library, but with pindings binding(PyMunk)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top