> I have a regular expression test in a script. When a unicode character > get tested in the regex it gives an error: > > UnicodeError: ASCII decoding error: ordinal not in range(128) > > Question: Is there a way to test a string for unicode chars (ie. test > if a string will throw the error cited above). > > Like: > if unicode string: > print 'string's line #' > else: > process the string
Sure: try: s.decode("ascii") except UnicodeError: print 'string's line #' else: process the string Notice that you get a *decoding* error, so you are not testing Unicode characters, but byte strings. HTH, Martin -- http://mail.python.org/mailman/listinfo/python-list