[PythonCE] How to execute a scipt on Python startup
mike at pcblokes.com
mike at pcblokes.com
Thu Apr 14 10:13:23 CEST 2005
Quoting Michael Murdock <michaelmurdock at gmail.com>:
> On 4/13/05, Michael Murdock <michaelmurdock at gmail.com> wrote:
> > Is there a way to have a Python script executed whenever Python starts
> up?
>
> On 4/12/05, Mark Doukidis <mdoukidis at gmail.com> wrote:
> >> Try placing your code inside "sitecustomize.py".
> >> This is run every time python is started.
>
> Thanks, Mark! This works fine.
>
> I was surprised when I found that my sitecustomize.py script imports
> sys but sys isn't defined when I ask about it at the python prompt, so
> I have to import it again. Why is that?
>
You'll *probably* find that sitecustomize.py is run by being *imported*. This
means that when sys is imported in ``sitecustomize.py`` a reference to the sys
module is held - inside the sitecustomize namespace.
The amendments you make to sys.path then affect anything else that
*subsequently* uses sys.path. See if the interpreter holds a reference to
``sitecustomize``. (Can't test right now - sorry). If it *does* you'll be able
to access sys through ``sitecustomize.sys`` - which is pointless, but shows you
how namespaces work.
Best Regards,
Fuzzy
http://www.voidspace.org.uk/python
> Thanks again,
>
> ~Michael.
> _______________________________________________
> PythonCE mailing list
> PythonCE at python.org
> http://mail.python.org/mailman/listinfo/pythonce
>
More information about the PythonCE
mailing list