self for modules

  • Thread starter Bertram Scharpf
  • Start date
B

Bertram Scharpf

Hi,

when I want to access the module itself, I can write

----
import sys
module_self = sys.modules[ __name__]
----

Is there a smarter way to do this?

On the other side, I could express my problem in the
following way: Is it legitimate to say

----
def f( d):
d.update( { 'a': 'spam', 'b': 'eggs'})

f( vars())

print a, 'and', b
----

?

Thanks for your answers in advance.

Bertram
 
T

Terry Reedy

Bertram Scharpf said:
Hi,

when I want to access the module itself, I can write

shorter and not implementation specific is
<module '__main__' (built-in)>

I presume this works in imported module also.

Terry J. Reedy
 
B

Bertram Scharpf

Hallo,

Terry Reedy said:
shorter and not implementation specific is
<module '__main__' (built-in)>

I presume this works in imported module also.

Nice idea, indeed. Thank you.

Bertram
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top