See All Titles |
![]() ![]() EnhancementsPython 2.0 comes bundled with many new features, bug fixes, and optimizations. The next list provides an appetizer for the main changes that were made, and that are about to be shown.
The following are considered to be the most important changes in this new release. Unicode SupportThis is a long awaited feature that was finally added to the language. Unicode strings are a new sort of data type, which can handle up to 65,536 distinct characters, instead of being limited to the 256 used by the ASCII format. Python now comes with a library of codecs for converting between Unicode and the various character encodings in use. This library can be extended very easily. List ComprehensionWhenever you need to compute a list (or lists) of elements in order to generate a new list, you can use this new and more efficient mechanism. It is offered for lists in order to replace the not-that-efficient method of using a for loop with an if statement and a list.append() call, for example, newlist = [y+3 for y in range(15)] Strings ManipulationPrior to version 2.0, you had to rely on the string module to manipulate your string objects. With this new release, the methods were pushed to the string type. Besides the methods that were inherited from the string module, two new methods were also added. Note that old string module was not removed from the distribution because it is still necessary for backward compatibility. Augmented AssignmentPython 2.0 implements a full set of augmented assignment operators. This includes: +=, -=, *=, /=, %=, **=, &=, |=, ^=, »=, and «= For example, instead of saying x = x+1, you can choose to say x += 1 Note that you can also specify methods for classes (such as __iadd__) in order to handle these new operators. Garbage CollectionThe Python interpreter is now using a new mechanism to collect unused objects. From time to time, this mechanism performs a cycle detection algorithm that searches for inaccessible cycles and deletes the participating objects. This process has been named Garbage Collection of Cycles. There are a couple of parameters of the garbage collection that you can manipulate. The module gc provides functions that help you out with that. Of course, you always have the option to disable this feature. To do so, simply specify the argument "--without-cycle-gc" when running the Python configure script. Maximum RecursionPrior to version 2.0, Python's maximum recursion depth used to be decided when you compiled Python. Now, the maximum number of recursive calls that can be made by Python code is easily interpreted and modified by Python programs just by using the functions sys.getrecursionlimit and sys.setrecursionlimit, respectively. Note that the default number of recursive calls is set to 1000, and you can use the script Misc/find_recursionlimit.py that comes as part of the 2.0 distribution to help you figure out what is the best number to use on your system. After running this program, you can add a setrecursionlimit() call to the end of site.py so that this limit is used by all Python programs on the system. Taking good care of this limit can help you trap infinite recursions of filling the C stack and causing a core dump or GPF on your system.
|
Index terms contained in this sectionassignment operatorsPython 2.0 Garbage Collection of Cycles (Python 2.0) IDLE Python 2.0 lists Python 2.0 methods Python 2.0 modules re Python 2.0 objects unused objects Python 2.0 operators assignment operators Python 2.0 Python 2.0 new features 2nd 3rd 4th re module Python 2.0 recursion Python 2.0 source code Python 2.0 strings Python 2.0 Unicode support Python 2.0 XML support in Python 2.0 |
© 2002, O'Reilly & Associates, Inc. |