__import__(x) VS __import__(x, {}, {}, [''])

P

Phil

I am trying to understand the difference between __import__(x) and
__import__(x, {}, {}, ['']).

The documentations wording was a bit weird for me to understand:
"The standard implementation does not use its locals argument at all,
and uses its globals only to determine the package context of the
import statement."

Does that mean it passes in the globals by default, or does the above
statement stand true only if globals() is passed in?
 
G

greg

Phil said:
I am trying to understand the difference between __import__(x) and
__import__(x, {}, {}, ['']).

The documentations wording was a bit weird for me to understand:
"The standard implementation does not use its locals argument at all,
and uses its globals only to determine the package context of the
import statement."
>
> Does that mean it passes in the globals by default, or does the above
> statement stand true only if globals() is passed in?

Not sure what you mean by "it" in that question.

This is talking about the built-in implementation of
the __import__ function, and what it does with the
'globals' and 'locals' arguments that get passed to
it (by whatever means).

If you call it without a value for 'globals', it uses
the current value of globals().

The bytecode generated for the 'import' statement
always calls it with the current globals() and locals().

If you pass an empty dict for 'globals', I think the
effect will be to cause the module name to always be
interpreted as a top-level module (i.e. no relative
import). But I'm not sure.
 
P

Phil

"If you call it without a value for 'globals', it uses the current
value of globals()."

Thanks, this is what I was trying to ask. I typed my question up way
too fast before dinner. You've been great help.
 

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
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top