Pro-grammer
Pro-grammer

Reputation: 870

Objects and lists, python

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.

Upvotes: 1

Views: 79

Answers (1)

thefourtheye
thefourtheye

Reputation: 239443

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/.

Upvotes: 2

Related Questions