Re: Question about isinstance()

2006-01-27 Thread Mr.Rech
bruno at modulix wrote: > Mr.Rech wrote: > > All in all it seems that the implementation that uses isinstance() is > > better in this case... > > You could also use something like Zope's Interfaces... But I'm not sure > it's worth the extra complexity. T

Re: Question about isinstance()

2006-01-27 Thread Mr.Rech
After reading all your comments and thinking a little to my specific case, I think it is definetively better to go with the "isinstance()" implementation. My objects represent mathematical function defined over a numerical grid, and I hardly think of an unrelated class objects that could be compare

Re: Question about isinstance()

2006-01-26 Thread Mr.Rech
All in all it seems that the implementation that uses isinstance() is better in this case... Thanks for your comments, Andrea. -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about isinstance()

2006-01-26 Thread Mr.Rech
Mmm... I've not considered such an event... Would you say it is one of those rare case in which isinstance() "can be used"? Any other suggestion? Thanks, Andrea -- http://mail.python.org/mailman/listinfo/python-list

Question about isinstance()

2006-01-26 Thread Mr.Rech
Hi all, I've read some thread about isinstance(), why it is considered harmful and how you can achieve the same results using a coding style that doesn't break polymorphism etc... Since I'm trying to improve my Python knowledge, and I'm going to design a class hierarchy from scratch, I'd like to ha

Re: Help with dynamic attributes.

2006-01-09 Thread Mr.Rech
I would have sworn that it had been a better way to get it. Thanks a lot, Andrea -- http://mail.python.org/mailman/listinfo/python-list

Help with dynamic attributes.

2006-01-09 Thread Mr.Rech
Hi all, I was writing a simple class when I get a strange error message that I can't understand. Hopefully someone could help me here. My class's init method takes a list of lists as input argument and I'd like to create several attributes each one referencing one item of the passed list. Easy-of-

Re: Implementing deepcopy

2005-12-07 Thread Mr.Rech
Thanks for your answer. Since perfomances are not an issue in my case I think I'd stay with copy.copy(). In this way I'm not required to know in advance the object type, and I can implement a __deepcopy__ method for my own classes as follows: >>> def __deepcopy__(self, memo = {}): new

Implementing deepcopy

2005-12-07 Thread Mr.Rech
Hi all, I'm writing a class with some attributes which deepcopy can't cope with, and I need some more clarifications. Sorry for my newbie questions, but I'm a newbie indeed (or a sort of). Suppose one of the attributes of my class is a dictionary whose values are callable functions, such as: >>>d

Re: Instances behaviour

2005-12-02 Thread Mr.Rech
I see your point. Looking again at my metaclass implementation and comparing it with your abstract class + inheritance approach it turns out that the latter is definetively more straightforward, easier to maintain and all in all more pythonic. Sorry, but being an OOP newbie put me in the position

Re: Instances behaviour

2005-12-02 Thread Mr.Rech
Thanks for your suggestions. They are very usefull and indeed bypass my problem. However, I've found a (perhaps) more elegant way to get the same result using metaclasses. My idea is to define my classes as follows: >>> class meta_A(type): def __new__(cls, classname, bases, classdict):

Instances behaviour

2005-12-01 Thread Mr.Rech
Hi all, I've been using Python for 3 years, but I've rarely used its OOP features (I'm a physicist, sorry). Now, after having read a lot about Python OOP capabilities, I'm trying to get advantage of this (for me) new paradigm. As a result I've a lot of somewhat philosophical questions. I will start