David López Luengo wrote:
Hi everybody there!, here's a quick question.

I'm getting the text from an entry:

<gtk.Entry-instance>.get_text()

Which actually has 'text text \xff text text'. This strings is returned "as is", this mean, with each character, including \ and x and f and f, all I want to do is just get the same string BUT with the scaped character "\xff" as just one byte, I have read
Well, for a start, you could use Python's built-in string-escape codec.

So bytes = entry.get_text().decode('string_escape')

http://docs.python.org/release/2.6/library/codecs.html

This decodes per Python string escaping rules, which is similar to C, but not exactly the same (maybe it is just the quote chars):
http://docs.python.org/release/2.6/reference/lexical_analysis.html#id7

If these rules don't meet your specifications precisely, I believe you'll have to write your own little decoding routine. I assume someone has done this, somebody might have even done it well.
I would add the term "escape" or "escaping" to your search queries.


_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to