[Tutor] some things work in IDLE but not a command prompt and vice versa
alan.gauld at btinternet.com
Thu Apr 24 11:41:23 CEST 2014
On 24/04/14 00:14, Martin wrote:
> If I run from a command prompt, however, I get
> C:\Users\Martin\Documents\College\python>python pickle.py
You have called your file pickle.py.
So when you try to import pickle the interpreter sees your file first
and imports that not the library pickle.
Never name your files the same as modules in the standard
library, or at least not the same as something you import.
> AttributeError: 'module' object has no attribute 'dump'
> I get the opposite problem with themsvcrt.getch() function. It works OK
> when run from a command prompt, but under IDLE it returns immediately
> without waiting for a key-press, with value b'\xff'. Is this just a
> feature of the IDLE?
I'd never noticed that particular quirk before but you are correct. I
get the same behaviour on win8.1 with Python 3.3. I also get the same
behaviour using Pythonwin (which is generally a much better IDE if you
are on Windows BTW!)
I'm not sure why they behave differently to the command line but most
IDEs have slight oddities like this. If in doubt use the command line
version as your reference.
Author of the Learn to Program web site
More information about the Tutor