Request for feedback on my first Python program
Raseliarison nirinA
nirina at mail.blueline.mg
Sat May 31 08:16:59 EDT 2003
"Scott Meyers" writes:
> - Is it better to get into the habit of (a) importing modules and using
> fully qualified names or (b) importing selective names from modules
> and using them without qualification? That is, which is generally
> better?
>
> import sys # a
> sys.exit(1)
>
> from sys import exit # b
> exit(1)
>
i cannot tell which is better. personally, i choose between them following
the context.
for example, with the form (a), one can use the same function names in
several modules. and when i use Tkinter, i always call:
from Tkinter import *
sometimes, the built-in function __import__ is useful:
SYS = __import__('sys')
QUIT = getattr(SYS,'exit')
QUIT(1)
if you want only one function from a module, you can specify its name, like
this:
from sys import exit as QUIT
QUIT(1)
also, take a look at the imp module:
>>> import imp
>>> help(imp)
Help on built-in module imp:
NAME
imp
FILE
(built-in)
DESCRIPTION
This module provides the components needed to build your own
__import__ function.
--
nirinA
--
More information about the Python-list
mailing list