In python, what is the fastest way to determine if a string is an email or an integer?
Posted
by ensnare
on Stack Overflow
See other posts from Stack Overflow
or by ensnare
Published on 2010-03-30T03:11:01Z
Indexed on
2010/03/30
3:13 UTC
Read the original article
Hit count: 461
I'd like to be able to pull users from a database using either a supplied e-mail address or the user id (an integer). To do this, I have to detect if the supplied string is an integer, or an e-mail. Looking for the fastest way to do this. Thanks.
def __init__(self, data):
#populate class data
self._fetchInfo(data)
def _fetchInfo(self, data):
#If an email
#SELECT ... WHERE email = 'data'
#or if a user_id
#SELECT ... WHERE id = 'data'
#Fill class attributes
self._id = row['id']
self._email = row['id']
...
© Stack Overflow or respective owner