Как создать ли мне класс (статический в Java), чтобы иметь доступ ко всем методам и атрибутам этого класса без необходимости создавать новые экземпляры/объекты?
Для пример:
Код: Выделить всё
class World:
allElems = []
def addElem(x):
allElems.append(x)
World.addElem(6)
print(World.allElems)
Код: Выделить всё
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]))
ошибку: имя «allAirports» не определено
Подробнее здесь: https://stackoverflow.com/questions/305 ... -instances
Мобильная версия