预计阅读本页时间:-
The Python Toolset
From this point forward, your future Python career will largely consist of becoming proficient with the toolset available for application-level Python programming. You’ll find this to be an ongoing task. The standard library, for example, contains hundreds of modules, and the public domain offers still more tools. It’s possible to spend a decade or more seeking proficiency with all these tools, especially as new ones are constantly appearing (trust me on this!).
Speaking generally, Python provides a hierarchy of toolsets:
广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元
Built-ins
Built-in types like strings, lists, and dictionaries make it easy to write simple programs fast.
Python extensions
For more demanding tasks, you can extend Python by writing your own functions, modules, and classes.
Compiled extensions
Although we don’t cover this topic in this book, Python can also be extended with modules written in an external language like C or C++.
Because Python layers its toolsets, you can decide how deeply your programs need to delve into this hierarchy for any given task—you can use built-ins for simple scripts, add Python-coded extensions for larger systems, and code compiled extensions for advanced work. We’ve only covered the first two of these categories in this book, and that’s plenty to get you started doing substantial programming in Python.
Table 35-1 summarizes some of the sources of built-in or existing functionality available to Python programmers, and some topics you’ll probably be busy exploring for the remainder of your Python career. Up until now, most of our examples have been very small and self-contained. They were written that way on purpose, to help you master the basics. But now that you know all about the core language, it’s time to start learning how to use Python’s built-in interfaces to do real work. You’ll find that with a simple language like Python, common tasks are often much easier than you might expect.
Table 35-1. Python’s toolbox categories
Category
Examples
Object types
Lists, dictionaries, files, strings
Functions
len, range, open
Exceptions
IndexError, KeyError
Modules
os, tkinter, pickle, re
Attributes
__dict__, __name__, __class__
Peripheral tools
NumPy, SWIG, Jython, IronPython, Django, etc.