mysql - Manipulate strings in python -
I should use my Xbee data stored in mysql. There is a long known address of XB in the database which is used to identify which network I am communicating with Xb.
The following code works perfectly, but in this example I am not recovering from the address database. This is just an example of what works.
addr3 = '\ x00 \ x13 \ xa2 \ x00 @ \ n! \ X1c 'xbee.send (' remote_at ', frame_id =' \ x01 ', dest_addr_long = addr3, # & lt; - this works! Command =' d0 ', parameter =' \ x04 ') Now as soon as I \ x00 \ x13 \ xa2 recover \ x00 = \ n! From the \ X1c database (it has been stored as varchar), I get an error: "% (field ['name'], field ['lane']) value: error 'Dest_addr_long' 8 bytes long "
Here is the code (I have included the output of the six print lines below to help with debugging)
= cusors () Q. In the category (cur.rowcount): row = cur.fetchone () addr1 = row [0] position = line [1] for executic ("add selection, pinstats for devicestats adrulum and lethinum;" Addr2 = repr (addr1) addr3 = '\ x00 \ x13 \ xa2 \ x00 @ \ n! \ X1c "print" address 1:% s "% addr1 print" address 2:% s "% addr2 print" address 3:% s "% addr3 print" Addr1 size:% s "% sys.getsizeof (addr1) print "Addr2 Size:% S"% ss.getsizeof (addr2) Print "Addr3: Size of% s"% sys.getsizeof (addr3) If position == 0: Close # xbee.send ('remote_at', frame_id = '\ X01', dest_addr_long = Addr2, # & lt; -problem here is the command = 'd' ', parameter =' \ x04 ') if position == 1: turn on # xbee.send (' remote_at ', frame_id = '\ X01', dest_addr_long = addr2, # & lt; -problem here is the command = 'd', parameter = '\ x05') and output is
< Blockquote>address 1: \ x00 \ x13 \ x2 \ x00 @ \ n! \ X1c
Address 2: '\\ x00 \\ x13 \\ xa2 \\ x00 @ \\ n! \\ x1c '
Address 3:? @
!
Addr1: 45 sizeAddr2 size: 53
Size of addr3: 29
Code> dest_addr_long = addr1, No use.
I have tried to manipulate the string like adding and removing the brackets and dozens of str and repr combinations I think I have the wrong path completely
I think that What do I need to ask for
addr3 = '\ x00 \ x13 \ xa2 \ x00 @ \ n! \ X1c 'print' address 3:% S "% addr3"
output
< P> And once I understand, how can I manipulate the editory from the database to match the ADR 3 because the lineaddress 3:? @!
dest_addr_long = addr3, works perfectly.
This is an ASCII representation of a byte string \ x00 , example For 00, ie NUL, and \ x13 is ESC; @ and ! are literal characters, The meaning of ekkin \ n is a new form, similarly it is 8 bytes long.
You can get back the real bytes by decoding with 'string-escape': < / P>
& gt; S = '\ x00 \ x13 \ xa2 \ x00 @ \ n! \ X1c'> <>>>>>>>>>>>>>>>>>>>>>>>>>>> 'String-Escape')! (Though the result of the print will appear different on the terminal).
Comments
Post a Comment