Doesn't know what it wants

John Machin sjmachin at lexicon.net
Sat Jan 26 02:52:54 EST 2008


On Jan 26, 6:25 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Fri, 25 Jan 2008 22:53:16 -0800, John Machin wrote:
> > On Jan 26, 5:32 pm, Jeroen Ruigrok van der Werven <asmo... at in-
> > nomine.org> wrote:
> >> -On [20080126 06:26], Tim Rau (bladedpeng... at gmail.com) 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
"""



More information about the Python-list mailing list