[Tutor] string conversion

2011-02-28 Thread Robert Clement

Hi

I have a wxpython control in which users are intended to enter control 
characters used to define binary string delimiters,  eg. '\xBA\xBA' or 
'\t\r\n' .


The string returned by the control is a unicode version of the string 
entered by the user, eg.  u'\\xBA\\xBA'  or  u'\\t\\r\\n' .


I would like to be able retrieve the original string containing the 
escaped control characters or hex values so that I can assign it to a 
variable to be used to split the binary string.


Does anyone know of a way this can be achieved?

Thanks
Rob



--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] binary string parsing

2011-03-08 Thread Robert Clement

Hi

I am receiving a string over a socket connection.  The string may be 
either line and value delimited ascii, or formated binary.  The skeleton 
of the code which handles the data is:


buffer = socket.recv(1000)
lines = buffer.split(linedelim)
 for line in lines:
if datatype  == 'binary':
if len(line) == binaryrecordsize:
values = unpack(formatin,line)
else:
print('error')
else:
values = line.split(signaldelim)

My problem arises when handling data which may be either big or little 
endian.  The endianess is handled properly when unpacking each line of 
data from the buffer but I was not sure how to handle the process if 
splitting the buffer into individual lines using the line delimiter.


The problem was first encountered when unpacking a formated binary 
buffer which had \xBA\xBA as the line delimiter.  The above code worked 
fine most of the time but occasionally an \xBA would crop up as the last 
byte of the line becasue the byte order was different than the default 
assumed for the buffer.


Thanks

Robert Clement

--
202 Crew Building
West Mains Road
Edinburgh
UK,  EH9 3JN

phone +44 131 650 7732




The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor