try using regular expressions. I'afraid that i don't have any
documentation right here but i think there is a starting point for a
web search now.
Greetings
>How can I check that a string does NOT contain NON English characters?
try:
foobar.encode('ascii')
except:
bla
or use string.ascii_letters and enhance it.
mfg
Daniel
> How can I check that a string does NOT contain NON English characters?
It depends on how you define the set of English characters which is
as much a matter of opinion or authority as fact. The following may be
regarded as English despite containing 9 (8 unique) non-ASCII characters:
The €200 encyclopædia defines the “coördinates” in ¼ ångströms.
Neil
> Hello,
>
> try using regular expressions.
"Some people, when confronted with a problem, think 'I know, I'll use
regular expressions'. Now they have two problems." -- Jamie Zawinski
The original poster asked:
"How can I check that a string does NOT contain NON English characters?"
REs are rather overkill for something so simple, don't you think?
import string
english = string.printable # is this what you want?
english = string.ascii_letters + string.digits # or maybe this?
english = "abc..." # or just manually set the characters yourself
for c in some_string:
if c not in english:
print "Not English!!!"
break
else:
print "English!"
if you want it as a function, it is even more flexible:
def all_good(s, goodchars=None):
if goodchars is None:
goodchars = string.printable
for c in s:
if c not in goodchars:
return False
return True
--
Steven.
--
-Scott David Daniels
scott....@acm.org