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
import pygame
from pygame.locals import *


This keeps the methods like
pygame.init()
pygame.display.set_mode()

etc.
but it lets you avoid having to do
for event in pygame.event.get():
    if event.type == pygame.KEYDOWN and event.key == pygame.K_UP:


instead you can do

for event in pygame.event.get():
    if event.type == KEYDOWN and event.key == K_UP:


But I don't know of any case where it's preferable to use the "from" syntax,
it's mostly just a laziness thing.

-Luke


On Fri, Jan 8, 2010 at 1:39 PM, Rob Cherry <pythontu...@lxrb.com> wrote:

> Extending on this advice somewhat - is it *ever* correct to "import
> foobar".
>
> There are countless examples of
>
> import os,sys
>
> etc,etc.  Strictly speaking should we always be using "from" to only
> get what we know we need?
>
> Thanks,
>
> Rob
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to