Arnaud Delobelle arnodel at
Wed Jan 27 18:57:59 CET 2010

George Trojan <george.trojan at> writes:

> Inspired by the 'Default path for files' thread I tried to use
> sitecustomize in my code. What puzzles me is that the's main()
> is not executed. My is
> def main():
>     print 'In Main()'
> main()
> and the test program is
> import site
> #site.main()
> print 'Hi'
> The output is
> $ python
> Hi

That's normal as is automatically imported on initialisation.
So when you do:

    import site

the module is not re-executed as it already has been imported.
Try this:

    ---- file:
    print 'Foo'
    ---- end

    --- Interactive session
    >>> import foo # First time, print statement executed
    >>> import foo # Second time, print statement not executed

> When I uncomment the site.main() line the output is
> $ python
> In Main()
> Hi

Now you explicitely call site.main(), so it executes it!

> If I change import site to import sitecustomize the output is as
> above. What gives?

It's normal, this time it's the first time you import it so its content
is executed.



More information about the Python-list mailing list