Jump to content

Python API mit Kontext-Manager


Recommended Posts

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):
        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():

def test(ipcon):

if __name__ == '__main__':
    HOST = ''
    PORT = 4223

    with IPConnection(HOST, PORT) as ipcon:


Viele Grüße


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...