Checking for binary data in a string

Mitko Haralanov mitko at qlogic.com
Fri Jun 19 16:18:58 EDT 2009


I have a question about finding out whether a string contains binary
data?

In my application, I am reading from a file which could contain
binary data. After I have read the data, I transfer it using xmlrpclib.

However, xmlrpclib has trouble unpacking XML which contains binary data
and my application throws an exception. The solution to this problem is
to use base64 encoding of the data but I don't know how to check
whether the encoding will be needed?

If I read in a string containing some binary data from the file, the
type of that string is <type 'str'> which is not different from any
other string, so I can't use that as a check.

The only other check that I can think of is to check every character in
the read-in string against string.printable but that will take a long
time.

Can anyone suggest a better way to handle the check? Thank you in
advance.

-- 
Mitko Haralanov



More information about the Python-list mailing list