Yes, it depends how the library was designed. Some are designed so that you can import some of the library into your global namespace. For example, in Pygame library, it's accepted to do<div>import pygame</div><div>from pygame.locals import *</div>
<div><br></div><div><br></div><div>This keeps the methods like</div><div>pygame.init()</div><div>pygame.display.set_mode()</div><div><br></div><div>etc.</div><div>but it lets you avoid having to do</div><div>for event in pygame.event.get():</div>
<div> if event.type == pygame.KEYDOWN and event.key == pygame.K_UP:</div><div><br></div><div><br></div><div>instead you can do</div><div><br></div><div>for event in pygame.event.get():</div><div> if event.type == KEYDOWN and event.key == K_UP:</div>
<div><br></div><div><br></div><div>But I don't know of any case where it's preferable to use the "from" syntax, it's mostly just a laziness thing.</div><div><br></div><div>-Luke</div><div><br></div><div>
<br><div class="gmail_quote">On Fri, Jan 8, 2010 at 1:39 PM, Rob Cherry <span dir="ltr"><<a href="mailto:pythontutor@lxrb.com">pythontutor@lxrb.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Extending on this advice somewhat - is it *ever* correct to "import foobar".<br>
<br>
There are countless examples of<br>
<br>
import os,sys<br>
<br>
etc,etc. Strictly speaking should we always be using "from" to only<br>
get what we know we need?<br>
<br>
Thanks,<br>
<font color="#888888"><br>
Rob<br>
</font></blockquote></div><br></div>