Shelve and classes

Curtis Jensen cjensen at bioeng.ucsd.edu
Wed Aug 9 23:26:18 EDT 2000


j vickroy wrote:
> 
> Hello Curtis,
> 
> I'm running Python 1.5.2 and here is a sample session:
> 
> >>>
> >>> import shelve
> >>> writer = shelve .open ('my_db')
> >>> writer ['1'] = 'a'
> >>> writer .close()
> >>> reader = shelve .open ('my_db')
> >>> reader ['1']
> 'a'
> >>> reader .close()
> >>>
> 
> Notice, I did not specify a filetype suffix for the name of the dbm file.
> Try that; I doubt the problem is with the class you were trying to archive.
> 

I'm also running Python 1.5.2 on IRIX 6.5
I tried that.  it works for something like 'a' but for my class, I got
the same error as before.  Here is my sample session:

>>> from continuity_wrapper import *

>>> import shelve
>>> d = shelve.open( 'my_db' )
>>> d['nodes'] = nodes
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "/usr/local/Python/lib/python1.5/shelve.py", line 71, in
__setitem__
    self.dict[key] = f.getvalue()
dbm.error: Cannot add item to database
>>> d['1'] = 'a'
>>> d.close()
>>> read = shelve.open( 'my_db' )
>>> read['1']
'a'
>>> read.close() 

>>> nodes
<Nodal.Nodal instance at 100aa478>
>>> dir(nodes)
['arc_length_deriv', 'basis_num', 'basis_type_num',
'deform_global_param_ZA', 'deform_global_param_ZP', 'elemnode_face_num',
'global_DOF_num', 'global_face_num', 'global_node_num', 'global_nodes',
'global_param_XA', 'global_param_XP', 'line_num_of_arcelem',
'line_num_of_arcface', 'mesh_DOF', 'nodal_basis_type',
'nodal_data_list', 'nodal_derv_dep_var', 'nodal_derv_geom_var',
'nodal_pos_list', 'node_corner', 'num_dep_var_elem', 'num_dep_var_node',
'num_of_elem_nodes_in_face', 'num_xj_coor', 'num_xj_coor_in_elem',
'old_scaling_factors', 'shared_corner']
>>> nodes.nodal_data_list
array([0, 0, 0, 0, 0, 0, 0])

continuity_wraper sets up the nodes instance.  I've put a little more
information about nodes in here; just in case it helps.

-- 
Curtis Jensen
cjensen at bioeng.ucsd.edu
http://www-bioeng.ucsd.edu/~cjensen/
FAX (425) 740-1451



More information about the Python-list mailing list