Dear Kent,

Consider I'm working with an interactive session during which I have already
run some scripts. Those scripts have produced several variables, say, e.g.,
a and b. Now I execute myscript which also creates variables named a and b,
but with a possibly different type or content. To be sure that the variables
I find in my workspace after the execution of myscript were created by this
script and not by another one, I want to reset the workspace.

Otherwise, how can I make a difference between variables having the same
name but created by two different scripts?

Maybe this question is too much related to my Matlab experience and not
relevant into Python's philosophy. Please tell me what I should do.

Dimitri

-----Message d'origine-----
De : [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] De la part de Kent
Johnson
Envoyé : vendredi 14 janvier 2005 12:03
Cc : tutor@python.org
Objet : Re: [Tutor] reinitializing namespace

I think you may be looking for something that is not needed in Python or
that you can easily do 
another way.

If you are running a script from the command line, e.g.
  > python myscript.py

then myscript.py will have a completely fresh runtime environment every time
you call it.

If you are running the script by importing in another module, then you can
use reload() to reload 
the imported script. That will reinitialize the namespace of the module,
which for your purposes 
*is* the global namespace of the module.

Please give us more details about how you will run the script and what kind
of problem you anticipate.

Kent

Dimitri D'Or wrote:
> Hello Michael,
> 
> Thank you for your answer. Actually, my question is not specific to
> interactive sessions. I've written a script that loads some modules,
create
> variables and show figures. What I would like to find, is a command for
> clearing all the created variables and close all figures before beginning
> the execution of the script. This command will be placed at the beginning
of
> the script and automatically reinitialize the namespace. The utility of
this
> command is to guarantee that all the variables that are available in the
> namespace after the execution of the script were created by it and are not
> remainders from older commands or scripts. Do you think it is possible to
do
> such a thing?
> 
> I'm coming from the Matlab world and I want to find equivalents for the
> "clear" and "close" matlab commands.
> 
> Thank you for your help,
> 
> Dimitri
> 
> 
> -----Message d'origine-----
> De : Michael Janssen [mailto:[EMAIL PROTECTED] 
> Envoyé : jeudi 13 janvier 2005 19:29
> À : Dimitri D'Or
> Cc : tutor@python.org
> Objet : Re: [Tutor] reinitializing namespace
> 
> On Thu, 13 Jan 2005 13:20:11 +0100, Dimitri D'Or
> <[EMAIL PROTECTED]> wrote:
> 
> 
>>For some purpose, I would like to reinitialize the main namespace, i.e. I
> 
> want
> 
>>to delete all the variables I have created through the use of functions or
>>keyboard entries.
> 
> 
> Hello Dimiti,
> 
> sound like you're talking about an interactive session. Otherwise
> (within a script) it would be a really bad idea to try this (better
> put your stuff into functions, that don't create global variables).
> 
> Even in an interactive session it sounds like a not that brilliant
> idea, especially since I can't think of a way other than using exec
> "del %s" % key for appropriate keys from globals(). Finding
> "appropiate" keys is one tricky thing.
> 
> Why not end your ugly python session and start a new one? You can
> define all your imports in the python startfile (on Linux, consult
> python manpage. On Windows, I don't know). You can also define useful
> functions or variables in your python startfile. This way, you're
> really shure that all ugly variables are away without del'iting
> anything important.
> 
> regards
> Michael
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to