Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SQLite:
- def __init__(self, ip, psw):
- pass
- def connect(self):
- print('Successful.')
- class DB_sql:
- def __init__(self):
- pass
- def connect(self, ip, psw):
- try:
- SQLite(ip, psw).connect()
- except Exception as e:
- print(e)
- def request(self, var):
- print('Successful.')
- def close(self):
- pass
- class Table:
- def __init__(self, **kwargs):
- self.db: DB_sql = DB_sql()
- self.db.connect('lh', '123')
- for key, value in kwargs.items():
- self.__setattr__(str(key), value)
- self.db.request((str(key), value))
- self.db.close()
- def get_value(self, target):
- self.db: DB_sql = DB_sql()
- self.db.connect('lh', '123')
- attrs = dir(self)
- for value in attrs:
- if target == value:
- try:
- self.db.request(f'GET {target} FROM {self.__class__.__name__}')
- print(target, self.__dict__[target])
- except Exception as e:
- print(e)
- finally:
- self.db.close()
- if __name__ == '__main__':
- db = Table(x=1, y=2, z=3)
- db.get_value('x')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement