473,396 Members | 2,158 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,396 software developers and data experts.

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.framework/Versions/2.3/lib/
python2.3/shelve.py", line 231, in open
return DbfilenameShelf(filename, flag, protocol, writeback,
binary)
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/shelve.py", line 212, in __init__
Shelf.__init__(self, anydbm.open(filename, flag), protocol,
writeback, binary)
File "/System/Library/Frameworks/Python.framework/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.AttributeError: "DbfilenameShelf instance has no
attribute 'writeback'" in ignored
---------------------

What should I do to correct that error?

Apr 5 '07 #1
13 6461
On Apr 5, 12:14 pm, "7stud" <bbxx789_0...@yahoo.comwrote:
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.framework/Versions/2.3/lib/
python2.3/shelve.py", line 231, in open
return DbfilenameShelf(filename, flag, protocol, writeback,
binary)
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/shelve.py", line 212, in __init__
Shelf.__init__(self, anydbm.open(filename, flag), protocol,
writeback, binary)
File "/System/Library/Frameworks/Python.framework/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.AttributeError: "DbfilenameShelf instance has no
attribute 'writeback'" in ignored
---------------------

What should I do to correct that error?
how did you generate aaa.txt?

Apr 5 '07 #2

mi*******@gmail.com wrote:
On Apr 5, 12:14 pm, "7stud" <bbxx789_0...@yahoo.comwrote:
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.framework/Versions/2.3/lib/
python2.3/shelve.py", line 231, in open
return DbfilenameShelf(filename, flag, protocol, writeback,
binary)
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/shelve.py", line 212, in __init__
Shelf.__init__(self, anydbm.open(filename, flag), protocol,
writeback, binary)
File "/System/Library/Frameworks/Python.framework/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.AttributeError: "DbfilenameShelf instance has no
attribute 'writeback'" in ignored
---------------------

What should I do to correct that error?

how did you generate aaa.txt?
In a text editor, which I then saved to that directory.

Apr 5 '07 #3
On Apr 4, 10:22 pm, mik3l3...@gmail.com wrote:
how did you generate aaa.txt?
Ok, I got it to work by supplying a filename that didn't previously
exist. Neither the book I am reading, "Beginning Python: From Novice
to Professional" nor the book I am using as a reference, "Python in
Nutshell", happens to mention that important fact.
Apr 5 '07 #4
7stud wrote:
On Apr 4, 10:22 pm, mik3l3...@gmail.com wrote:
>how did you generate aaa.txt?

Ok, I got it to work by supplying a filename that didn't previously
exist. Neither the book I am reading, "Beginning Python: From Novice
to Professional" nor the book I am using as a reference, "Python in
Nutshell", happens to mention that important fact.

It seems to make sense that you have to open a file as writable in order
to be able to change its contents, though, doesn't it?

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 5 '07 #5
On Apr 5, 5:20 am, Steve Holden <s...@holdenweb.comwrote:
7stud wrote:
On Apr 4, 10:22 pm, mik3l3...@gmail.com wrote:
how did you generate aaa.txt?
Ok, I got it to work by supplying a filename that didn't previously
exist. Neither the book I am reading, "Beginning Python: From Novice
to Professional" nor the book I am using as a reference, "Python in
Nutshell", happens to mention that important fact.

It seems to make sense that you have to open a file as writable in order
to be able to change its contents, though, doesn't it?
My text file was writable.

Apr 5 '07 #6
7stud <bb**********@yahoo.comwrote:
On Apr 4, 10:22 pm, mik3l3...@gmail.com wrote:
how did you generate aaa.txt?

Ok, I got it to work by supplying a filename that didn't previously
exist. Neither the book I am reading, "Beginning Python: From Novice
to Professional" nor the book I am using as a reference, "Python in
Nutshell", happens to mention that important fact.
I notice that the Nutshell (2nd ed) has a small errata that may be
what's confusing you. On p. 284, under "The shelve module", I say:

shelve supplies a function open that is polymorphic to anydbm.open .

