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

Return to Question

Post Timeline

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

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:

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:

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:

edited title
Link
Bart
  • 20.1k
  • 8
  • 72
  • 80

Python: How to avoid explicit 'self''self' in Python?

Rollback to Revision 6
Link
bguiz
  • 28.5k
  • 49
  • 165
  • 259

Python: How to avoid explicit 'self' 'self'?

edited title
Link
Bart
  • 20.1k
  • 8
  • 72
  • 80
Loading
edited title
Link
bguiz
  • 28.5k
  • 49
  • 165
  • 259
Loading
added 4 characters in body; edited title
Source Link
Roger Pate
Roger Pate
Loading
deleted 117 characters in body; edited tags; edited title
Source Link
bguiz
  • 28.5k
  • 49
  • 165
  • 259
Loading
deleted 14 characters in body; edited tags; edited title
Source Link
Roger Pate
Roger Pate
Loading
added links to referenced questions
Source Link
bguiz
  • 28.5k
  • 49
  • 165
  • 259
Loading
Source Link
bguiz
  • 28.5k
  • 49
  • 165
  • 259
Loading
lang-py

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