I have been trying to get access to available functions for a Match Object from re.search. I am looking for a way to do that similar to how I could do dir(str) and I can find .replace.
This is my dir() for the re module and some of the things I have tried:
>>> import re
>>> m = re.search('x', 'x')
>>> dir(re)
['DEBUG', 'DOTALL', 'I', 'IGNORECASE', 'L', 'LOCALE', 'M', 'MULTILINE',
'S', 'Scanner', 'T', 'TEMPLATE', 'U', 'UNICODE', 'VERBOSE', 'X',
'_MAXCACHE', '__all__', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__version__', '_alphanum', '_cache', '_cache_repl',
'_compile', '_compile_repl', '_expand', '_locale', '_pattern_type',
'_pickle', '_subx', 'compile', 'copy_reg', 'error', 'escape', 'findall',
'finditer', 'match', 'purge', 'search', 'split', 'sre_compile',
'sre_parse', 'sub', 'subn', 'sys', 'template']
I want to get to this menu without having to create the Match Object:
>>> dir(m)
['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__',
'__format__', '__getattribute__', '__hash__', '__init__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__',
'__str__', '__subclasshook__', 'end', 'endpos', 'expand', 'group',
'groupdict', 'groups', 'lastgroup', 'lastindex', 'pos', 're', 'regs',
'span', 'start', 'string']
Is there a way to go from dir(m) and be able to find out how to go up a level? That way I can trace my way back to the module and functions. Like if I was to do dir(re.search.func_dict), how can I find out what I need to type into dir() to get back a list that included func_dict()?
>>> dir(re.Match)
Traceback (most recent call last):File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Match'
I see this thing about _sre.SRE._Match but how do I found out where that lives so I can get more information on it?
>>> locals()
{'__builtins__': <module '__builtin__' (built-in)>, 'm': <_sre.SRE_Match
object at 0xb7b0d8a8>, '__package__': None, 're': <module 're' from
'/usr/lib/python2.7/re.pyc'>, '__name__': '__main__', '__doc__': None}
I have tried to use the inspect function, but the only function that gives me any info is inspect.getmembers(re) but it's just a ton of stuff I don't understand.
I am a complete newbie following a learn as you program course and I have no bases knowledge in Python other than some programs I have written. I have been trying to use dir() and help() a lot to learn. I greatly appreciate your help.