[Tutor] Missing methods in string module?

Brian van den Broek bvande at po-box.mcgill.ca
Thu Jun 30 03:16:45 CEST 2005


Philip Carl said unto the world upon 29/06/2005 15:32:
> If I check the Python Libray Reference for String Methods (2.3.6.1) I 
> find many methods listed e.g. decode, encode, endswith etc. that do not 
>   seem to be listed by the command line dir(string) in Python 2.4 under 
> Windows XP, although many other methods e.g. capitalize and center are. 
>     Why is this?  Thanks.
> 
> Philip Carl


Hi Philip,

dir(string) reports on the string module, not string methods. See the 
snip below; if that doesn't clear it up for you, ask again.

Best,

Brian vdB


PythonWin 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit 
(Intel)] on win32.
Portions Copyright 1994-2004 Mark Hammond (mhammond at skippinet.com.au) 
- see 'Help/About PythonWin' for further copyright information.
 >>> dir(string)
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
NameError: name 'string' is not defined
 >>> dir('an actual string')
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', 
'__eq__', '__ge__', '__getattribute__', '__getitem__', 
'__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', 
'__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', 
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', 
'__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 
'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 
'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 
'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 
'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitlines', 
'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
 >>> import string
 >>> dir(string)
['Template', '_TemplateMetaclass', '__builtins__', '__doc__', 
'__file__', '__name__', '_float', '_idmap', '_idmapL', '_int', 
'_long', '_multimap', '_re', 'ascii_letters', 'ascii_lowercase', 
'ascii_uppercase', 'atof', 'atof_error', 'atoi', 'atoi_error', 'atol', 
'atol_error', 'capitalize', 'capwords', 'center', 'count', 'digits', 
'expandtabs', 'find', 'hexdigits', 'index', 'index_error', 'join', 
'joinfields', 'letters', 'ljust', 'lower', 'lowercase', 'lstrip', 
'maketrans', 'octdigits', 'printable', 'punctuation', 'replace', 
'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 
'splitfields', 'strip', 'swapcase', 'translate', 'upper', 'uppercase', 
'whitespace', 'zfill']
 >>>



More information about the Tutor mailing list