Tuesday, January 06
I just wrote an almost completely generic object-oriented wrapper for Metakit records in 35 lines of Python code. Which includes 4 lines of comments, 5 blank lines and 5 lines of debugging code.
It handles searching by the primary key, creation if it's not found, and completely transparent transferral of data from the argh. Uzgbf. Never mind. Back to the drawing board.
Update: I just wrote an even more almost completely generic object-oriented blah blah, same length (well, I took out the 5 debugging lines), only this time it doesn't screw everything up when two threads try to manipulate the same record.
I call it MEOW: The Metakit Easy Object Wrapper. Hooray for getattr, setattr and hasattr! I've never tinkered with Python objects like this before, but after only a couple of hours it all makes sense. In fact, it's obvious that this is how to do it. (Actually, there's probably an even simpler way that I have yet to find, but pfft. This is neat and understandable, very general, fast enough, and works.)
A little more tweaking and I'll have a base class that I can derive all my objects from. Yay!
(For those of you saying What?: Persistent objects made easy. For those of you still saying What?: Shiny programmer thing!)
More Update: Poo! The mere presence of __getattr__ in a class definition causes the class to run like molasses in January. When I enable __getattr__, time taken to instantiate the class increases by a factor of 250 - even though it is never called! I may have to ask the Python wizards about this.
Err, in theory it should never be called. In practice, it is getting called 2988 times for a single instantiation. Odd, that.
Oh. Using hasattr() within the definition of __getattr__ is a Bad Thing. Access __dict__ directly. Right.
Posted by: Pixy Misa at
01:19 PM
| Comments (5)
| Add Comment
| Trackbacks (Suck)
Post contains 307 words, total size 2 kb.
Posted by: Lee at Tuesday, January 06 2004 05:02 PM (BpPRO)
Posted by: Victor at Tuesday, January 06 2004 06:06 PM (L3qPK)
Posted by: Rob at Tuesday, January 06 2004 08:52 PM (ZfpQw)
Posted by: Pixy Misa at Tuesday, January 06 2004 10:27 PM (kOqZ6)
Posted by: Simon at Wednesday, January 07 2004 12:44 AM (UKqGy)
56 queries taking 0.126 seconds, 362 records returned.
Powered by Minx 1.1.6c-pink.









