[Tutor] some things work in IDLE but not a command prompt and vice versa

Martin j.m.rice at talktalk.net
Thu Apr 24 20:08:55 CEST 2014


On 24/04/2014 10:41, Alan Gauld wrote:
> 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.
>
>>      pickle.dump(contents,file2,True)
>> 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.
>
> HTH
Many thanks for the advice about file names.  I was having great fun (or 
Python was having fun with me) trying to run a very simple program with 
the file name dictionary.py but sanity returned when I renamed it 
dictionery.py




---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



More information about the Tutor mailing list