python - Subclass lookup -
(I'm developing in Python 3.1, so if there's some shiny new 3.x feature, I know about it I have got a class (we call it a "packet") which acts as a parent, which is a few dozen packet types from some classes. Represent a legacy client-server protocol on which I have no control. (Packets are often wildly different behaviors, so I gave them their class to make their life easier.)
When obtaining a packet, I have a simple "dispatch" function Checks the packet headers to determine the type, then close the hands of the class that know how to deal with it.
I want to keep no lookup table with hand - it is uncomfortable and just asking for trouble, instead, I sorted by checking all the sub-sections of the packet I want to create a table on time, which will be the square variable which specifies which packet type they match, such as:
class login (packet): Type_id = 0x01
I thought, absolutely, object .__ subclasses (__ ()
walk through Regardless of this, but I get a little different perspective on safety and justification, to use it for things like this, with implications, that this implementation is specific and can not work in other places than CPITHON, and this future May be missing from CPython. Am I getting mad too? Is the __ sub Classes now considered to be the "real" part of the language?
If not, what's a good "dragon" method to do this?
__ subclass __
is part of the IIS Python language, and with Ironstone and Jyoth as well as CPI There is no money in hand for now, but I wonder if they have broken -) Anyone who has given you an impression that __ subclass __
was all problematic?! @gnibbler I see a comment in the same vein and I want to challenge it I: Do you can post the URL of Sbcleses __ __
to Python is not an important part of language ?!
Comments
Post a Comment