Best Python code snippet using lemoncheesecake
mqtt_paho_subscribe.py
Source:mqtt_paho_subscribe.py
...77 print("mid: "+str(mid))78 def on_subscribe(self, mqttc, obj, mid, granted_qos):79 print("Subscribed: "+str(mid)+" "+str(granted_qos))80 # store xs and ys81 def on_log(self, mqttc, obj, level, string):82 #parse83 #append(location)84 #print "message: ", string85 print(string)86 def parse(self, message):87 s=message88 #print "s.split(,) = ", s.split(",")89 #print "s.split(,)[0].split(:) = ", s.split(",")[0].split(":")90 x = float(s.split(",")[0].split(":")[1])91 y = float(s.split(",")[1].split(":")[1])92 #s = s.split(",")93 x_y = [x,y]94 return x_y95def on_connect(mqttc, obj, flags, rc):96 print("rc: "+str(rc))97def on_message(mqttc, obj, msg):98 print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload))99def on_publish(mqttc, obj, mid):100 print("mid: "+str(mid))101def on_subscribe(mqttc, obj, mid, granted_qos):102 print("Subscribed: "+str(mid)+" "+str(granted_qos))103 # store xs and ys104def on_log(mqttc, obj, level, string):105 #parse106 #append(location)107 print "message: ", string108 print(string)109# sampler = mqtt_sampler()110# sampler.take_sample()111# sampler.take_sample()...
lesson_2_meta_7.py
Source:lesson_2_meta_7.py
...141516class Logging(type):17 # ÐеÑод on_log18 def on_log(cls):19 LOG.info(f'ÐаннÑй меÑаклаÑÑ ÑикÑиÑÑÐµÑ ÑабоÑÑ Ñ ÐºÐ»Ð°ÑÑом {cls}')2021 # ÐÑзÑваем меÑаклаÑÑ22 def __call__(self, *args, **kwargs):23 # ÑоздаÑм новÑй клаÑÑ ÐºÐ°Ðº обÑÑно24 cls = type.__call__(self, *args)2526 # опÑеделÑем новÑй меÑод on_log Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð³Ð¾ из ÑÑиÑ
клаÑÑов27 setattr(cls, "on_log", self.on_log)2829 # возвÑаÑаем клаÑÑ30 return cls313233# ÐÑовеÑÑем меÑаклаÑÑ34class MyClass(metaclass=Logging):35 def fixing(self):36 self.on_log()3738# СоздаÑм ÑкземплÑÑ Ð¼ÐµÑаклаÑÑа. Ðн должен авÑомаÑиÑеÑки ÑодеÑжаÑÑ Ð¼ÐµÑод on_log39# Ñ
оÑÑ Ð¾Ð½ не обÑÑвлен в клаÑÑе вÑÑÑнÑÑ40# инÑми Ñловами, он обÑÑвлен за Ð½Ð°Ñ Ð¼ÐµÑаклаÑÑом414243MC = MyClass()44MC.fixing()4546"""47ÐеÑаклаÑÑÑ Ð´Ð°ÑÑ Ð½Ð°Ð¼ возможноÑÑÑ Ð¿Ð¸ÑаÑÑ ÐºÐ¾Ð´, коÑоÑÑй изменÑÐµÑ Ð½Ðµ ÑолÑко даннÑе, 48но и дÑÑгой код, Ñо еÑÑÑ Ð¸Ð·Ð¼ÐµÐ½ÑÐµÑ ÐºÐ»Ð°ÑÑ Ð²Ð¾ вÑÐµÐ¼Ñ ÐµÐ³Ð¾ ÑозданиÑ. 49РпÑимеÑе вÑÑе Ð½Ð°Ñ Ð¼ÐµÑаклаÑÑ Ð°Ð²ÑомаÑиÑеÑки добавлÑÐµÑ Ð½Ð¾Ð²Ñй меÑод к новÑм клаÑÑам, 50коÑоÑÑе Ð¼Ñ Ð¾Ð¿ÑеделÑем, ÑÑÐ¾Ð±Ñ Ð¸ÑполÑзоваÑÑ Ð¼ÐµÑаклаÑÑ.
...
mqtt_test.py
Source:mqtt_test.py
...39 print("mid: "+str(mid))40def on_subscribe(mqttc, obj, mid, granted_qos):41 print("Subscribed: "+str(mid)+" "+str(granted_qos))42 # store xs and ys43def on_log(mqttc, obj, level, string):44 print(string)45# If you want to use a specific client id, use46# mqttc = mqtt.Client("client-id")47# but note that the client id must be unique on the broker. Leaving the client48# id parameter empty will generate a random id for you.49mqttc = mqtt.Client()50mqttc.on_message = on_message51mqttc.on_connect = on_connect52mqttc.on_publish = on_publish53mqttc.on_subscribe = on_subscribe54# Uncomment to enable debug messages55#mqttc.on_log = on_log56mqttc.connect(host_name, 1883, 60)57mqttc.subscribe(topic_name, 0)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!