Static Class Initialization Question.

Thomas Troeger thomas.troeger.ext at siemens.com
Fri Jul 4 13:48:07 CEST 2008


Hello,

I have a class that looks like this:

class A(object):
	def __init__(self, a=0, b=1):
		self.a, self.b=a, b
	
	def __str__(self):
		return "%s(%d,%d)" % (type(a).__name__, self.a, self.b)

I want to have a list of such classes instantiated automatically on 
startup of my program. My current (most probably clumsy) implementation 
looks like this:

bla=[A(x[0], x[1]) for x in ((1, 2), (3, 4))]

giving the following:

 >>> map(str, bla)
['A(1,2)', 'A(3,4)']

Is there a better way to construct a list of such classes? Basically 
what I want is something similar to the following C example:

struct {
	int a;
	int b;
} bla[]={ {1, 2}, {3, 4} };

Regards,
T.



More information about the Python-list mailing list