472,368 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,368 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 6356
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.