How to get the list of imported variables/functions 
Author Message
 How to get the list of imported variables/functions

Greetings,

        Is there a way to know what variables/functions were imported
from a given module after :

        from blah_blah import *

Thanks for your time and help

_____________________________________________________________

                                        LaBoufarikoise



Sat, 19 Oct 2002 03:00:00 GMT  
 How to get the list of imported variables/functions

Quote:

> Greetings,

>    Is there a way to know what variables/functions were imported
> from a given module after :

>    from blah_blah import *

> Thanks for your time and help

Not directly, but something like:

filter(lambda x:not x.startswith("_"),sys.modules['blah_blah'].keys())

should do the trick.

Cheers,
M.

--
  nonono,  while we're making wild  conjectures about the behavior
  of completely  irrelevant tasks,  we must not  also make serious
  mistakes, or the data might suddenly become statistically valid.
                                      -- Erik Naggum, comp.lang.lisp



Sat, 19 Oct 2002 03:00:00 GMT  
 How to get the list of imported variables/functions

|
|Greetings,
|
|       Is there a way to know what variables/functions were imported
|from a given module after :
|
|
|       from blah_blah import *
|
|Thanks for your time and help
|

I think the following will give what you want:

dir(blah_blah)

However, I am also curious as to whether there is a way to look at the
entire local namespace.   I there a way to do:

dir( builtins and all imported modules )

        just wondering,
                ~c



Sat, 19 Oct 2002 03:00:00 GMT  
 How to get the list of imported variables/functions
Quote:
>>> a = dir()
>>> from string import *
>>> b = dir()
>>> for each in b:

 if not (each in a):
  print each

I couldn't get Mike's sys.module['imported_mod'].keys() to work,
and dir() of import * type thing doesn't do it.

HTH,

Emile van Sebille

-------------------



Sat, 19 Oct 2002 03:00:00 GMT  
 How to get the list of imported variables/functions

Quote:
> >>> a = dir()
> >>> from string import *
> >>> b = dir()
> >>> for each in b:
>  if not (each in a):
>   print each

Cunning.

Quote:
> I couldn't get Mike's sys.module['imported_mod'].keys() to work,
> and dir() of import * type thing doesn't do it.

Ah, that's probably because I used a string method; try

filter(lambda s:s[1]<>'_',sys.module['imported_mod'].keys())

instead.

--
  nonono,  while we're making wild  conjectures about the behavior
  of completely  irrelevant tasks,  we must not  also make serious
  mistakes, or the data might suddenly become statistically valid.
                                      -- Erik Naggum, comp.lang.lisp



Sat, 19 Oct 2002 03:00:00 GMT  
 How to get the list of imported variables/functions
Well, I got this to work:

a = dir(sys.modules['imported_mod'])

then filter as needed.

I couldn't get the keys attribute of the module though. Should
I have been able to?

Emile van Sebille

-------------------


<snip>

Quote:
> Ah, that's probably because I used a string method; try

> filter(lambda s:s[1]<>'_',sys.module['imported_mod'].keys())

> instead.



Sat, 19 Oct 2002 03:00:00 GMT  
 How to get the list of imported variables/functions

Quote:
> Well, I got this to work:

> a = dir(sys.modules['imported_mod'])

> then filter as needed.

> I couldn't get the keys attribute of the module though. Should
> I have been able to?

> filter(lambda s:s[1]<>'_',sys.module['imported_mod'].__dict__.keys())

Ack, surse me for a fool; I meant

filter(lambda s:s[1]<>'_',sys.modules['imported_mod'].__dict__.keys())

(I've even tested it this time!)

M.

--
8. A programming language is low level when its programs require
   attention to the irrelevant.
     -- Alan Perlis, http://www.cs.yale.edu/~perlis-alan/quotes.html



Sun, 20 Oct 2002 03:00:00 GMT  
 How to get the list of imported variables/functions
Cool.  I got it to work.  I don't know what I was doing yesterday
though.
I'd figured on the missing 's', but must have had a typo somewhere else
in
the rest of it anyway.

Thanks,

Emile van Sebille


Quote:

> > Well, I got this to work:

> > a = dir(sys.modules['imported_mod'])

> > then filter as needed.

> > I couldn't get the keys attribute of the module though. Should
> > I have been able to?

> > filter(lambda s:s[1]<>'_',sys.module['imported_mod'].__dict__.keys())

> Ack, surse me for a fool; I meant

> filter(lambda s:s[1]<>'_',sys.modules['imported_mod'].__dict__.keys())

> (I've even tested it this time!)

> M.

> --
> 8. A programming language is low level when its programs require
>    attention to the irrelevant.
>      -- Alan Perlis, http://www.cs.yale.edu/~perlis-alan/quotes.html
> --
> http://www.python.org/mailman/listinfo/python-list



Sun, 20 Oct 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Getting the value of a var in a list of variables

2. Getting a list of ALL functions in a class

3. Accessing variables created after import in imported files

4. C functions with variable parm lists

5. How do I let a function accept a variable number of lists:

6. Help with access-to-functions and imported C functions

7. getting variable name from the variable itself?

8. indirect function calls and variable variables

9. indirect function calls and variable variables

10. import Image vs from PIL import Image vs import PIL.Image

11. Passing variables to user functions of Clipper functions

12. Trouble using variables for function names in function declarations

 

 
Powered by phpBB® Forum Software