[Q]Python Classes

Rainer Deyke root at rainerdeyke.com
Sun May 27 00:51:40 EDT 2001


"Siew-Ann Cheong" <cheong at msc.cornell.edu> wrote in message
news:9epv95$9m8$1 at news01.cit.cornell.edu...
> In C++, I am used to the construct:
>
> class MyClass
> {
> public:
> MyClass(int data)
> {
> private_data = data;
>
> MyInitialization();
> }


Completely off topic remark: IMO it is better to use the preamble for
initialization, like this:

MyClass(int data)
  : private_data(data)
{
  MyInitialization();
}


> void MyInitialization()
> {
> ...
> }
> private:
> int private_data;
> }

> However, if I try to do the same thing in python,
>
> class MyClass:
> def __init__(self, data):
> self.private_data = data
> MyInitialization()

This line should be:

  self.MyInitialization()

(At the correct indentation level, of course.)

> def MyInitialization(self):
> ...
>
> I get complaints on MyInitialization().



--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list