<div class="gmail_quote">On 13 December 2011 13:30, Jean-Michel Pichavant <span dir="ltr"><<a href="mailto:jeanmichel@sequans.com" target="_blank">jeanmichel@sequans.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



writing<div>
<br>
x = 1<br>
<br>
def spam():<br>
   x = 2<br>

<br></div>
is in general a bad idea. That was my point.</blockquote><div><br></div><div>Why? I have a few (probably wrong) guesses.</div><div><br></div><div>Because you expect it to be the same every time you use it?</div><div>Well, then this should be "in general a bad idea":</div>

<div>
x = 1; print(x); x = 2; print(x)</div><div>Even though it makes total sense to me.</div><div><br></div><div>Is it because it's used to different purpose between similarly-looking functions?</div><div>This looks fine, though:</div>


<div>def func1(): x=1; print(x)</div><div>def func2(): x=2; print(x)</div><div><br></div><div>Is it because it looks like a reassignment of the more global x?</div><div>I don't have an example here but, simply put, I don't believe this. We can use "id" as our own local variable without thinking that we're tampering with "__builtins__.id". I don't see it as much of a leap from builtin to global (except that you <i>*can*</i> do "dir = 1; del dir; dir" without error).</div>

<div><br></div><div>That said, I'm sorta' just guessing the reason you might think it's a bad idea.</div>
</div>