Python: startswith any alpha character
If you want to match non-ASCII letters as well, you can use str.isalpha
:
if line and line[0].isalpha():
You can pass a tuple to startswiths()
(in Python 2.5+) to match any of its elements:
import string
ALPHA = string.ascii_letters
if line.startswith(tuple(ALPHA)):
pass
Of course, for this simple case, a regex test or the in
operator would be more readable.
An easy solution would be to use the python regex module:
import re
if re.match("^[a-zA-Z]+.*", line):
Do Something