[pygtk] Handling strings from gtk.Entries
John K. Luebs
jkluebs at luebsphoto.com
Sun Dec 26 14:41:39 WST 2010
David López Luengo wrote:
> Hi everybody there!, here's a quick question.
> I'm getting the text from an entry:
> 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')
This decodes per Python string escaping rules, which is similar to C,
but not exactly the same (maybe it is just the quote chars):
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.
More information about the pygtk