Re: Referring to a module by a string without using eval()

2017-05-17 Thread jeanbigboute
Thanks to all for the prompt replies. I look forward to trying both approaches. I wasn't aware that subpackages such as numpy.random and such could be imported after numpy was imported at the top level. For some reason I thought it would cause confusion. The functools.reduce and class ap

Re: Referring to a module by a string without using eval()

2017-05-17 Thread Andre Müller
Peter Otten <__pete...@web.de> schrieb am Mi., 17. Mai 2017 um 09:31 Uhr: > jeanbigbo...@gmail.com wrote: > > > I am trying to write some recursive code to explore the methods, classes, > > functions, builtins, etc. of a package all the way down the hierarchy. > > > 2) I ultimately need to create

Re: Referring to a module by a string without using eval()

2017-05-17 Thread Steve D'Aprano
On Wed, 17 May 2017 05:14 pm, Terry Reedy wrote: > On 5/17/2017 2:04 AM, jeanbigbo...@gmail.com wrote: > >> Question: Is there a solution to this "turn a string into the module it >> represents" problem? > > Built-in function __import__ Like all dunders, __import__ is intended for the interpre

Re: Referring to a module by a string without using eval()

2017-05-17 Thread Peter Otten
jeanbigbo...@gmail.com wrote: > I am trying to write some recursive code to explore the methods, classes, > functions, builtins, etc. of a package all the way down the hierarchy. > > 1) Preliminaries > In [2]: def explore_pkg(pkg): >...: return dir(pkg) >...: > > In [3]: import numpy

Re: Referring to a module by a string without using eval()

2017-05-17 Thread Terry Reedy
On 5/17/2017 2:04 AM, jeanbigbo...@gmail.com wrote: Question: Is there a solution to this "turn a string into the module it represents" problem? Built-in function __import__ -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list

Referring to a module by a string without using eval()

2017-05-16 Thread jeanbigboute
I am trying to write some recursive code to explore the methods, classes, functions, builtins, etc. of a package all the way down the hierarchy. 1) Preliminaries In [2]: def explore_pkg(pkg): ...: return dir(pkg) ...: In [3]: import numpy as np In [4]: l2 = explore_pkg(np.random)