Can you give me a succinct explanation for the difference between
using Import pyTC and From pyTC Import *
It appears to me that one makes the file available while the other
actually loads the locations of the included functions.
That is when I use "From pyTC Import *" my main app can call
Test_Control without difficulty.
If I use "Import pyTC" my main app doesn't see the function Test
Control anymore unless I prefix the Call with pyTC.Test_Control
a bit more typing but it makes things clearer when you come back to this in 3 years time:)
The other thing that happens is all the imports in pyTC also become
unavailable...
they are still available, but you have to prefix with pyTC, e.g. if in pyTC you have
import xyz
then to access it you use pyTC.xyc
In either case a Frame I create in pyTC isn;t seen unless I
specifically pass a reference to...
pyTC.yourframe should do it too. Or if you need to access an instance of yourframe in another module then instead of passing a reference (and couple these two modules together) you might want to look at "pubsub" (stand alone or in wx.lib.pubsub - http://pubsub.sourceforge.net/
So, as I try to explain my design decision I am unsure as to how to
explain the importance of which form to use when importing files.
Thanks
smm
Just my point of view, hopefully someone can jump in and correct anything I state and/or complete it.
from x import *
Import everything from x, I think most people agree now a days that this should be used only very very rarely.
Problems with it:
- It pollutes your namespace, especially bad if "x" is a something big
- coming back later to a module using this it can be difficult to debug, i.e. in your case "how do you know where "Test_Control" comes from
import something or import something as st
Problems with it:
- more typing as you have to prefix everything either with "something." or "st."
Advantages:
- namespace is not polluted
- clean namespace makes debugging with an interactive debugger much easier/faster (e.g. the one in Boa Constructor or in Editra/Studio)
- everything is clearly identified from where it comes, e.g. in your case it would be very clear that "pyTC.Test_Control" comes from the module or package "pyTC"
I recently had some problems in trying to figure out inter and intra package import and have started a wiki page explaining my findings and it also gives some useful links.
RecipesEngineering - wxPyWiki - "Import and folder structure for application"
Hope this helps and doesn't cause more confusion:)
Werner
···
On 09/08/2011 02:44 PM, SpiritualMadMan wrote: