471,350 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

list property fires get on append

ian
I've created a class that has a property which points at a private
list. When I try to use the append() function on this list property,
the fget method is fired rather than the fset method. If I directly
set my property to a literal list, the set method fires.

Here's a stripped down version of my code:

class Hierarchy(object):
_children = []

def __init__(self):
return

def get_children(self):
print("GETTING")
return self._children

def set_children(self, value):
print("SETTING")
self._children = value

children = property(get_children, set_children)

-----USAGE------

import Hierarchy
hierarchy = Hierarchy.Hierarchy()
# this fires a get for some reason
hierarchy.children.append( Hierarchy.Hierarchy())
# this fires a set as expected
hierarchy.children = [Hierarchy.Hierarchy()]

------RESULT------

it prints:

GETTING
SETTING
Jan 6 '08 #1
0 797

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Martin Christensen | last post: by
7 posts views Thread by Dave Hopper | last post: by
reply views Thread by Scott K | last post: by
7 posts views Thread by Lonnie Princehouse | last post: by
1 post views Thread by David Veeneman | last post: by
2 posts views Thread by Lespaul36 | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.