How Do I Access Classes And Get A Dir() Of Available Actions?
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 .repl
Solution 1:
In Python 3.7, re.Match
is the type of the objects returned by re.match
. See bpo30397.
In previous versions, re.Match
is not defined. If you wanted a reference to the type of match objects you could get it with
Match = type(re.match('',''))
You can use dir
on either the Match
type or on a match object to list its attributes and methods.
Solution 2:
This is the closest thing I have gotten so far:
>>> import re, inspect
>>> inspect.getmembers(re,inspect.isclass)
[('Scanner', <class re.Scanner at 0xb7b7bcec>), ('_pattern_type', <type
'_sre.SRE_Pattern'>), ('error', <class 'sre_constants.error'>)]
>>> from re import _pattern_type
>>> dir(_pattern_type)
['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__format__',
'__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'findall',
'finditer', 'flags', 'groupindex', 'groups', 'match', 'pattern', 'scanner', 'search',
'split', 'sub', 'subn']
Solution 3:
So apparently _sre is a C-extension so SRE_Match is defined within this C-file
Post a Comment for "How Do I Access Classes And Get A Dir() Of Available Actions?"