I have a auto-completion script that I would like to modify
to complete class names, attributes, methods, etc. In python
when i do: re.co<TAB> it should give me a list of matching
methods. Problem is, I don’t want to parse the re.py file.
I’d prefer to:
import re
and then do dir(re) to get the list of methods. But How???
I tried:
imp_obj = exec('import re')
and it refused to work in if_py! 2 + 2 works though..
The best way to do this is to use the builtin
__import__function to import the module like so:Your code probably does not work because
importdoes not return a value that would in turn be returned byexec('import re').In general, it is a bad idea to use
execon text input by the user because it has a higher probability of executing arbitrary code you don’t want to execute.