[IronPython] avoiding using the keyword 'self'

Michael Foord fuzzyman at voidspace.org.uk
Sat Aug 4 13:30:04 CEST 2007


Ori wrote:
> Hello,
>
> I have a python class which inherits from some other (c#) class. Something
> like:
> from MyNamespace import MyClass 
> class PyClass(MyClass) 
>   def myMethod(self)
>     return self.PropertyFormInheritedClass
>   

You appear to have a syntax error here (which may be the answer to your 
previous question about why your inheritance doesn't work).

The class declaration must be terminated with a colon:

class PyClass(MyClass):


> I don't understand why I have to write the "self." prefix - the context is
> the inherited class. Is there a way to avoid this prefix?
>   

Please read the Python FAQ about self (Python is not C#).

'Why must 'self' be used explicitly in method definitions and calls?'

http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls

Michael Foord
http://www.ironpython.info/

> Thanks,
> Ori
>   




More information about the Ironpython-users mailing list