[Tutor] (no subject)

Luke Paireepinart rabidpoobear at gmail.com
Fri Oct 29 03:23:06 CEST 2010


On Thu, Oct 28, 2010 at 8:11 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>
>> postPos=words[3]
>
> This like will fail with NameError, because words is not defined anywhere.
>
> This is not the code you are running. We can't tell what is wrong with the
> code you run when you show us something completely different.
>
> Please send us the *actual* code you run, not something you've re-typed from
> memory, or copied and pasted in bits and pieces from different places.
>
Actually Steven, if you are using IDLE (as a lot of new programmers
are), the code by default does NOT execute in a subprocess but instead
in the same interpreter IDLE is running.  Therefore it can actually
have variables stick around from previous executions.  So if he didn't
have that line in his code the first time he executed, then words
would be defined.  Then the second time perhaps he added that line,
and in that case it will actually succeed because an old value of
'words' is floating around.

It also causes issues because if you import a module from the
interpreter and then use it in your code, it will work only during
that instance, but if you try to run the code standalone it will fail
when you try to use the module.

I know that sounds weird and that's why IDLE should be configured to
run as a subprocess.


More information about the Tutor mailing list