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

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' 
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().

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 
in 3.5.1, byte stream formatting string allowed 1 step work of 2 steps. !@$@# language python is?!

liudr wrote:the following line of code generates error in python 3.2.3 works expected in 3.5.1

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' 
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().

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 
in 3.5.1, byte stream formatting string allowed 1 step work of 2 steps. !@$@# language python is?!
wheezy or jessie? :? :?
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'))))
cannot used b', whenever used utf-8. used bytes


raspberrypi



Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code