On Thu, Feb 08, 2001 at 01:39:55PM +0800, LUK ShunTim wrote:
> 
> That means names in the modules that are imported by default when
> invoking python is not automatically available to the user in the
> interpreter environment, ie, the __main__ namespace I suppose. Is it the
> case?

Yup.

> 
> If it is so, is there any reason why that it should be implemented this
> way? Surely these names are used very often and it makes sense not to
> have to re-input them again.
>

Well, that is a decision that was made by Guido (the creator of Python) and I
don't disagree with him. site.py loads those modules because *it* needs to
use them. If my script does *not* need to use them then it should not have
its namespace polluted with these references. It is not *that* big a burden
to have to explicitly "import sys" to use it and, better yet, it makes it
explicit that you want to use it -- your script does not *depend* on site.py
loading certain modules.


> And that means if I'd like to get, say, sys in the __main__ namespace at
> start every time, I *have to* do it using a startup script.

Yup, though for interactive use of Python I *think* that there is a way to do
what you want though I don't remember what it is offhand. You should ask on
[EMAIL PROTECTED] Someone should know there.

> 
> Finally, in a non-interactive invoking of python, are names in these
> import-by-default
> modules available?
>

Well, in a non-interactive script it works exactly the same as with the
interactive shell: you have to explicitly "import" the modules you want to
use.

Cheers,
Trent

-- 
Trent Mick
[EMAIL PROTECTED]
_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activepython

Reply via email to