persistant gloabl vars (very newbie) ?

Stef Mientki S.Mientki-nospam at mailbox.kun.nl
Wed Dec 27 10:42:12 EST 2006


hi all,

I'm investigating the possibilities to replace MatLab with Python
(+NumPy +SciPy).
I'm a very newbie, I just typed my first characters and calculated the
sum of 2 and 3 in Python.

My application is a Delphi program, for data-acquisition and real-time
data analysis. The real-time analysis is done with MatLab, embedded
through a OLE coupling. I already found PythonforDelphi which probably
helps a lot to make the first steps.

But I'm now stumbled about something very basic, which I don't
understand. The problem might be due to the IDE I use (PyScripter), but
I tried several and they all behave the same. And I expect that the
observed  behaviour might be very important notch in my final 
application (blockwise, real time interaction).

In MatLab I declare a workspace, in which each variable I declare
is automatically global, and can be reached from all views, i.e. from 
the command line interpreter as well as form the OLE environment, no 
matter where they are declared.
I try to do something similar in Python:
- I want to run an initialization part just once
- I want to run some testcode often and interactively

So the most simple example:

#Initialization
import time;
A = 5;

#code under test
x=time.time();
    # do something time consuming
print 1000*(time.time()-x);

Now if I run the initialization part, manual line by line in the command 
line interpreter, I can run the code under test as often as I want.
My real initilization code is much larger and therefor very clumsy to 
run line by line in the command line interpreter.

Is there a way to run the initialization code from a script(file) once,
to achieve the same effect ?

thanks,
Stef Mientki






More information about the Python-list mailing list