473,836 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

shelve error

test1.py:
--------------------
import shelve

s = shelve.open("/Users/me/2testing/dir1/aaa.txt")
s['x'] = "red"
s.close()
--------output:------

$ python test1.py
Traceback (most recent call last):
File "test1.py", line 3, in ?
s = shelve.open("/Users/me/2testing/dir1/aaa.txt")
File "/System/Library/Frameworks/Python.framewor k/Versions/2.3/lib/
python2.3/shelve.py", line 231, in open
return DbfilenameShelf (filename, flag, protocol, writeback,
binary)
File "/System/Library/Frameworks/Python.framewor k/Versions/2.3/lib/
python2.3/shelve.py", line 212, in __init__
Shelf.__init__( self, anydbm.open(fil ename, flag), protocol,
writeback, binary)
File "/System/Library/Frameworks/Python.framewor k/Versions/2.3/lib/
python2.3/anydbm.py", line 80, in open
raise error, "db type could not be determined"
anydbm.error: db type could not be determined
Exception exceptions.Attr ibuteError: "DbfilenameShel f instance has no
attribute 'writeback'" in ignored
---------------------

What should I do to correct that error?

Apr 5 '07
13 6526
Alex Martelli wrote:
BTW, if you DO want to call shelve.open on a path f that may correspond
to an arbitrary existing file (and want to toss away the previous
contents of that file, if any) the correct way to call is then:

s*=*shelve.open (whatever_path, *'n')

since 'n' truncates an existing file, or creates a new one, as needed.
It's not entirely arbitrary since you get an exception if that file is not a
valid database:
>>open("tmp.db" , "w").write("gar bage")
import shelve
shelve.open(" tmp.db", "n")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.5/shelve.py", line 225, in open
return DbfilenameShelf (filename, flag, protocol, writeback)
File "/usr/local/lib/python2.5/shelve.py", line 209, in __init__
Shelf.__init__( self, anydbm.open(fil ename, flag), protocol, writeback)
File "/usr/local/lib/python2.5/anydbm.py", line 80, in open
raise error, "db type could not be determined"
anydbm.error: db type could not be determined

Peter
Apr 9 '07 #11
Peter Otten <__*******@web. dewrote:
Alex Martelli wrote:
BTW, if you DO want to call shelve.open on a path f that may correspond
to an arbitrary existing file (and want to toss away the previous
contents of that file, if any) the correct way to call is then:

s = shelve.open(wha tever_path, 'n')

since 'n' truncates an existing file, or creates a new one, as needed.

It's not entirely arbitrary since you get an exception if that file is not a
valid database:
>open("tmp.db ", "w").write("gar bage")
import shelve
shelve.open("t mp.db", "n")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.5/shelve.py", line 225, in open
return DbfilenameShelf (filename, flag, protocol, writeback)
File "/usr/local/lib/python2.5/shelve.py", line 209, in __init__
Shelf.__init__( self, anydbm.open(fil ename, flag), protocol, writeback)
File "/usr/local/lib/python2.5/anydbm.py", line 80, in open
raise error, "db type could not be determined"
anydbm.error: db type could not be determined
You're right -- anydbm.open, even when asked to "truncate the file",
still does mandate that the file, if it exists, be in some proper DBM
format (to determine which DBM module it will use to open it). This is
not intuitive, and needs to be mentioned in the Nutshell.
Alex
Apr 9 '07 #12
7stud wrote:
>Discussion subject changed to "Python universal build, OSX 10.3.9 and undefined symbols when
linking" by David Pratt

