WHAT IS PYTHON STANDARD LIBRARY AND HOW TO USE IN PYTHON PROGRAMMING

PYTHON STANDARD LIBRARY

Typically, you write Python programs by combining functions and classes (that is, custom types) that you create with preexisting functions and classes defined in modules, such as those in the Python Standard Library and other libraries. A key programming goal is to avoid “reinventing the wheel.”
A module is a file that groups related functions, data and classes. The type Decimal from the Python Standard Library’s decimal module is actually a class. We introduced classes briefly in Chapter 1 and discuss them in detail in the “Object-­Oriented Programming” chapter. A package groups related modules. In this book, you’ll work with many preexisting modules and packages, and you’ll create your own modules—in fact, every Python source­code (.py) file you create is a module. Creating packages is beyond this book’s scope. They’re typically used to organize a large library’s functionality into smaller subsets that are easier to maintain and can be imported separately for convenience. For example, the matplotlib visualization library that we use in Section 5.17 has extensive functionality (its documentation is over 2300 pages), so we’ll import only the subsets we need in our examples (pyplot and animation).

The Python Standard Library is provided with the core Python language. Its packages and modules contain capabilities for a wide variety of everyday programming tasks.
You can see a complete list of the standard library modules at

https://docs.python.org/3/library/

You’ve already used capabilities from the decimal, statistics and random modules. In the next section, you’ll use mathematics capabilities from the math module. You’ll see many other Python Standard Library modules through-out the article’s examples, including many of those in the following table:

Some popular Python Standard Library modules
collections—Data structures
  1. beyond lists, tuples, dictionaries and sets.
  2. Cryptography modules—Encrypting data for secure transmission.
  3. csv—Processing comma­separated value files (like those in Excel).
  4. datetime—Date and time manipulations. Also modules time and calendar.
  5. decimal—Fixed­point and floating-point arithmetic, including monetary calculations.
  6. doctest—Embed validation tests and expected results in docstrings for simple unit testing.
  7. math—Common math constants and operations.
  8. os—Interacting with the operating system.
  9. profile, pstats, timeit—Performance analysis.
  10. random—Pseudorandom numbers.
  11. re—Regular expressions for pattern matching.
  12. sqlite3—SQLite relational database access.
  13. statistics—Mathematical statistics functions such as mean, median, mode and variance.
  14. string—String processing.
  15. sys—Command­line argument
  16. gettext and locale—Internationalization and localization modules.
  17. json—JavaScript Object Notation (JSON) processing used with web services and NoSQL document databases.
  18. processing; standard input, standard output and standard error streams.
  19. tkinter—Graphical user interfaces (GUIs) and canvas­based graphics.
  20. turtle—Turtle graphics.
  21. webbrowser—For conveniently displaying web pages in Python apps.

*

إرسال تعليق (0)
أحدث أقدم