Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from contextlib import closing
- import serial
- ##############################################
- Better example
- ##############################################
- # https://docs.python.org/2.7/library/contextlib.html
- # https://docs.python.org/3.5/library/contextlib.html
- with closing(serial.Serial('/dev/ttyUSB0', baudrate=11520)) as ser:
- print(ser.inWaiting())
- # the function closing calls the method
- # close of the wrapped object when leaving
- # the context
- # Here is the serial connection already closed :-)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement