ASPN ActiveState Programmer Network
  ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups | Web Services
SEARCH
advanced | search help

Reference
ActivePython 2.4
What's New
What's new in Python 2.4?
Contents
1 PEP 218: Built-In Set Objects
2 PEP 237: Unifying Long Integers and Integers
3 PEP 289: Generator Expressions
4 PEP 292: Simpler String Substitutions
5 PEP 318: Decorators for Functions and Methods
6 PEP 322: Reverse Iteration
7 PEP 324: New subprocess Module
8 PEP 327: Decimal Data Type
9 PEP 328: Multi-line Imports
10 PEP 331: Locale-Independent Float/String Conversions
11 Other Language Changes
12 New, Improved, and Deprecated Modules
13 Build and C API Changes
14 Porting to Python 2.4
15 Acknowledgements
About this document ...

MyASPN >> Reference >> ActivePython 2.4 >> What's New >> What's new in Python 2.4?
ActivePython 2.4 documentation

9 PEP 328: Multi-line Imports

One language change is a small syntactic tweak aimed at making it easier to import many names from a module. In a from module import names statement, names is a sequence of names separated by commas. If the sequence is very long, you can either write multiple imports from the same module, or you can use backslashes to escape the line endings like this:

from SimpleXMLRPCServer import SimpleXMLRPCServer,\
            SimpleXMLRPCRequestHandler,\
            CGIXMLRPCRequestHandler,\
            resolve_dotted_attribute

The syntactic change in Python 2.4 simply allows putting the names within parentheses. Python ignores newlines within a parenthesized expression, so the backslashes are no longer needed:

from SimpleXMLRPCServer import (SimpleXMLRPCServer,
                                SimpleXMLRPCRequestHandler,
                                CGIXMLRPCRequestHandler,
                                resolve_dotted_attribute)

The PEP also proposes that all import statements be absolute imports, with a leading "." character to indicate a relative import. This part of the PEP was not implemented for Python 2.4, but was completed for Python 2.5.

See Also:

PEP 328, Imports: Multi-Line and Absolute/Relative
Written by Aahz. Multi-line imports were implemented by Dima Dorfman.

See About this document... for information on suggesting changes.

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState 2004 All rights reserved