WebMaster
WebMaster

Reputation: 117

Getting variables in a class?

When I try to do this:

print(pyfancy.RED + "Hello Red!" + pyfancy.END)

RED and END is a variable but when I run it I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'RED'

It worked before now it does not work!

Please Help!

Upvotes: 2

Views: 62

Answers (2)

NPE
NPE

Reputation: 500307

It sounds like you have a module called pyfancy that contains a class, probably also called pyfancy(?).

Either write pyfancy.pyfancy.RED or import the class like so:

from pyfancy import pyfancy

(You might need to tweak this to match the actual class name used in your code.)

Upvotes: 4

Steve Barnes
Steve Barnes

Reputation: 28370

RED is probably a class attribute of a class called pyfancy in a module called pyfancy - you need to either from pyfancy import pyfancy or use pyfancy.pyfancy.RED, etc.

Upvotes: 0

Related Questions