On p. 286, you find the whole page explaining anydbm.open (which is why
I didn't want to duplicate all that info), including the detail that the
default value for argument flag is 'r' (meaning read-only operation, and
on a file that must already exist). However, shelve.open is not
_entirely_ polymorphic to anydbm.open, in this small but crucial detail:
the defaulf value for argument flag is 'c' (meaning, as p. 286 correctly
says, that it creates a new file if it doesn't exist, but also accepts
and opens an existing file, and operation is read-write).

Of course, if the existing file was not created by the shelve module,
there may well be errors -- shelve uses DBM-like archive files, as
clearly explained on p. 284, not arbitrary text files (nor for that
matter arbitrary binary files). As the documentation for anydbm.open
explicitly says, it's all about DBM files; adding "will not work right
if you try to open just any random textfile or other file you may happen
to have laying around on your favourite storage device" would be
insulting to the reader and a waste of space, so I don't consider it a
valid errata.

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, changing the previously quoted sentence
to:

shelve supplies a function open that is polymorphic to anydbm.open
(except that the default value of argument flag is 'c' rather than 'n').
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.

That is also shown in the code example for module shelve in the Nutshell
(the 'n' occurs just at the top of p. 285).
Alex

Apr 9 '07 #7
Hi. I am on a PPC and have been getting the same undefined symbols
traceback when linking applications after compiling. A few weeks back I
posted on a problem to py***********@python.org after attempting to
build mod_python, today its pylucene - same problem. I initially
shrugged off the problem with mod_python as likely an issue with the mac
port.

Crazy thing is that I built the same version of pylucene successfully
just before upgrading to universal build of 2.4.4 python for mac without
problems. So I recompiled the same version of pylucene I had previously
built with a PPC only build of python to evaluate whether my thoughts
were right. I had a hunch universal python was causing my trouble with
mod_python and a newer build of pylucene and it appears I was right. I
am currently using Mac OSX 10.3.9 on a PPC with universal build of
2.4.4. I should say that other than linking problem I am experiencing,
the python functions as it should.

From mod_python build:

ld: Undefined symbols:
_fstatvfs referenced from Python expected to be defined in libSystem
_lchown referenced from Python expected to be defined in libSystem
_statvfs referenced from Python expected to be defined in libSystem
apxs:Error: Command failed with rc=65536
..
make[1]: *** [mod_python.so] Error 1
make: *** [do_dso] Error 2

From pylucene build:

ld: Undefined symbols:
_fstatvfs referenced from Python expected to be defined in libSystem
_lchown referenced from Python expected to be defined in libSystem
_statvfs referenced from Python expected to be defined in libSystem
gmake: *** [release/_PyLucene.so] Error 1

I have googled to see there have been others with this issue however
they have tended to communicate about the problem on software lists or
forums specific to the software they were attempting to build. I did not
see this resolved in any case that I have read.

I am hoping someone may be able to advise a possible solution. I am
planning on upgrading to OSX 10.4 within a week since mac is not making
the JDK 1.5.0 available for OSX 10.3 users - so pretty much being forced
into upgrading in any case.

If you had the same linking issue with the universal build of python it
would be good to hear from you - better yet would be some way of solving
this or at least understanding what may be going on. I have posted to
py***********@python.org in the interim but there is very little traffic
on this list. In the meantime I thought there may other OSX 10.3.9 users
out there who may have run into the same fate. Many thanks.

Regards,
David
Apr 9 '07 #8
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.

Apr 9 '07 #9
7stud <bb**********@yahoo.comwrote:
...
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.
Suggest that to O'Reilly: they're the one who prepare the index, not me;
I only get to point out errors I may notice on it during the roughly 4-5
days I get to review it in the late phases of production.

I don't believe any major change in the index can be contemplated
between one printing and another, but your complaint, if directed to the
appropriate ears, might possibly infuence some future edition.

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.
Similarly, I have no control on any aspect of the physical production of
the book: again, telling me about your complaints is absolutely useless,
if you want any chance to have an effect, tell O'Reilly.
Alex
Apr 9 '07 #10
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("garbage")
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(filename, 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(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("garbage")
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(filename, 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**********@yahoo.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
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...
0
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...
0
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...
0
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
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...
5
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...
3
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...
6
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...
5
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...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.