Python has moved to sourceforge.
Unicode support
u'string'
\u0000
encode([encoding]) method (returns an 8-bit string in the desired encoding)
sys.setdefaultencoding([encoding])
Combining 8-bit and unicode coerces to unicode.
unicodedata module.
codecs module to look up and register new encodings.
List Comprehensions:
This:
sublist = filter( lambda s, substring=S:
string.find(s, substring) != -1, L)
becomes:
sublist = [ s for s in L if string.find(s, S) != -1 ]
List comprehensions have the form:
[ expression for expr in sequence1
for expr2 in sequence2 ...
for exprN in sequenceN
if condition
]
Effectively:
for expr1 in sequence1:
for expr2 in sequence2:
...
for exprN in sequenceN:
if (condition):
# Append the value of
# the expression to the
# resulting list.
Example:
seq1 = 'abc'
seq2 = (1,2,3)
>>> [ (x,y) for x in seq1 for y in seq2]
[('a', 1), ('a', 2), ('a', 3), ('b', 1), ('b', 2), ('b', 3), ('c', 1),
('c', 2), ('c', 3)]
Augmented assignment:
+=, -=, *=, /=, %=, **=, &=, |=, ^=, >>=, and <<=
Override with __iadd__, __isub__, etc.
Strings have grown methods.
Example:
>>> 'andrew'.capitalize()
'Andrew'
>>> 'hostname'.replace('os', 'linux')
'hlinuxtname'
>>> 'moshe'.find('sh')
2
New methods: startswith() and endswith()
Cycle-detection in the GC:
Periodicly the GC will run a cycle-detection pass to look for any
inaccessable cycles and deletes them.
The "gc" module provides methods for tuning the GC, forcing a GC, and
getting stats.
Can be disabled with "--without-cycle-gc" at compile time.
f(*args, **kw) is shorthand for apply(f, args, kw)
print >> sys.stderr, "Warning: action field not supplied"
import string as st
"'%r' % s" is equivalent to "repr(s)"
__contains__() method to override "in".
Recursive deletion of objects no longer used.
Recursive definitions no longer crash.
Comparisons can now raise exceptions. They used to be swallowed.
New platforms: 64-bit windows, OS X, WinCE.
NameError for unknown symbols is now UnboundLocalError
SyntaxError now has two new children: TabError and IndentationError
New method: zip(seq1, seq2, ...)
Unlike map(None, seq1, seq2), zip() truncates to the length of the shortest.
int() and long() now accept a base argument.
dict.setdefault(key, default) method
similar to dict.get(key, default); dict[key] = default
Recursion depth can be changed at run-time using sys.setrecursionlimit
sys.getrecursionlimit retrieves it
Backwards incomatibility:
l.append(1,2) and l.insert(1,2) must now be l.append(( 1,2 ))
socket.connect still allows (1,2) because of bugs in the docs.
This will change.
'\xFF' now consumes exactly two digits.
Long ints more interchangable: can be used in slices, seek(), '%d'.
str(1L) no longer has trailing L.
repr() of a float now uses '%.17g' while str() continues to use '%.12g'
-X option for string exceptions has been removed.
Many extending/embedding changes.
Distutils:
"python setup.py install"
Will detect paths, compilers, flags to use, build any modules, and install
them in the right place.
XML:
xmllib module
SAX2 -- provides an event-driven interface with some similarities to xmllib
DOM -- provides a tree-based interface, transforming an XML document into
a tree of nodes that can be traversed and modified. Minimal impl.
PyXML support can be gotten by simply installing PyXML. Simple programs
can get by with existing "xml" module, more complicated programs will
need PyXML.
PyXML includes:
4DOM, a full DOM implementation from FourThought, Inc.
The xmlproc validating parser, written by Lars Marius Garshol.
The sgmlop parser accelerator module, written by Fredrik Lundh.
Module changes:
SSL Support in the socket module.
httplib and urllib now support https://
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(( '216.17.150.34', 443 ))
>>> s2 = socket.ssl(s2, None, None)
>>> print s2.issuer()
/C=ZA/ST=Western Cape/L=Cape Town/O=Thawte Consulting cc/OU=Certification Services Division/CN=Thawte Server CA/Email=server-certs@thawte.com
>>> print s2.server()
/C=US/ST=Colorado/L=Fort Collins/O=tummy.com, ltd./CN=www.tummy.com
Tkinter now supports Tk8.3
curses module greatly extended.
re module re-written, includes support for unicode.
atexit.register() should be used instead of sys.exitfunc
filecmp module deprecates cmp, cmpcache, dircache
gettext internationalization
linuxaudiodev
mmap
pyexpat -- interface to expat XML parser.
robotparser
tabnanny
UserString
webbrowser -- platform-independant web browser launching.
_winreg -- Windows registry.
zipfile
imputil -- Customized import hooks.
Many IDLE changes
Deprecated modules:
gone: stdwin
Moved: cmp, cmpcache, dircmp, dump, find, grep, packmail, poly, util,
whatsound, zmod
Contact |
Privacy Policy Copyright © 1995-2003 tummy.com, ltd, All Rights Reserved 5400 Fossil Court North, Fort Collins, Colorado, USA, 80525 Last modified on 2004-06-07 Python programming makes us more efficient. |