Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Source Link
ironfroggy
  • 8.1k
  • 7
  • 38
  • 45

You demonstrate a fundamental misunderstanding.

You never created an instance of SimpleClass at all, because you didn't call it.

for count in xrange(4):
 x = SimpleClass()
 x.attr = count
 simplelist.append(x)

Or, if you let the class take parameters, instead, you can use a list comprehension.

simplelist = [SimpleClass(count) for count in xrange(4)]
Post Made Community Wiki by Community Bot
lang-py

AltStyle によって変換されたページ (->オリジナル) /