-4

So am currently writing a simple settings page for a project... and so this is what the page looks like:

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

st = Settings()
print(st.screen_width)

and so I followed the instruction on what this other question: Accessing a class' member variables in Python? but I still have issues accessing a single variable...

this is the error I get: error_code

it basically says that the current class (which is "Settings") doesn't have an attribute called "screen_width"

am starting to think its my text editor... I use VSCode but I don't know maybe am missing something?

falsetru
  • 357,413
  • 63
  • 732
  • 636

3 Answers3

1

You have made a minor mistake..in your init function it should be __init__ not _init_

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

st = Settings()
print(st.screen_width)
Aliasgher Nooruddin
  • 534
  • 1
  • 6
  • 18
0

Mis-spelled __init__, _init_ should be replaced with __init__:

class Settings(object):
   def __init__(self):  # <---
       self.screen_width = 1200
       self.screen_height = 800
       self.bg_color = (230,230,230)
falsetru
  • 357,413
  • 63
  • 732
  • 636
0

Here you have make mistake in int function Instant of this

def _init_(self):

Change to def int(self)

Kukesh
  • 490
  • 1
  • 5
  • 18