C API Q II : __main__.__dict__.keys() not same as dir()

Martin v. Löwis loewis at informatik.hu-berlin.de
Sun Apr 14 08:39:12 EDT 2002


"Johan Hahn" <johahn at delta.telenordia.se> writes:

> I figured that since the InteractiveConsole hangs after calling
> interact() you have to have atleast 2 threads to use that, right?

Unless it is acceptable that it hangs: yes.

> I thought the documentation was a little vague on that.

In what respect? The interact documentation says:

  "Closely emulate the interactive Python console."

So it is pretty clear to me that it is an infinite loop - just as the
interactive Python console.

> Where does the user imported modules (and all other objects too for that
> matter) hide??

They don't hide... When you import a module, two things happen:

1. the module is loaded and run
2. the resulting module object is put into sys.modules
3. the resulting module object is added to the namespace that
   executed the import statement. If you do it in the interactive
   prompt, it is added to globals(), which is __main__.__dict__.
[as any good list announced with two items, I have three of them]

Regards,
Martin



More information about the Python-list mailing list