15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

# impter.py #<br />

#############<br />

import imptee<br />

imptee.show()<br />

imptee.foo = 123<br />

print 'foo from impter:', imptee.foo<br />

imptee.show()<br />

Once we make the update and change our references accordingly, we now have achieved the desired<br />

effect.<br />

foo from imptee: abc<br />

foo from impter: 123<br />

foo from imptee: 123<br />

12.5.5. Back to the __future__<br />

Back in the days of <strong>Python</strong> 2.0, it was recognized that due to improvements, new features, and current<br />

feature enhancements, certain significant changes could not be implemented without affecting some<br />

existing functionality. To better prepare <strong>Python</strong> programmers for what was coming down the line, the<br />

__future__ directives were implemented.<br />

By using the from-import statement and "importing" future functionality, users can get a taste of new<br />

features or feature changes enabling them to port their applications correctly by the time the feature<br />

becomes permanent. The syntax is:<br />

from __future__ import new_feature<br />

It does not make sense to import __future__ so that is disallowed. (Actually, it is allowed but does not<br />

do what you want it to do, which is enable all future features.) You have to import specific features<br />

explicitly. You can read more about __future__ directives in PEP 236.<br />

12.5.6. Warning Framework<br />

Similar to the __future__ directive, it is also necessary to warn users when a feature is about to be<br />

changed or deprecated so that they can take action based on the notice received. There are multiple<br />

pieces to this feature, so we will break it down into components.<br />

The first piece is the application programmer's interface (API). Programmers have the ability to issue<br />

warnings from both <strong>Python</strong> programs (via the warnings module) as well as from C [via a call to<br />

PyErr_Warn()].<br />

Another part of the framework is a new set of warning exception classes. Warning is subclassed directly<br />

from Exception and serves as the root of all warnings: UserWarning, DeprecationWarning, SyntaxWarning,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!