All of the tutorials I see online show how to create classes with __init__
constructor methods so one can declare objects of that type, or instances of that class.
How do I create a class (static in Java) so that I can access all methods and attributes of that class without having to create new instances/objects?
For example:
class World:
allElems = []
def addElem(x):
allElems.append(x)
World.addElem(6)
print(World.allElems)
EDIT
class World(object):
allAirports = []
@staticmethod
def initialize():
f = open(os.path.expanduser("~/Desktop/1000airports.csv"))
file_reader = csv.reader(f)
for col in file_reader:
allAirports.append(Airport(col[0],col[2],col[3]))
error: name 'allAirports' is not defined