473,385 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

trying to learn shelving keep getting an error

Input:
Expand|Select|Wrap|Line Numbers
  1. import pickle, shelve
  2.  
  3. variety = ["sweet", "hot", "dill"]
  4. shape = ["whole", "spear", "chip"]
  5. brand = ["Claussen", "Heinz", "Vlassic"]
  6. f = open("pickles2.db", "wb")
  7. pickle.dump(variety, f)
  8. pickle.dump(shape, f)
  9. pickle.dump(brand, f)
  10. f.close()
  11.  
  12. f = open("pickles2.db", "rb")
  13. variety = pickle.load(f)
  14. shape = pickle.load(f)
  15. brand = pickle.load(f)
  16.  
  17. print(variety)
  18. print(shape)
  19. print(brand)
  20. f.close()
  21.  
  22. print("\nShelving lists.")
  23. s = shelve.open("pickles2.db")
Output error in idle:

Traceback (most recent call last):
File "C:/Python33/pickling 2.py", line 23, in <module>
s = shelve.open("pickles2.db")
File "C:\Python33\lib\shelve.py", line 232, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "C:\Python33\lib\shelve.py", line 216, in __init__
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
File "C:\Python33\lib\dbm\__init__.py", line 83, in open
raise error[0]("db type could not be determined")
dbm.error: db type could not be determined

Prints that after outputting everything until after:
print("\nShelving lists.")

I'm very new go easy on me.
Jul 19 '13 #1
2 2270
bvdet
2,851 Expert Mod 2GB
From the Python docs: "A “shelf” is a persistent, dictionary-like object." The data you are attempting to shelve is not a dictionary.
Jul 19 '13 #2
dwblas
626 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. f = open("pickles2.db", "rb")
  2. variety = pickle.load(f)
  3. shape = pickle.load(f)
  4. brand = pickle.load(f)
  5.  
  6. s = shelve.open("pickles2.db") 
The pickles2.db file can only be one type, pickle, shelve, text, etc. If you change the name of one of the files, then the program runs, i.e. you are not trying to open a pickle file using shelve.

Shelve create file example: http://pymotw.com/2/shelve/
Pickle create file example: http://pymotw.com/2/pickle/index.html
Jul 20 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Vernon | last post by:
Hi anyone, This is my code. int num num = 0; for(int a=0; a<count; ++a){ if(current->transID==aNo) ++num; current = current->next;
4
by: Chefry | last post by:
I'm trying to set up an off the shelf script and keep getting an error. My host set up the mysql on my site and I changed the variables I had to in the settings.php file but I keep getting the...
2
by: iainw | last post by:
HI All, 1st post here, i wonder if you can help. We are about to upload CMS t a windows server and keep getting 2 errors below. We need to go LIVE an it's delaying us. An error occured when...
2
by: nfr | last post by:
I keep getting the following warning in my compile: Warning: The dependency 'WBWebServices, Version=1.0.1289.13943, Culture=neutral' in project 'WBWin' cannot be copied to the run directory...
2
by: partybob99 | last post by:
I am trying to call SP_Password from some vb.net code. This should be very straight forward but no matter what I do, I keep getting errors. Here is the code strConnectString = "Data Source=" +...
3
by: Greg Noss | last post by:
I'm trying to install MySQL. During the security settings portion fo the setup. I keep getting a Connection Error. Error Nr. 1045 Access denied for user'root'@'localhost'(using password:YES) ...
8
by: lawrence k | last post by:
I've installed Apache 1.3.36 on my Redhat EL 3 machine. Now I'm trying to install PHP 5.1.4. I can not get the ./configure command to work. I keep getting this error: configure: error: Invalid...
8
by: illuzion | last post by:
ok I keep getting this error: Parse error: syntax error, unexpected T_VARIABLE in /home/illuzion/public_html/BAMF/contactus.php on line 38 and this error is possibly on other lines could...
3
by: tvnaidu | last post by:
I need to bringup xterm of remote machine on local machine, I did login to remote and set "export DISPLAY=ip_local:0.0", then I issued "xhost +" command, so that I would like to launch GUI window of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.