Seite 1 von 1

pickle ubuntu 10.04 lts import funktioniert nicht

Verfasst: Freitag 25. Juni 2010, 07:42
von krischeu
Hallo,
hab python unter ubuntu 10.04 installiert über apt-get install python.
Ich bekomme beim ausführen von meinem Testskript unten stehenden Fehler.
Muß ich noch was nachinstallieren?
Skript ist von: http://zetcode.com/tutorials/pyqt4/germ ... tprograms/

Besten Dank

heinz@pippin:~/scripte$ ./pickle.py
Monica
15
Traceback (most recent call last):
File "./pickle.py", line 5, in <module>
import pickle
File "/home/heinz/scripte/pickle.py", line 24, in <module>
pickle.dump(person, f)
AttributeError: 'module' object has no attribute 'dump'

Mein Testskript:

Code: Alles auswählen

#!/usr/bin/python

# pickle.py

import pickle

class Person:
   def __init__(self, name, age):
      self.name = name
      self.age = age

   def getName(self):
      return self.name

   def getAge(self):
      return self.age


person = Person('Monica', 15)
print person.getName()
print person.getAge()

f = open('monica', 'w')
pickle.dump(person, f)
f.close()

f = open('monica', 'r')
monica = pickle.load(f)
f.close()

print monica.getName()
print monica.getAge()

Re: pickle ubuntu 10.04 lts import funktioniert nicht

Verfasst: Freitag 25. Juni 2010, 07:51
von BlackJack
@krischeu: Dein Skript heisst `pickle.py` -- nun rate mal was bei ``import pickle`` importiert wird. ;-)

Re: pickle ubuntu 10.04 lts import funktioniert nicht

Verfasst: Freitag 25. Juni 2010, 10:07
von krischeu
Hi,
ich weiß nicht :K
Jedenfalls bekomme ich eine Fehlermeldung.

Re: pickle ubuntu 10.04 lts import funktioniert nicht

Verfasst: Freitag 25. Juni 2010, 10:09
von EyDu
Der Hinweis von BlackJack war doch jetzt mehr als deutlich. Bennene dein Modul um.

Re: pickle ubuntu 10.04 lts import funktioniert nicht

Verfasst: Freitag 25. Juni 2010, 10:18
von krischeu
Hi,
Das Python-Testprog heißt nun asdf.py und gibt immer noch den gleichen Fehler.
Meint Ihr eventuell bei:

Code: Alles auswählen

import pickle

Re: pickle ubuntu 10.04 lts import funktioniert nicht

Verfasst: Freitag 25. Juni 2010, 10:20
von Rebecca
Hast du noch eine pickle.pyc oder sonstwas rumfliegen?

Re: pickle ubuntu 10.04 lts import funktioniert nicht

Verfasst: Freitag 25. Juni 2010, 10:36
von krischeu
Jep,
da gibt es sowas ...
root@pippin:~/scripte# ls -la
insgesamt 164
drwxr-xr-x 2 heinz heinz 4096 2010-06-25 11:26 .
drwx------ 50 heinz heinz 16384 2010-06-25 11:26 ..
-rwx------ 1 heinz heinz 468 2010-06-25 11:19 asdf.py
-rw------- 1 heinz heinz 1043 2010-06-25 11:19 asdf.pyc
-rwx------ 1 heinz heinz 5755 2010-06-23 12:16 filemakerdatei-ueberpruefen.sh
-rwx------ 1 root root 905 2010-06-25 11:26 inputdialog.py
-rw-r--r-- 1 heinz heinz 0 2010-06-25 11:19 monica
-rw-r--r-- 1 heinz heinz 32 2010-06-25 08:43 output
-rw------- 1 heinz heinz 1044 2010-06-25 08:31 pickle.pyc
-rwx------ 1 heinz heinz 866 2010-06-24 16:04 python-fenster.py
-rwx------ 1 heinz heinz 261 2010-06-25 08:43 redirect.py
-rw-r--r-- 1 heinz heinz 2076 2010-06-22 14:08 test
-rw-r--r-- 1 heinz heinz 10969 2010-06-22 10:54 users_utf-8.txt

Re: pickle ubuntu 10.04 lts import funktioniert nicht

Verfasst: Freitag 25. Juni 2010, 10:56
von EyDu
Dann lösche auch noch die pickle.pyc.

Re: pickle ubuntu 10.04 lts import funktioniert nicht

Verfasst: Freitag 25. Juni 2010, 10:58
von krischeu
pickle.pyc gelöscht und gut.

Danke für die schnelle Hilfe