Object help

2009-01-11 Thread killsto
I have a class called ball. The members are things like position,
size, active. So each ball is an object.

How do I make the object without specifically saying ball1 = ball()?
Because I don't know how many balls I want; each time it is different.

The balls are to be thrown in from the outside of the screen. I think
you get that is enough information.

This doesn't directly pertain to balls, I have wanted to do something
like this for many different things but didn't know how.

I would think something like:

def newball():
 x = last_named_ball + 1
ball_x = ball(size, etc) # this initializes a new ball
return ball_x

But then that would just name a ball ball_x, not ball_1 or ball_2.

Is it possible?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Object help

2009-01-11 Thread killsto
On Jan 11, 2:20 pm, Steven D'Aprano  wrote:
> On Sun, 11 Jan 2009 14:06:22 -0800, killsto wrote:
> > I have a class called ball. The members are things like position, size,
> > active. So each ball is an object.
>
> > How do I make the object without specifically saying ball1 = ball()?
> > Because I don't know how many balls I want; each time it is different.
>
> > The balls are to be thrown in from the outside of the screen. I think
> > you get that is enough information.
>
> > This doesn't directly pertain to balls, I have wanted to do something
> > like this for many different things but didn't know how.
>
> > I would think something like:
>
> > def newball():
> >      x = last_named_ball + 1
> >     ball_x = ball(size, etc) # this initializes a new ball return ball_x
>
> > But then that would just name a ball ball_x, not ball_1 or ball_2.
>
> This is the TOTALLY wrong approach.
>
> Instead of having named balls, have a list of balls.
>
> balls = []  # no balls yet
> balls.append(Ball())  # one ball comes in from off-screen
> balls.append(Ball())  # and a second
> del balls[0]  # the first ball got stuck in a tree
> balls = []  # all the balls were swept up in a hurricane and lost
> balls = [Ball(), Ball(), Ball(), Ball()]  # four balls come in
> balls.append(Ball())  # and a fifth
> for b in balls:
>     print b.colour  # print the colour of each ball
>
> and so forth.
>
> --
> Steven

Thanks. That makes sense. It helps a lot. Although, you spelled color
wrong :P.

Just curious, is there another way? How would I do this in c++ which
is listless IIRC.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Object help

2009-01-11 Thread killsto
>
> > Thanks. That makes sense. It helps a lot. Although, you spelled color
> > wrong :P.
>
> At this time of day you are likely to find yourself communicating with
> Australians. Get used to it :-)
>
> Cheers,
> John

I was kidding. IMO, we Americans should spell color like everyone
else. Heck, use the metric system too while we are at it.
--
http://mail.python.org/mailman/listinfo/python-list


Programming friction

2009-01-13 Thread killsto
I'm trying to implement a basic user controlled sliding box with
pygame. I have everything worked out, except for two things.

The acceleration is changed once a second (for meters/second) this
leads to very jumpy movement. I need to add a way to check how long it
takes the program to loop and multiply the acceleration by that much.
(I think)

After I move, the box slows down appropriately, but then the speed
passes 0 and the box shoots off the other way. The equation (in real
life) is mS (Coefficient of static friction)*Normal Force >= friction
force. So lets say I am slowing down at a rate of -2m/s^2, if I hit 1,
the next number will be -1 and I shoot off in the other direction. How
do I fix this an still have backwards movement?
--
http://mail.python.org/mailman/listinfo/python-list


Beautiful soup tag attributes - Dictionary?

2008-11-30 Thread killsto
The documentation says I can find attributes of tags by using it as a
dictionary. Ex:

product = p.findAll('dd')
print product['id']

However, when I try that python thinks I am slicing it. When I print
product, it works but is a list. I am pretty sure I have the latest
version.

Any ideas?

Reference: 
http://www.crummy.com/software/BeautifulSoup/documentation.html#The%20attributes%20of%20Tags
--
http://mail.python.org/mailman/listinfo/python-list