Używam Pycharm. Przede wszystkim, gdy dowolny moduł jest importowany w Pycharm. Cała linia importu zanika. Ale w przypadku import shelve
nie zanika. Również kiedy uruchomić plik i uzyskać następujące błędy:shelve: nie można określić typu db
Traceback (most recent call last):
File "/Users/abhimanyuaryan/PycharmProjects/shelve/main.py", line 13, in <module>
s = shelve.open("file.dat")
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/shelve.py", line 239, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/shelve.py", line 223, in __init__
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/dbm/__init__.py", line 88, in open
raise error[0]("db type could not be determined")
dbm.error: db type could not be determined
Oto mój kod:
import shelve
s = shelve.open("file.dat")
s["first"] = (1182, 234, 632, 4560)
s["second"] = {"404": "file is not present", "googling": "Google to search your content"}
s[3] = ["abhilasha", "jyoti", "nirmal"]
s.sync()
print(s["first"])
print(s["second"])
print(s[3])
Więc jaki typ DB jest 'file.dat' ma być? Czy to istnieje? Najwyraźniej jest to przyczyną problemów PyCharm, choć nie jest do końca jasne, dlaczego. –
Napisałem do pliku dat używając pikle i napisałem do tego pliku. Nadal nie rozumiem, o co chodzi w tym przypadku. N Tak, wyjście z pliku. – AbhimanyuAryan