__LC__ Posted April 15, 2019 at 08:42 PM Posted April 15, 2019 at 08:42 PM Hallo liebes Tinkerforge-Team. Ich bin gerade wieder darüber gestolpert und möchte heute an dieser Stelle gern mal nachfragen. Würde es zukünftig nicht Sinn machen die Python-API dahingehend zu erweitern, dass man die verschiedenen Klassen auch im Rahmen des Kontext-Managers mit dem with-Statement ansprechen könnte? from tinkerforge.ip_connection import IPConnection as _IPConnection from tinkerforge.brick_master import BrickMaster as _BrickMaster class IPConnection(_IPConnection): def __init__(self, host=None, port=4223): _IPConnection.__init__(self) if host is not None: self.connect(host, port) self.__host = host self.__port = port def __enter__(self): if not self.get_connection_state(): self.connect(self.__host, self.__port) return self def __exit__(self, type, value, traceback): if self.get_connection_state(): self.disconnect() def test(ipcon): print(ipcon.get_connection_state()) ipcon.set_auto_reconnect(True) ipcon.disconnect() print(ipcon.get_connection_state()) if __name__ == '__main__': HOST = '127.0.0.1' PORT = 4223 with IPConnection(HOST, PORT) as ipcon: test(ipcon) Viele Grüße __LC__ Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.