One of the things I like about the Spyder ide is the ability to highlight a block of code, and use 'Run Cell': I'll write several blocks of code and test them this way. As much of my work involves editing database field values, I'll often write original values to a text file before running an update cursor so I can see if what I'm trying to do actually works. Typically I'll do it like this:
blah blah blah<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN>
logFile <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\scripts\logs\name.txt'</SPAN>
logoutput <SPAN class="operator token">=</SPAN> open<SPAN class="punctuation token">(</SPAN>logFile<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'w'</SPAN><SPAN class="punctuation token">)</SPAN>
sys<SPAN class="punctuation token">.</SPAN>stdout <SPAN class="operator token">=</SPAN> logoutput <SPAN class="comment token"># lets me use print() statements</SPAN>
blah
blah
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Something'</SPAN><SPAN class="punctuation token">)</SPAN>
blah
blah
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Something else'</SPAN><SPAN class="punctuation token">)</SPAN>
logoutput<SPAN class="punctuation token">.</SPAN>close<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
It's line 13 that goofs on me in Spyder. If I .close() my file handle, the console window never returns to the In [#]: prompt, so it appears that the that the cell is still running. If I open my text file it has all the records in it. If I comment out line 13, the cell runs, and returns to the In [#]: prompt. The text file is exactly the same as if I leave it as is.
There doesn't seem to be anything different syntax wise in open(), write() close() between Python 3.x or 2.x. Anyone else seeing things like this?