How can I conjoin this parent and child class in python? -
class parent: def __init__(self, host, data, user, password): self.db = mysql_database(host, data, user, password) self.db.connect() def is_connected(self): return self.db.is_connected() def get_locations(self, query): if self.is_connected(): return self.db.execute(query) else: return none def close(self): self.db.close() class child(parent): def get_locations(self, query): cursor = super().grab_locations(query) results = [] if cursor != none: (name,lat,long) in cursor: locate = location(name,lat,long) results.append(locate) return results
i'm grabbing code database. i'd convert code 1 class if possible, i'm confused on how.
do mean want combine get_locations
this:
def get_locations(self, query): results = [] if self.is_connected(): cursor = self.db.execute(query) (name,lat,long) in cursor: locate = location(name,lat,long) results.append(locate) return results
Comments
Post a Comment