object oriented programming question

Daniel Nogradi nogradi at gmail.com
Mon Dec 19 10:51:07 CET 2005


Hi Michael, one more thing.

As you could see my only goal was to be able to say

1  inst = x()
2
3  inst.a("some string")
4  inst.a.func()
5
6  inst.b("some other string")
7  inst.b.func()

and (3) should modify 'inst.content' in some way depending on "some string"
and the attribute 'a' while (4) should modify 'inst.content' using 'func()'.
Similarly for (6) and (7) using another attribute 'b'. Now maybe the way I
solved it (using your suggestion) is not the simplest way to do it,
especially because I have to define a class '_a' and then create an instance
'a' of this class '_a' inside 'x'. And if I have many such classes, '_a',
'_b', '_c', .... etc, then I have to write everything twice, once define the
class and then create the instances inside 'x' which can be inconvenient if
I decide to add another class.

Is there a smarter way if the only constraint is that I can say things like
(1-7)?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051219/e2f99ad0/attachment.html>


More information about the Python-list mailing list