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
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to