beginners syntax question
Steve Holden
sholden at holdenweb.com
Mon Apr 8 17:15:18 EDT 2002
"Tony" <tonyl at homechoice.co.uk> wrote in message
news:3caf47a5 at news1.homechoice.co.uk...
> Hi,
>
> I'm trying to call the update() method of several objects ie:
>
> object1.update()
> object2.update()
> etc
>
So, you've bound each of the objects to a different variable. How did you
perform these bindings? If you wrote
object0 = SomeClass(0)
object1 = SomeClass(1)
etc., then you really ought to be asking yourself why you didn't write:
olist = []
for i in range(6):
olist.append(SomeClass(i))
or some such construct. Then you can do
for i in range(6):
olist[i].update()
> I'd really like to do
>
> for x in range(7):
> "object"+str(x).update
>
> but can't figure outthe syntax, is this possible?
>
As you've already been shown, yes, it's possible. Unfortunately the answer
to "is this desirable?" is almost always a resounding "No".
regards
Steve
More information about the Python-list
mailing list