Re: Python help
Both of these are somewhat unpythonic in nature. The first goes against the idea of dynamic casting. The second is a perfect dictionary application.
Still:
For the first you could make a class that extends the list class and override its .append method to check for a certain type, probably given to the constructor. You may also need to override some other methods in order to make sure the user doesn't change the objects type in another way.
For the second you might be able to catch the error that comes with trying to access a non-existent member variable and use it to create the variable and initialize it to the input value - no warranty on that (might not be practical/possible).
Last edited by smartbei; November 8th, 2007 at 09:48 AM.
Intel E6300 / MSI P4M890M / 2GB DDR2 677 / 80GB + 1TB SATA2 / GeForce 6200TC / DL DVD+-RW / Dell 24" U2410
Bookmarks