<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:10pt"><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt; "></div><div><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px; "><div style="font-family: arial, helvetica, sans-serif; "><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678"><font size="2" face="Arial"><span>Please, see my comments between your lines. Thank you very much for your explanation!</span></font></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678"><font size="2" face="Arial"><b><span style="font-weight:bold;"><br></span></b></font></div><div style="font-size: 12pt; font-family: 'times new roman', 'new
 york', times, serif; "><font size="2" face="Arial">  <b><span style="font-weight:bold;">From:</span></b> Lie Ryan <lie.1296@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> python-list@python.org <br> <b><span style="font-weight: bold;">Sent:</span></b> Thursday, January 5, 2012 2:30 AM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: a little help<br> </font> <br>
On 01/05/2012 11:29 AM, Andres Soto wrote:<br>> my mistake is because I have no problem to do that using Prolog which<br>> use an interpreter as Python. I thought that the variables in the main<br>> global memory space (associated with the command line environment) were<br>> kept, although the code that use it could change.<br>> As you explain me, Python behave like a compiled language: any time I<br>> make a change in the code, I have to "compile" it again, and re-run (and<br>> re-load the data). There is nothing to do.<br><br>it is usually trivial to redefine state-free functions, you just need to copy and paste the new code into the shell.</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678"><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678">&&&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</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678"><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678"> 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.</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "
 class="yui_3_2_0_29_132577488683678"><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678">&&&I tried to use classes but I got not good results so I left it for a while<br><br>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; </div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678"><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678">&&&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</div><div style="font-family: 'times new roman', 'new york',
 times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678"><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678">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.</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678"><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678">&&&yes, I understand that<br><br>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).</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678"><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; " class="yui_3_2_0_29_132577488683678"><span style="font-size: 12pt; ">So here's the gotchas to be aware of when reloading modules:</span><br></div><div class="yui_3_2_0_29_132577488683678"><br><span style="font-size: 12pt;">1. import is cached, if you want to reimport a changed module you have to call reload()</span><br><span style="font-size: 12pt;">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.</span><br><span style="font-size: 12pt;">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</span><br><span style="font-size: 12pt;">4. be careful when reloading functions that have function attributes. The same caution applies when reloading class that have class attributes.</span><br><br><span style="font-size: 12pt;">-- http://mail.python.org/mailman/listinfo/python-list</span><br><br><br> </div> </div> </blockquote></div>   </div></body></html>