On Sun, Dec 20, 2009 at 1:20 PM, Stephen Hansen <apt.shan...@gmail.com>wrote:
> On Sun, Dec 20, 2009 at 3:05 AM, Victor Subervi > <victorsube...@gmail.com>wrote: > >> Of course, I can pass the page name as a parameter, but that's not >> elegant. >> > > That is precisely what it is in fact-- elegant; it is non-elegant to have > magical behavior where what 'imports' something somehow changes or > determines how that something behaves. > > It may be possible to go into dark places to discover what code first > imported a module, but its not possible to discover what code does > subsequent imports-- and in either case, this is /not/ something that has > any sort of elegance to it. Its deeply hackish. > > If you want a piece of code to have a variable number of differing > behaviors, that's something you can handle in many elegant ways. That's > something inheritance is good for, with a core default behavior represented > in one class and more specialized behavior represented in sub-classes. But > either way, you have to tell it which class to create at the moment, which > entails passing in a parameter explicitly activating one or the other. This > is a good thing. Don't try to get around it. > Inelegant. This will be elegant: ourFile = string.split(__file__, "/") p = ourFile[len(ourFile) - 1] p = p[: - 3] site = ourFile[4][:-10] if site != '': site = site[:-1] from this import that(site) Now it's automated. V
-- http://mail.python.org/mailman/listinfo/python-list