1

When I run hello printer I get this error

AttributeError: type object 'Setup' has no attribute 'hello'

please help!

hello printer

from rpg import *
print Setup.hello

rpg

class Setup(object):
   def setup(self):
       hello = 5
1
  • If you want a static variable form a class Alex answer is right but if u want a class attribute mine is right Commented Jan 7, 2016 at 11:16

2 Answers 2

1

Either make setup method static or insert self argument.

class Setup(object):
    @staticmethod
    def setup():
        hello = 5
        print hello
Setup.setup()

As its a static method, you don't have to initialize a class. or

class Setup(object):
    def setup(self):
        hello = 5
        print hello
s = Setup()
s.setup()

In this case you will have to create an object of Setup class as you will be accessing the class method.

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

Comments

0

You define hello in the function setup so it does not belong to the class namespace. To access a class variable you need to define it in the class, not in a function:

class Setup(object):
    hello = 5

6 Comments

Wrong Answer, hello is static member now. how about class attributes?
How is this wrong? This is exactly what OP needs to do to make it work.
@Wombatz this is static variable but question is access to class members , this is why answer is wrong
Where did OP state that he wants a "class member"?
@Wombatz and he didnt say static memebr too
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.