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

Martin j.m.rice at talktalk.net
Thu Apr 24 01:14:35 CEST 2014


Experimenting with pickling...

import pickle

file1 = open('first.txt','r')
contents = file1.read()
file1.close()

print(contents)

file2 = open('pickle.dat','wb')
pickle.dump(contents,file2,True)
file2.close()

contents = ''

file3 = open('pickle.dat','rb')
contents = pickle.load(file3)
print(contents)
input('\nPress Enter to finish')

This works as expected when run under the IDLE.
first.txt is just a small text file.

If I run from a command prompt, however, I get

C:\Users\Martin\Documents\College\python>python pickle.py
Hello!
How are you?
123
Traceback (most recent call last):
   File "pickle.py", line 1, in <module>
     import pickle
   File "C:\Users\Martin\Documents\College\python\pickle.py", line 11, 
in <module
 >
     pickle.dump(contents,file2,True)
AttributeError: 'module' object has no attribute 'dump'

C:\Users\Martin\Documents\College\python>

Get similar problem on College computers as well as at home.  Python 
3.3.3  Windows 7 Professional SP1

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?

Martin


---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140424/714d7ee8/attachment.html>


More information about the Tutor mailing list