Please, see my comments between your lines. Thank you very much for your 
explanation!
>
>
>From: Lie Ryan <lie.1...@gmail.com>
>To: python-list@python.org 
>Sent: Thursday, January 5, 2012 2:30 AM
>Subject: Re: a little help
> 
>On 01/05/2012 11:29 AM, Andres Soto wrote:
>> my mistake is because I have no problem to do that using Prolog which
>> use an interpreter as Python. I thought that the variables in the main
>> global memory space (associated with the command line environment) were
>> kept, although the code that use it could change.
>> As you explain me, Python behave like a compiled language: any time I
>> make a change in the code, I have to "compile" it again, and re-run (and
>> re-load the data). There is nothing to do.
>
>it is usually trivial to redefine state-free functions, you just need to copy 
>and paste the new code into the shell.
>
>
>&&&yes, I am already using that, but I thought that maybe there were a more 
>elegant way. In Prolog, you just have to reload the code and nothing happens 
>with the global variables
>
>
> Redefining a class is a bit more complicated, while you can redefine a class 
>by the same technique (copy pasting the new class definition to the shell), it 
>will not modify the class definition for existing instances of that class. 
>Worst comes to worst, you could end up with a list of instances where half of 
>the items come from the old definition and the other half from the new 
>definition.
>
>
>&&&I tried to use classes but I got not good results so I left it for a while
>
>If your global data are only of native types (e.g. list, dict, int, float), 
>then you usually can safely carry your data between redefinitions; 
>
>
>&&&up to now, I am just using native types (e.g. list, dict, int, float). How 
>can I carry my data between redefinitions? copying and pasting the new code 
>into the shell? OK, that I am doing
>
>
>if you have objects in your global data that you want to preserve, you need to 
>be really careful not to confuse instances from old definitions with instances 
>from new definitions.
>
>
>&&&yes, I understand that
>
>Also, reload() will reload a module with the new definition, but it does not 
>touch existing function definitions in the global namespace; therefore if you 
>want to use reload(), you probably should avoid "from ... import ..." (if you 
>want to import module functions into your global namespace, then you'll need 
>to reimport them after you reload the module).
>
>
>So here's the gotchas to be aware of when reloading modules:
>
>
>1. import is cached, if you want to reimport a changed module you have to call 
>reload()
>2. reload does not modify anything in existing global namespace, if you have 
>imported functions/class definition to your global namespace, you will need to 
>reimport them after reloading.
>3. be careful if you mix instances made from old definitions with instances 
>made from new definitions, python does not modify the class definition of 
>existing instances
>4. be careful when reloading functions that have function attributes. The same 
>caution applies when reloading class that have class attributes.
>
>-- http://mail.python.org/mailman/listinfo/python-list
>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to