I should add (that as I understand it), when you do a 'from foo import blah', or 'from foo import *', this is doing a <i>copy</i> (effectively) of that module's attributes into the current namespace. Doing "import foo" or "import foo as goo" is keeping a <i>reference </i>to the imported module rather than a copy. <br>
<br>If you use the 'from import' system, changes made to attrs of the imported module <i>won't</i> be seen by any other module that imported it. <br>If you do just an 'import' on a module (or 'import ... as ...'), then changes made to attrs on the imported module <i>will </i>be seen by othe modules that import it as well. I hope that is somewhat clear. ;)<br>
<br><div class="gmail_quote">On Sat, Jan 9, 2010 at 8:35 AM, Lowell Tackett <span dir="ltr"><<a href="mailto:lowelltackett@yahoo.com">lowelltackett@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
If I might offer one small comment...<br><br>It seems to me that this argument also goes to a code readability issue; ergo, if you choose "from foobar..." as opposed to "import foobar", then from that point on you only need employ foobar's methods in your code, and they are not alway easily recognizable. i.e, by importing foobar, you will always prefix a method with its' parent module name, which [I think] makes the code more understandable.<br>
<br><span style="font-family: comic sans ms;">From the <span style="font-style: italic;">virtual</span> desk of Lowell Tackett <img src=""><br></span><br><br>--- On <b>Sat, 1/9/10, Alan Gauld <i><<a href="mailto:alan.gauld@btinternet.com" target="_blank">alan.gauld@btinternet.com</a>></i></b> wrote:<br>
<blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From:
Alan Gauld <<a href="mailto:alan.gauld@btinternet.com" target="_blank">alan.gauld@btinternet.com</a>><br>Subject: Re: [Tutor] Question on "import foobar" vs "from foobar import *"<br>To: <a href="mailto:tutor@python.org" target="_blank">tutor@python.org</a><br>
Date: Saturday, January 9, 2010, 10:21 AM<div><div></div><div class="h5"><br><br><div><br>"Rob Cherry" <<a href="http://mc/compose?to=pythontutor@lxrb.com" target="_blank">pythontutor@lxrb.com</a>> wrote<br>
<br>> Extending on this advice somewhat - is it *ever* correct to "import foobar".<br><br>Yes, it is *usually* correct to "import foobar" and rarely correct to "from foobar".<br>The exception being if you only need one or two names from foobar, but<br>
usually you need a lot more, in which case use import foobar.<br><br>To save typing you can give foobar a shorter name:<br><br>import foobar as fb<br><br>For some reason that convenience feature doesn't get mentioned<br>
all that often but I use it a lot.<br><br>HTH,<br><br><br>-- Alan Gauld<br>Author of the Learn to Program web site<br><a href="http://www.alan-g.me.uk/" target="_blank">http://www.alan-g.me.uk/</a> <br></div></div></div></blockquote>
</td></tr></tbody></table><br></blockquote></div><br>