Skip to content

Instantly share code, notes, and snippets.

@bandit145
Created March 15, 2018 22:50
Show Gist options
  • Save bandit145/195f36f160678c9eadd1c5763c78cb56 to your computer and use it in GitHub Desktop.
Save bandit145/195f36f160678c9eadd1c5763c78cb56 to your computer and use it in GitHub Desktop.
Using a staticmethod to return instantiated versions of itself
class System:
names_from_api = ['server1','server2','server3']
def __init__(self, hostname):
self.hostname = hostname
@staticmethod
def get_systems(name):
system_list = []
for hostname in System.names_from_api:
if name == hostname:
system_list.append(System(hostname))
return system_list
@jffz
Copy link

jffz commented Mar 15, 2018

from System import System


servers = System.get_systems('server1')
print(servers)
print(type(servers[0]))
print(servers[0].hostname)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment