david.lygagnon wrote:
>
> I am dealing with wx.TextCtrl and when grabbing the value I
> need to do some validation on it. The validation could be
> anything, it is defined by the user. Example, the validation
> might be a function that verifies the value is an integer
> greater than 0 or a function that verifies if the value is a
> string containing negative integers.
>
I don't really understand the question, and I don't know much about unicode,
so take my comments with a pinch of salt, but here goes.
You presumably know that wxPython strings are unicode strings (unless you
have a non-unicode build - unlikely).
There is no problem in converting a unicode string to an integer -
>>>int('1')
1
>>>int(u'1')
1
There are various string methods that may be of use -
>>>'a'.isdigit()
False
>>>'1'.isdigit()
True
>>>u'a'.isdigit()
False
>>>u'1'.isdigit()
True
There is also isnumeric(), which only operates on unicode strings. From the
docs, numeric characters include digit characters, and all characters that
have the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION ONE
FIFTH.
You probably know that in python 2.x, 'a' creates a byte string, and u'a'
creates a unicode string.
You probably also know that this has changed in python 3.x - 'a' creates a
unicode string. If you particularly want a byte string, you can use b'a'.
You may or may not know that python 2.6 allows the following 'future'
statement -
from __future__ import unicode_literals
This causes python 2.6 to behave the same as python 3.x.
I don't know if this helps at all. If no-one else chimes in, perhaps you can
give an example of what the actual problem is.
Frank Millman