Skip to main content

Python-Specific Syntax Sugar

import darra_pns.sugar There are three additional ways to write this. If you don't import it, just write it the same way you did before.

import darra_pns.sugar

session()​

def session()

Come in start(), go out stop(). The example is still there.

Example:

import darra_pns.sugar

with svc.session():
...

if svc​

def __bool__(self) -> bool

if svc Exactly if svc.connected. We're checking whether the cycle data has changed, not whether the object exists. If there's no "start," it's false.

Example:

import darra_pns.sugar

if svc:
print("周期数据在换")

Unpack​

def __iter__(self)

connected, state = svc.

Example:

import darra_pns.sugar

connected, state = svc
print(connected, state)