Object help

killsto kiliansto at gmail.com
Sun Jan 11 23:06:22 CET 2009


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?



More information about the Python-list mailing list