Modified Import

Can supply new names for modules

     import socket as sock
     s = sock.socket(sock.AF_INET,sock.SOCK_STREAM)
     ...
     from string import replace as rep
     rep(s,"foo","bar")

__all__ attribute

  • A module can explicitly control list of exports for from module import *
     def foo():
        ...
     def bar():
        ...
     __all__ = ["foo"]

Case sensitivity

  • Python 2.1 provides case sensitive import on case-insensitive platforms.
  • Example: Windows is case-preserving, but case-insensitive
<<< O'Reilly OSCON 2001, New Features in Python 2, Slide 33
July 26, 2001, beazley@cs.uchicago.edu
>>>