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

shelf membership

can you shelve objects with membership?

this gives you:

TypeError: object does not support item assignment
dict 0 True
Exception exceptions.TypeError: 'object does not support item assignment'
in ignored
ignored is a bit mysterious. tx in advance.
from shelve import *
class MyShelf(DbfilenameShelf):
def __init__(self, filename, flag='c', protocol=None,
writeback=False, binary=None):
self.__dict__['ready']=False
DbfilenameShelf.__init__(self, filename, flag, protocol,
writeback, binary)
self.ready=True
def __setattr__(self,name,value):
if not self.ready:
self.__dict__[name]=value
else:
print name, value, self.ready
self.__dict__[name]=value
DbfilenameShelf.__setitem__(self,name,value)

def open(filename, flag='c', protocol=None, writeback=False, binary=None):
return MyShelf(filename, flag, protocol, writeback, binary)

Mar 31 '07 #1
3 1241
On Apr 1, 8:02 am, Aaron Brady <a...@uchicago.eduwrote:
can you shelve objects with membership?

this gives you:

TypeError: object does not support item assignment
dict 0 True
Exception exceptions.TypeError: 'object does not support item assignment'
in ignored
ignored is a bit mysterious. tx in advance.

from shelve import *
class MyShelf(DbfilenameShelf):
def __init__(self, filename, flag='c', protocol=None,
writeback=False, binary=None):
self.__dict__['ready']=False
DbfilenameShelf.__init__(self, filename, flag, protocol,
writeback, binary)
self.ready=True
def __setattr__(self,name,value):
if not self.ready:
self.__dict__[name]=value
else:
print name, value, self.ready
self.__dict__[name]=value
DbfilenameShelf.__setitem__(self,name,value)

def open(filename, flag='c', protocol=None, writeback=False, binary=None):
return MyShelf(filename, flag, protocol, writeback, binary)
Please supply the *full* traceback, using copy/paste.

Apr 1 '07 #2
En Sat, 31 Mar 2007 21:22:20 -0300, John Machin <sj******@lexicon.net>
escribió:
On Apr 1, 8:02 am, Aaron Brady <a...@uchicago.eduwrote:
>can you shelve objects with membership?

this gives you:

TypeError: object does not support item assignment
dict 0 True
Exception exceptions.TypeError: 'object does not support item
assignment'
in ignored
ignored is a bit mysterious. tx in advance.

Please supply the *full* traceback, using copy/paste.
Not this time. Exceptions in __del__ are ignored and all you got is that
message.

To the OP: This comes from Shelf.__del__, which in turn calls close(),
which tries to set the internal dict to 0 (?!). You may try overriding
close() - but what do you want to achieve, exactly?

--
Gabriel Genellina

Apr 1 '07 #3
Aaron Brady wrote:
can you shelve objects with membership?

this gives you:

TypeError: object does not support item assignment
dict 0 True
Exception exceptions.TypeError: 'object does not support item assignment'
in**ignored
ignored is a bit mysterious.**tx*in*advance.

from shelve import *
class MyShelf(DbfilenameShelf):
**********def*__init__(self,*filename,*flag='c',*p rotocol=None,*
writeback=False, binary=None):
******************self.__dict__['ready']=False
******************DbfilenameShelf.__init__(self,*f ilename,*flag,*protocol,*
writeback, binary)
******************self.ready=True
**********def*__setattr__(self,name,value):
******************if*not*self.ready:
**************************self.__dict__[name]=value
******************else:
**************************print*name,*value,*self. ready
**************************self.__dict__[name]=value
**************************DbfilenameShelf.__setite m__(self,name,value)

def open(filename, flag='c', protocol=None, writeback=False, binary=None):
******return*MyShelf(filename,*flag,*protocol,*wri teback,*binary)
The root cause of your problems is that you are mixing two namespaces: that
of the shelved items and that used internally by DbfilenameShelf to
implement the shelving functionality.

While the cleanest approach is to not do it, you can make such a mix work
in /some/ cases if you give precedence to the "implementation namespace".
This requires that you pass by any implementation attributes

pass_through_attributes = [...]
def __setattr__(self, name, value):
if name in pass_through_attributes:
self.__dict__[name] = value # *
else:
# do whatever you like

(*) Assuming that DbfilenameShelve is an oldstyle class and does not itself
implement a __setattr__() method.

From your error message one can infer that pass_through_attributes must
contain at least the name "dict"; for a complete list you have to inspect
the Dbfilename source code.

An approach that is slightly more robust is to wrap DbfilenameShelf -- make
it an attribute of MyShelf -- and pass the relevant method calls to the
attribute.

Peter
Apr 1 '07 #4

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

Similar topics

9
by: Paul Keegstra | last post by:
Hi, I am currently working on an asp.net 2.0 web site that is a replacement of a classic asp web site. The current web site uses a Commerce Server 2002 database for storing user information. ...
4
by: Pony Tsui | last post by:
I was install the starter kits CLUB, and created a CLUB WEB SITE, this application use the MemberInfo table in club.mdf to store the membership'data, but i can not find out where to define or...
2
by: Balaji | last post by:
Hi All, Can I use more than one membership provider for a given website? I understand only one of them could be default one. If yes, then how to programmatically access the other membership...
3
by: ryan.mclean | last post by:
Hello everyone, I am wondering, can the membership provider be changed at runtime? Perhaps the connectionStringName? I would like to use a different database based on the server the site is...
4
by: =?Utf-8?B?Q2hyaXMgQ2Fw?= | last post by:
I have been having some trouble with implementing a custom Membership Provider. We have a custom data store and business logic that pulls user information. I need some level of functionality...
3
by: Glenn | last post by:
My current classic-ASP site has users, projects, roles and the 2.0 membership looks like a perfect fit, but I'm having trouble finding examples of how to have users that belong to different...
1
by: =?Utf-8?B?ZVByaW50?= | last post by:
Asp.Net v2.0 I have created a web application and I am using it from a single website and database. The web application has different ‘portals’ – each independent and I am using the...
1
by: =?Utf-8?B?ZVByaW50?= | last post by:
Asp.Net v2.0 I have created a web application and I am using it from a single website and database. The web application has different ‘portals’ – each independent and I am using the...
8
by: Nick | last post by:
Hi there, Membership.GetNumberOfUsersOnline() works great the first time, then jumps up to the number of users registered in the system. I have tried enumerating through each user individually...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.