Python 3.2.3 vs. 3.5.1 string formatting - Raspberry Pi Forums
the following line of code generates error in python 3.2.3 works expected in 3.5.1
trying print byte streams serial port ser. converted string user_sdi_12_address byte stream. sdi_12_address byte stream.
after struggle, determined b'%sa%s!'. in 3.2.3, byte stream formatting string not allowed. have cast string, using string formatting string. cast result byte stream before ser.write(). in 3.5.1, byte stream formatting string allowed 1 step work of 2 steps. !@$@# language python is?!
code: select all
traceback (most recent call last): file "sdi_12_config.py", line 51, in <module> ser.write(b'%sa%s!' %(sdi_12_address,user_sdi_12_address.encode('utf-8'))) typeerror: unsupported operand type(s) %: 'bytes' , 'tuple'
after struggle, determined b'%sa%s!'. in 3.2.3, byte stream formatting string not allowed. have cast string, using string formatting string. cast result byte stream before ser.write().
code: select all
temp='%sa%s!' %(sdi_12_address.decode('utf-8'),user_sdi_12_address) # format string ser.write(temp.encode()) # format byte stream serial write
wheezy or jessie?liudr wrote:the following line of code generates error in python 3.2.3 works expected in 3.5.1
trying print byte streams serial port ser. converted string user_sdi_12_address byte stream. sdi_12_address byte stream.code: select all
traceback (most recent call last): file "sdi_12_config.py", line 51, in <module> ser.write(b'%sa%s!' %(sdi_12_address,user_sdi_12_address.encode('utf-8'))) typeerror: unsupported operand type(s) %: 'bytes' , 'tuple'
after struggle, determined b'%sa%s!'. in 3.2.3, byte stream formatting string not allowed. have cast string, using string formatting string. cast result byte stream before ser.write().in 3.5.1, byte stream formatting string allowed 1 step work of 2 steps. !@$@# language python is?!code: select all
temp='%sa%s!' %(sdi_12_address.decode('utf-8'),user_sdi_12_address) # format string ser.write(temp.encode()) # format byte stream serial write
using jessie. been working on irc chat. have seen error problem.
code: select all
er.write(bytes(%sa%s!' %(sdi_12_address,user_sdi_12_address.encode('utf-8'))))
raspberrypi
Comments
Post a Comment