huwei
huwei

Reputation: 3

Settings object has no attribute screen_height?

settings.py:

class Settings():
    def __int__(self):
        self.screen_width = 1200
        self.screen_height = 800
        self.bg_color = (230,230,230)

try.py:

from settings import Settings
ai_settings=Settings() 
print(ai_settings.screen_height)

I execute try.py, why tell me "Settings object has no attribute screen_height"

Upvotes: 0

Views: 333

Answers (1)

Aaron Christiansen
Aaron Christiansen

Reputation: 11817

You misspelled __init__ as __int__, which meant that your constructor wasn't being called when you created an instance of the Settings class, because it had the wrong name.

Change def __int__(self): to def __init__(self): so that Python sees your class' constructor.

Upvotes: 1

Related Questions