Ed Leafe wrote: > On Nov 17, 2006, at 4:46 PM, Paul McNett wrote: > >>> sure I see why you are doing 'from' and not just 'import.' >>> wouldn't it be >>> better to do: >>> >>> import FrmBase >>> class FrmEvents(FrmBase.FrmBase): >>> >>> So that there isn't an extra.. um.. something ? >> It is a style issue, completely subjective. When importing from >> modules >> to do subclasses, I like to import just the class I want to >> instantiate >> or subclass. Hence, from x import Y. > > The only reason not to import specific classes is if you may have > more than one with a given name in the namespace. "from foo import > bar" brings 'bar' into the current namespace, while "import foo" > leaves 'bar' in the foo namespace. So, if you really think that there > may be another object in the namespace named 'FrmBase', you shouldn't > use the 'from...' format. Otherwise, it makes no difference, except > to make the code that uses the imported class a bit cleaner.
Right, and for this reason it is pretty universally agreed that 'from x import *' is very bad because you really have no idea what names you may be polluting your namespace with. But 'from x import Y' is fine, because it is explicit. I take the argument that it is much better to keep stuff in their own namespaces, in fact I heartily agree. But in the case of modules named the same as the class they design, I can't stand things like: class foo(Bar.Bar): So it is a (mostly harmless) style thing. -- pkm ~ http://paulmcnett.com _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
