1

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.

2
  • 3
    Whats wrong with your current code? Commented Oct 25, 2013 at 11:40
  • 1
    (FWIW acceleration has two 'e's and one 'a'.) Commented Oct 25, 2013 at 11:54

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Technically true, but variable names starting with an underscore are by convention for internal use. So perhaps the fix is to lose the underscore (and use a name other than list) or write a @property getter.
@kojiro Added a note in the answer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.