Why doesn't this work

Skip Montanaro skip at pobox.com
Tue Sep 2 16:42:48 EDT 2014


On Tue, Sep 2, 2014 at 3:13 PM, Seymore4Head <Seymore4Head at hotmail.invalid>
wrote:

> I still can't get the syntax
> test='Hey buddy get away from my car'
> if test[0].alpha():
>     return True
>

My guess is you meant isalpha(), as Mark indicated. Here's a cheap way to
see what an object can do:

>>> test='Hey buddy get away from my car'
>>> dir(test)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__',
'__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__',
'__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__',
'__setattr__', '__sizeof__', '__str__', '__subclasshook__',
'_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center',
'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format',
'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle',
'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace',
'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split',
'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate',
'upper', 'zfill']

or more precisely:

>>> [attr for attr in dir(test) if "alpha" in attr]
['isalpha']

Skip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140902/6fc57769/attachment.html>


More information about the Python-list mailing list