I'm new to python/pygame. I want to define my own class. This class takes a list within a list and a acceleration function. I want to call these functions in another class so that they can be changed/ manipulated.
This is what i have:
Class baddie():
def __init__(self):
self._list=([random.randint(100,210),530])
def accelaration(self,acc):
clock=300-(acc)
I then want the baddie class to be called in the space class. So the user can manipulate the two above functions.
Class space():
b = baddie()
b.accelaration(203)
I also want the user to be able to call the list which takes a random integer and another number, but I don't understand how.
Any suggestions.
-
3Whats wrong with your current code?Nafiul Islam– Nafiul Islam2013年10月25日 11:40:41 +00:00Commented Oct 25, 2013 at 11:40
-
1(FWIW acceleration has two 'e's and one 'a'.)kojiro– kojiro2013年10月25日 11:54:32 +00:00Commented Oct 25, 2013 at 11:54
1 Answer 1
import random
class baddie():
def __init__(self):
self._list=([random.randint(100,210),530])
def accelaration(self,acc):
clock=300-(acc)
class space():
b = baddie()
b.accelaration(203)
print b._list # This is how we print the _list
space()
_list is just an instance variable, which holds a tuple. So you can simply access it with b._list
Note: As suggested by kojiro in the comments section, try to change your variable name to something more meaningful to your application than _list. Since you are a beginner, I recommend reading this atleast once http://www.python.org/dev/peps/pep-0008/.
2 Comments
list) or write a @property getter.