[Tutor] Setting PYTHONPATH and other env vars dynamically
Hello We have developed three custom applications in Python. Each one of these applications needs a different PYTHONPATH, in addition to different environment variables to work. Instead of manually setting the environment variables for each application, what would be the best way to set PYTHONPATH and other environment variables for a specific application? We only run one application at a time, not all of them. We are running Python 2.5.2 and Python 2.4.1 on Win2K. Is a bash script that sets the environment variables on the application start-up way to go? Any ideas? I was not aware of site.py until a co-worker bandied it about - he says site.py is better than PYTHONPATH. Ideas and recommendations welcome.. Regards Jramak ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Setting PYTHONPATH and other env vars dynamically
> > > One more - put required packages and modules into the same directory > as the executable, usually the current directory is on the Python > search path. > > Kent > Hi Kent, there is no executable. It is just a collection of python scripts. I assume you refer to the Python search path as PYTHONPATH or sys.path. Do correct me if I am wrong. Jramak ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Setting PYTHONPATH and other env vars dynamically
> > > > > Don't edit site.py, it is part of the std lib. If you do want to > customize it, add a site-customize.py in your site-packages folder and > put your customizations there. > > Kent > There is no site-customize.py in Python25, how does Python know that site-customize.py needs to be loaded on start-up? Or did you mean sitecustomize.py ? Jramak ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Setting PYTHONPATH and other env vars dynamically
> > >> >> Don't edit site.py, it is part of the std lib. If you do want to >> customize it, add a site-customize.py in your site-packages folder and >> put your customizations there. > > > >> There is no site-customize.py in Python25, how does Python know that > site-customize.py needs to be loaded on start-up? Or did you mean > sitecustomize.py ? > > Jramak > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Setting PYTHONPATH and other env vars dynamically
Thanks for all the insight, everyone. I was originally thinking of writing a bash or bat script that would set the PYTHONPATH and other environment variables before running the specific application code. It seemed to be the most simplest solution. There are no other applications that rely on the PYTHONPATH. As Alan said this might result in surprises So a combo solution where in the env vars would be in an .ini file and the path is set in sys.path would be, IMHO a good way to go.. it's simple. I also looked at virtualenv http://pypi.python.org/pypi/virtualenv . Each virtual env takes up 2.3 MB. To me this seems a bit of overkill, but this will enable you to run Python24, Python25, Python26 etc specific code on one computer. Jramak ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Setting PYTHONPATH and other env vars dynamically
> > > Sorry, I mean put the packages in the same directory as the python > script that needs them. The search path is sys.path which is affected > by PYTHONPATH among other things... > > > sys.path is affected by PYTHONPATH ? how could it be affected by the PYTHONPATH ? Could you pls enlighten me ? Jramak ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Callbacks in Python
Hello I'm confused by callbacks. I would really appreciate any introduction or help in understanding the concept of callbacks. Thanks much Jramak ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Callbacks in Python
Thanks everyone for your excellent insights. I think I understand the callback concept better. So, it is like passing a function as an argument to another function. I am interested in learning more about how callbacks can be applied in GUIs, using wxPython as an example. Would appreciate any insight. Thanks much Jramak On 8/27/09, Alan Gauld wrote: > > "Jramak" wrote > >> I'm confused by callbacks. I would really appreciate any introduction or >> help in understanding the concept of callbacks. > > Callbacks are used in all sorts of different ways in programming > so it might help to undertand what exactly confuses you. > > Is it the whole concept of a callback? > Is it the idea of a function as an object? > Is it the use of callbacks? > In a GUI? In a networking framework like Twisted? > > Do you want to use someone elses callback mechanism > or do you want to create your own? > > The basic name comnes from the concept of calling > someone, asking them to do someting then call you back > when they are done. So you leave your number with them. > The number you leave is what they "call back". > In programming you call a function and at some critical > point that function calls you back on the function that > you passed in. > > def someFunction(value, callback) >result = pow(value,2) >callback(result) > > def myFunction() >v = 42 >someFunction(v, myFunction_continue) > > def myFunction_contiinue(result) > print result > > myFunction() > > This was very useful before threading environments became > common as a way of simulating multi threading. Then when GUIs > came along it bacame a common way of associating functions > with widgets. And in networking we can associate network events > with functions in a similar way. In fact any kind of event driven > program is likely to use callbacks as a way of distributing control > depending on event type. The typical implementation will see the > event framework storing the callbacks in some kind of dictionary > keyed by event type. > > HTH, > > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor