So I started using python very recently. I am doing a small project involving classes. I for the most part have the conventions down like using self... etc. What I haven't figured out quite yet is the name mangling which may be related to my question.
Here is some code that forms a class to create a turn object that i can intilize in the beginning of a battle and allows me to switch turns periodically. (the game is going to be a pokemon battle simulator)
class turn:
TURNS = ("player","computer")
curr=0
def __init__(self):
self.currentTurn=turn.TURNS[turn.curr]
def getTurn(self):
return turn.TURNS[turn.curr]
def switch(self):
if turn.curr == 0:
turn.curr = 1
else:
turn.curr = 0
if turn.curr==0:
print "It's your move! \n"
self.currentTurn=TURNS[turn.curr]
So my question is this:
Is there any feature of python that would allow me to omit the class name when referring to the class vairables. I feel like it should know to look within the class definition for those variables but it doesn't. Also, If I want to use a helper method within the same class, i seem to have to prefix that with self.
Is there anyway around this?
**makes things bold.