Can I avoid explicit 'self'?

Posted by bguiz on Stack Overflow See other posts from Stack Overflow or by bguiz
Published on 2009-12-31T05:50:07Z Indexed on 2010/03/25 3:53 UTC
Read the original article Hit count: 544

Filed under:
|
|

I am fairly new to Python and trying to pick it up, so please forgive if this question has a very obvious answer!

I have been learning Python by following some pygame tutorials.

Therein I found extensive use of the keyword self, and coming from a primarily Java background, I find that I keep forgetting to type self. For example, instead of self.rect.centerx I would type rect.centerx, because, to me, rect is already a member variable of the class.

The Java parallel I can think of for this situation is having to prefix all references to member variables with this.

Am I stuck prefixing all member variables with self, or is there a way to declare them that would allow me to avoid having to do so?

Even if what I am suggesting isn't "pythonic", I'd still like to know if it is possible.

I have taken a look at these related SO questions, but they don't quite answer what I am after:
Python - why use “self” in a class?
Why do you need explicitly have the “self” argument into a Python method?

© Stack Overflow or respective owner

Related posts about python

Related posts about pythonic