What gives? How come you can change the title of my thread?
On Apr 8, 8:14 pm, a...@mac.com (Alex Martelli) wrote:
>But if you open an errata for the missing explanation for the different
default value of the flag argument (use URL
<http://www.oreilly.com/catalog/pythonian2/errata/>), I'll be glad to
fix it for the next printing...

In my opinion, the most valuable thing you could do for a next
printing would be to expand the index to 3 times its current length.
As it is now, I think the index is woefully inadequate, which I find
surprising for a reference book. I haven't been able to find 3/4 of
the things I have looked up in the index. For instance __get__(),
__set__(), and sorted() are nowhere to be found in the index.

Also, the book is brand new, yet the cover has completely separated
from the spine of the book, and now the cover is only attached to the
first and last pages with a bit of glue.
That's not something an author can do much about ...

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com

Apr 9 '07 #13
"7stud" <bb**********@y ahoo.comwrites:
[...]
Also, the book is brand new, yet the cover has completely separated
from the spine of the book, and now the cover is only attached to the
first and last pages with a bit of glue.
I think they used to advertise that as a feature -- "stay-flat
binding" or something...
John
Apr 11 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4772
by: Rami A. Kishek | last post by:
Hi - this mysterious behavior with shelve is just about to kill me. I hope someone here can shed some light. First of all, I have this piece of code which uses shelve to save instances of some class I define. It works perfectly on an old machine (PII-400) running Python 2.2.1 under RedHat Linux 8.0. When I try to run it under Python for windows ME on a P-4 1.4 GHz, however, it keeps crashing on reading from the shelved file the second...
0
2479
by: seth | last post by:
Last week I encountered an AttributeError in my unit tests that I wasn'table to catch with an "except AttributeError" statement. The problem stemmed from a class that raised an error inside __init__and defined a __del__ method to clean up resources. I then discovered asimilar problem in the shelve module. This led me to two importantdiscoveries: 1. Attributes defined in __init__ after an error is raised will not be apart of the...
0
2044
by: ex laguna | last post by:
Hi, I have ran into a problem with py2exe 0.5.0 and shelve in python 2.3.3. The script works fine standalone, but not with py2exe. Does anyone have a solution of workaround for this? Thanks much. # Begin of setup.py from distutils.core import setup import py2exe setup(console=)
0
1371
by: Michael Mulcahy | last post by:
Hi All, Problem: Shelve module doesn't like me OS: Win2000 version: 2.3.3 Here is simple reproduction code and the error that occurs: import shelve, anydbm
0
1375
by: Ray O | last post by:
I have read a number of threads relating to problems with shelve, but I couldn't find one directly related my experience, so I would appreciate some advice. The closest one ended with a recommendation to upgrade to Python 2.3, but that, unfortunately, is out of my control. The system I use runs Python 2.2.2, and whichdb gives dbhash. The problem only occurs when serializing class instances; lists don't seem to be affected. Every time...
5
1339
by: Philippe C. Martin | last post by:
Hi, I just installed (compiled) Python 2.4.2 under Suse 10. The following code generates a seg error: import shelve print shelve.open ('test') I assume this has to do with the db behind shelve.
3
7945
by: Michele Petrazzo | last post by:
Hi, I'm trying a script on a debian 3.1 that has problems on shelve library. The same script work well on a fedora 2 and I don't know why it create this problem on debian: #extract from my code import shelve class XX: def __init__(self): self._data = shelve.open("/tmp/myfile")
6
4454
by: aomighty | last post by:
I wanted to write the following code: import shelve try: db = shelve.open(file, "r") except SomeError: print "Oh no, db not found" Only, I'm not sure what SomeError should be. I tried error, anydbm.error, shelve.open.anydb.error, etc. but can't find it. Things
5
1651
by: gluckj | last post by:
Hi, I'm not a Win ME fan myself (I'm a Mac user), but I'm here in Thailand developing software for special-needs kids, and the test PC in my home office is a Win ME machine (sigh). So when I ported my Python program today to the PC, it quickly crashed. Everything seems to work except for shelve. Using the latest version of Python (2.5.1), when I do the following in IDLE on the Win ME machine here's the result: Python 2.5.1...
0
10859
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10560
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10260
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9388
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6984
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4463
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.