reaching hidden methods + casting

per9000 per9000 at gmail.com
Thu Apr 12 03:18:19 EDT 2007


Hi,
can I reach a hidden method when doing ugly inheritance in python?

>>> class A:
...     def spin(self, n): print "A", n
...
>>> class B:
...     def spin(self, m): print "B", m
...
>>> class C(A,B):
...     def spin(self, k): print "C", k
...
>>> myC = C()
>>> dir(myC)
['__doc__', '__module__', 'spin']

In f.x. the C-family of languages I guess something like this would
call B.spin:
((B)myC).spin("Lancelot"); // almost forgot the ';'

Please correct me I am wrong (which I likely am) but as I understand
it this example calls the constructor of int instead of casting it,
right?
>>> leet = int('1337')
>>> leet
1337

So is there another way of digging into the past of a class? Or can/
should I create constructors for the classes A, B and C that takes
objects of the other classes?

Or should I have thought about getting unique names before I
implemented the ugly inheritance graph?

/Per

--

Per Erik Strandberg
blog: http://www.pererikstrandberg.se/blog/




More information about the Python-list mailing list