how to read serial stream of data [newbie]

Heiko Wundram modelnine at modelnine.org
Tue Feb 7 09:04:39 EST 2012


Am 07.02.2012 14:48, schrieb Antti J Ylikoski:
> On 7.2.2012 14:13, Jean Dupont wrote:
>> ser2 = serial.Serial(voltport, 2400, 8, serial.PARITY_NONE, 1,
>> rtscts=0, dsrdtr=0, timeout=15)
>> In Python, if you want to continue the source line into the next text
> line, you must end the line to be continued with a backslash '\'.

Absolutely not true, and this is bad advice (stylistically).
When (any form of) brackets are open at the end of a line, Python does 
not start a new command on the next line but rather continues the 
backeted content.
So:
ser2 = serial.Serial(voltport, 2400, 8, serial.PARITY_NONE, 1,
 rtscts=0, dsrdtr=0, timeout=15)
is perfectly fine and certainly the recommended way of putting this.
Adding the backslash-continuation is always _possible_, but only 
_required_ when there are no open brackets.
So:
x = "hello" \
 " test"
is equivalent to:
x = ("hello"
 " test")
in assigning:
x = "hello test"
-- 
--- Heiko.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /