Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Mike Meyer
>> here's one attempt. (I'm no expert, so wait for better :-) >> >>> class ModFlagDict(dict): >> def __init__(self, *args, **kwargs): >> super(ModFlagDict, self).__init__(*args, **kwargs) >> self.modified = False >> def __setitem__(self, key, value): >>

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Paul Rubin
Steve Holden <[EMAIL PROTECTED]> writes: > > Make a subclass of dict, or an object containing a dictionary, that > > has a special __setattr__ method that traps updates and sets that > > /__setattr__/__setitem__/ ? Yes, thinkographical error. Thanks. -- http://mail.python.org/mailman/listinfo/p

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Steve Holden
Paul Rubin wrote: > [EMAIL PROTECTED] writes: > >>Still, I'd love to hear how you guys would do it. > > > Make a subclass of dict, or an object containing a dictionary, that > has a special __setattr__ method that traps updates and sets that /__setattr__/__setitem__/ ? regards Steve -- Stev

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Paul Rubin
Brian van den Broek <[EMAIL PROTECTED]> writes: > It's broken in at least one way: > > >>> newmd = ModFlagDict(3=4, 1=5) > SyntaxError: keyword can't be an expression newmd = ModFlagDict(**{3:4, 1:5}) -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Dan Sommers
On Thu, 12 Jan 2006 03:42:21 -0600, Brian van den Broek <[EMAIL PROTECTED]> wrote: > It's broken in at least one way: newmd = ModFlagDict(3=4, 1=5) > SyntaxError: keyword can't be an expression > So, as it stands, no integers, floats, tuples, etc can be keys on > initialization ... T

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > It's important that I can read the contents of the dict without > flagging it as modified, but I want it to set the flag the moment I add > a new element or alter an existing one (the values in the dict are > mutable), this is what makes it difficult. Because the values

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Brian van den Broek
Brian van den Broek said unto the world upon 12/01/06 03:42 AM: > [EMAIL PROTECTED] said unto the world upon 12/01/06 03:15 AM: > >>I can think of several messy ways of making a dict that sets a flag if >>it's been altered, but I have a hunch that experienced python >>programmers would probably ha

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Tim N. van der Leeuw
Should the dict flag when the dict itself has been updated? Or also when any of the items in the dict has been updated? Say you have a dict consisting of lists... The dict should be flagged as modified when an item is added; or when an item is replaced (you call dict.__setitem__ with a key that a

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Brian van den Broek
[EMAIL PROTECTED] said unto the world upon 12/01/06 03:15 AM: > I can think of several messy ways of making a dict that sets a flag if > it's been altered, but I have a hunch that experienced python > programmers would probably have an easier (well maybe more Pythonic) > way of doing this. > > It'

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Paul Rubin
[EMAIL PROTECTED] writes: > Still, I'd love to hear how you guys would do it. Make a subclass of dict, or an object containing a dictionary, that has a special __setattr__ method that traps updates and sets that modification flag. There are contorted ways the caller can avoid triggering the flag,

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Amit Khemka
Ideally, I would have made a wrapper to add/delete/modify/read from the dictionay. But other than this, one way i can think straight off is to "pickle" the dict, and to see if the picked object is same as current object. cheers, amit. On 12 Jan 2006 01:15:38 -0800, [EMAIL PROTECTED] <[EMAIL PROT

How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread sandravandale
I can think of several messy ways of making a dict that sets a flag if it's been altered, but I have a hunch that experienced python programmers would probably have an easier (well maybe more Pythonic) way of doing this. It's important that I can read the contents of the dict without flagging it a