forked from AFPy/python-docs-fr
852 lines
28 KiB
Plaintext
852 lines
28 KiB
Plaintext
# SOME DESCRIPTIVE TITLE.
|
|
# Copyright (C) 2001-2016, Python Software Foundation
|
|
# This file is distributed under the same license as the Python package.
|
|
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
|
#
|
|
#, fuzzy
|
|
msgid ""
|
|
msgstr ""
|
|
"Project-Id-Version: Python 3.6\n"
|
|
"Report-Msgid-Bugs-To: \n"
|
|
"POT-Creation-Date: 2017-04-02 22:11+0200\n"
|
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
|
"Language: fr\n"
|
|
"MIME-Version: 1.0\n"
|
|
"Content-Type: text/plain; charset=UTF-8\n"
|
|
"Content-Transfer-Encoding: 8bit\n"
|
|
|
|
#: ../Doc/faq/library.rst:5
|
|
msgid "Library and Extension FAQ"
|
|
msgstr "Bibliothèque et Extension FAQ"
|
|
|
|
#: ../Doc/faq/library.rst:12
|
|
msgid "General Library Questions"
|
|
msgstr "Questions générales sur la bibliothèque"
|
|
|
|
#: ../Doc/faq/library.rst:15
|
|
msgid "How do I find a module or application to perform task X?"
|
|
msgstr ""
|
|
"Comment puis-je trouver un module ou une application pour exécuter la tâche "
|
|
"X?"
|
|
|
|
#: ../Doc/faq/library.rst:17
|
|
msgid ""
|
|
"Check :ref:`the Library Reference <library-index>` to see if there's a "
|
|
"relevant standard library module. (Eventually you'll learn what's in the "
|
|
"standard library and will be able to skip this step.)"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:21
|
|
msgid ""
|
|
"For third-party packages, search the `Python Package Index <https://pypi."
|
|
"python.org/pypi>`_ or try `Google <https://www.google.com>`_ or another Web "
|
|
"search engine. Searching for \"Python\" plus a keyword or two for your "
|
|
"topic of interest will usually find something helpful."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:28
|
|
msgid "Where is the math.py (socket.py, regex.py, etc.) source file?"
|
|
msgstr "Où se situe le fichier source math.py (socket.py, regex.py, etc.)?"
|
|
|
|
#: ../Doc/faq/library.rst:30
|
|
msgid ""
|
|
"If you can't find a source file for a module it may be a built-in or "
|
|
"dynamically loaded module implemented in C, C++ or other compiled language. "
|
|
"In this case you may not have the source file or it may be something like :"
|
|
"file:`mathmodule.c`, somewhere in a C source directory (not on the Python "
|
|
"Path)."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:35
|
|
msgid "There are (at least) three kinds of modules in Python:"
|
|
msgstr "Il y a (au moins) trois types de modules dans Python"
|
|
|
|
#: ../Doc/faq/library.rst:37
|
|
msgid "modules written in Python (.py);"
|
|
msgstr "modules écrits en Python (.py);"
|
|
|
|
#: ../Doc/faq/library.rst:38
|
|
msgid ""
|
|
"modules written in C and dynamically loaded (.dll, .pyd, .so, .sl, etc);"
|
|
msgstr ""
|
|
"modules écrits en C et chargés dynamiquement (.dll, .pyd, .so, .sl, .etc);"
|
|
|
|
#: ../Doc/faq/library.rst:39
|
|
msgid ""
|
|
"modules written in C and linked with the interpreter; to get a list of "
|
|
"these, type::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:47
|
|
msgid "How do I make a Python script executable on Unix?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:49
|
|
msgid ""
|
|
"You need to do two things: the script file's mode must be executable and the "
|
|
"first line must begin with ``#!`` followed by the path of the Python "
|
|
"interpreter."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:53
|
|
msgid ""
|
|
"The first is done by executing ``chmod +x scriptfile`` or perhaps ``chmod "
|
|
"755 scriptfile``."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:56
|
|
msgid ""
|
|
"The second can be done in a number of ways. The most straightforward way is "
|
|
"to write ::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:61
|
|
msgid ""
|
|
"as the very first line of your file, using the pathname for where the Python "
|
|
"interpreter is installed on your platform."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:64
|
|
msgid ""
|
|
"If you would like the script to be independent of where the Python "
|
|
"interpreter lives, you can use the :program:`env` program. Almost all Unix "
|
|
"variants support the following, assuming the Python interpreter is in a "
|
|
"directory on the user's :envvar:`PATH`::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:71
|
|
msgid ""
|
|
"*Don't* do this for CGI scripts. The :envvar:`PATH` variable for CGI "
|
|
"scripts is often very minimal, so you need to use the actual absolute "
|
|
"pathname of the interpreter."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:75
|
|
msgid ""
|
|
"Occasionally, a user's environment is so full that the :program:`/usr/bin/"
|
|
"env` program fails; or there's no env program at all. In that case, you can "
|
|
"try the following hack (due to Alex Rezinsky)::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:84
|
|
msgid ""
|
|
"The minor disadvantage is that this defines the script's __doc__ string. "
|
|
"However, you can fix that by adding ::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:92
|
|
msgid "Is there a curses/termcap package for Python?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:96
|
|
msgid ""
|
|
"For Unix variants: The standard Python source distribution comes with a "
|
|
"curses module in the :source:`Modules` subdirectory, though it's not "
|
|
"compiled by default. (Note that this is not available in the Windows "
|
|
"distribution -- there is no curses module for Windows.)"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:101
|
|
msgid ""
|
|
"The :mod:`curses` module supports basic curses features as well as many "
|
|
"additional functions from ncurses and SYSV curses such as colour, "
|
|
"alternative character set support, pads, and mouse support. This means the "
|
|
"module isn't compatible with operating systems that only have BSD curses, "
|
|
"but there don't seem to be any currently maintained OSes that fall into this "
|
|
"category."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:107
|
|
msgid ""
|
|
"For Windows: use `the consolelib module <http://effbot.org/zone/console-"
|
|
"index.htm>`_."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:112
|
|
msgid "Is there an equivalent to C's onexit() in Python?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:114
|
|
msgid ""
|
|
"The :mod:`atexit` module provides a register function that is similar to "
|
|
"C's :c:func:`onexit`."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:119
|
|
msgid "Why don't my signal handlers work?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:121
|
|
msgid ""
|
|
"The most common problem is that the signal handler is declared with the "
|
|
"wrong argument list. It is called as ::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:126
|
|
msgid "so it should be declared with two arguments::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:133
|
|
msgid "Common tasks"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:136
|
|
msgid "How do I test a Python program or component?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:138
|
|
msgid ""
|
|
"Python comes with two testing frameworks. The :mod:`doctest` module finds "
|
|
"examples in the docstrings for a module and runs them, comparing the output "
|
|
"with the expected output given in the docstring."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:142
|
|
msgid ""
|
|
"The :mod:`unittest` module is a fancier testing framework modelled on Java "
|
|
"and Smalltalk testing frameworks."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:145
|
|
msgid ""
|
|
"To make testing easier, you should use good modular design in your program. "
|
|
"Your program should have almost all functionality encapsulated in either "
|
|
"functions or class methods -- and this sometimes has the surprising and "
|
|
"delightful effect of making the program run faster (because local variable "
|
|
"accesses are faster than global accesses). Furthermore the program should "
|
|
"avoid depending on mutating global variables, since this makes testing much "
|
|
"more difficult to do."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:153
|
|
msgid "The \"global main logic\" of your program may be as simple as ::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:158
|
|
msgid "at the bottom of the main module of your program."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:160
|
|
msgid ""
|
|
"Once your program is organized as a tractable collection of functions and "
|
|
"class behaviours you should write test functions that exercise the "
|
|
"behaviours. A test suite that automates a sequence of tests can be "
|
|
"associated with each module. This sounds like a lot of work, but since "
|
|
"Python is so terse and flexible it's surprisingly easy. You can make coding "
|
|
"much more pleasant and fun by writing your test functions in parallel with "
|
|
"the \"production code\", since this makes it easy to find bugs and even "
|
|
"design flaws earlier."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:168
|
|
msgid ""
|
|
"\"Support modules\" that are not intended to be the main module of a program "
|
|
"may include a self-test of the module. ::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:174
|
|
msgid ""
|
|
"Even programs that interact with complex external interfaces may be tested "
|
|
"when the external interfaces are unavailable by using \"fake\" interfaces "
|
|
"implemented in Python."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:180
|
|
msgid "How do I create documentation from doc strings?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:182
|
|
msgid ""
|
|
"The :mod:`pydoc` module can create HTML from the doc strings in your Python "
|
|
"source code. An alternative for creating API documentation purely from "
|
|
"docstrings is `epydoc <http://epydoc.sourceforge.net/>`_. `Sphinx <http://"
|
|
"sphinx-doc.org>`_ can also include docstring content."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:189
|
|
msgid "How do I get a single keypress at a time?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:191
|
|
msgid ""
|
|
"For Unix variants there are several solutions. It's straightforward to do "
|
|
"this using curses, but curses is a fairly large module to learn."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:235
|
|
msgid "Threads"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:238
|
|
msgid "How do I program using threads?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:240
|
|
msgid ""
|
|
"Be sure to use the :mod:`threading` module and not the :mod:`_thread` "
|
|
"module. The :mod:`threading` module builds convenient abstractions on top of "
|
|
"the low-level primitives provided by the :mod:`_thread` module."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:244
|
|
msgid ""
|
|
"Aahz has a set of slides from his threading tutorial that are helpful; see "
|
|
"http://www.pythoncraft.com/OSCON2001/."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:249
|
|
msgid "None of my threads seem to run: why?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:251
|
|
msgid ""
|
|
"As soon as the main thread exits, all threads are killed. Your main thread "
|
|
"is running too quickly, giving the threads no time to do any work."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:254
|
|
msgid ""
|
|
"A simple fix is to add a sleep to the end of the program that's long enough "
|
|
"for all the threads to finish::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:269
|
|
msgid ""
|
|
"But now (on many platforms) the threads don't run in parallel, but appear to "
|
|
"run sequentially, one at a time! The reason is that the OS thread scheduler "
|
|
"doesn't start a new thread until the previous thread is blocked."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:273
|
|
msgid "A simple fix is to add a tiny sleep to the start of the run function::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:286
|
|
msgid ""
|
|
"Instead of trying to guess a good delay value for :func:`time.sleep`, it's "
|
|
"better to use some kind of semaphore mechanism. One idea is to use the :mod:"
|
|
"`queue` module to create a queue object, let each thread append a token to "
|
|
"the queue when it finishes, and let the main thread read as many tokens from "
|
|
"the queue as there are threads."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:294
|
|
msgid "How do I parcel out work among a bunch of worker threads?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:296
|
|
msgid ""
|
|
"The easiest way is to use the new :mod:`concurrent.futures` module, "
|
|
"especially the :mod:`~concurrent.futures.ThreadPoolExecutor` class."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:299
|
|
msgid ""
|
|
"Or, if you want fine control over the dispatching algorithm, you can write "
|
|
"your own logic manually. Use the :mod:`queue` module to create a queue "
|
|
"containing a list of jobs. The :class:`~queue.Queue` class maintains a list "
|
|
"of objects and has a ``.put(obj)`` method that adds items to the queue and a "
|
|
"``.get()`` method to return them. The class will take care of the locking "
|
|
"necessary to ensure that each job is handed out exactly once."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:306
|
|
msgid "Here's a trivial example::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:344
|
|
msgid "When run, this will produce the following output:"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:362
|
|
msgid ""
|
|
"Consult the module's documentation for more details; the :class:`~queue."
|
|
"Queue` class provides a featureful interface."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:367
|
|
msgid "What kinds of global value mutation are thread-safe?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:369
|
|
msgid ""
|
|
"A :term:`global interpreter lock` (GIL) is used internally to ensure that "
|
|
"only one thread runs in the Python VM at a time. In general, Python offers "
|
|
"to switch among threads only between bytecode instructions; how frequently "
|
|
"it switches can be set via :func:`sys.setswitchinterval`. Each bytecode "
|
|
"instruction and therefore all the C implementation code reached from each "
|
|
"instruction is therefore atomic from the point of view of a Python program."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:376
|
|
msgid ""
|
|
"In theory, this means an exact accounting requires an exact understanding of "
|
|
"the PVM bytecode implementation. In practice, it means that operations on "
|
|
"shared variables of built-in data types (ints, lists, dicts, etc) that "
|
|
"\"look atomic\" really are."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:381
|
|
msgid ""
|
|
"For example, the following operations are all atomic (L, L1, L2 are lists, "
|
|
"D, D1, D2 are dicts, x, y are objects, i, j are ints)::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:396
|
|
msgid "These aren't::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:403
|
|
msgid ""
|
|
"Operations that replace other objects may invoke those other objects' :meth:"
|
|
"`__del__` method when their reference count reaches zero, and that can "
|
|
"affect things. This is especially true for the mass updates to dictionaries "
|
|
"and lists. When in doubt, use a mutex!"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:410
|
|
msgid "Can't we get rid of the Global Interpreter Lock?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:414
|
|
msgid ""
|
|
"The :term:`global interpreter lock` (GIL) is often seen as a hindrance to "
|
|
"Python's deployment on high-end multiprocessor server machines, because a "
|
|
"multi-threaded Python program effectively only uses one CPU, due to the "
|
|
"insistence that (almost) all Python code can only run while the GIL is held."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:419
|
|
msgid ""
|
|
"Back in the days of Python 1.5, Greg Stein actually implemented a "
|
|
"comprehensive patch set (the \"free threading\" patches) that removed the "
|
|
"GIL and replaced it with fine-grained locking. Adam Olsen recently did a "
|
|
"similar experiment in his `python-safethread <http://code.google.com/p/"
|
|
"python-safethread/>`_ project. Unfortunately, both experiments exhibited a "
|
|
"sharp drop in single-thread performance (at least 30% slower), due to the "
|
|
"amount of fine-grained locking necessary to compensate for the removal of "
|
|
"the GIL."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:427
|
|
msgid ""
|
|
"This doesn't mean that you can't make good use of Python on multi-CPU "
|
|
"machines! You just have to be creative with dividing the work up between "
|
|
"multiple *processes* rather than multiple *threads*. The :class:"
|
|
"`~concurrent.futures.ProcessPoolExecutor` class in the new :mod:`concurrent."
|
|
"futures` module provides an easy way of doing so; the :mod:`multiprocessing` "
|
|
"module provides a lower-level API in case you want more control over "
|
|
"dispatching of tasks."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:435
|
|
msgid ""
|
|
"Judicious use of C extensions will also help; if you use a C extension to "
|
|
"perform a time-consuming task, the extension can release the GIL while the "
|
|
"thread of execution is in the C code and allow other threads to get some "
|
|
"work done. Some standard library modules such as :mod:`zlib` and :mod:"
|
|
"`hashlib` already do this."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:441
|
|
msgid ""
|
|
"It has been suggested that the GIL should be a per-interpreter-state lock "
|
|
"rather than truly global; interpreters then wouldn't be able to share "
|
|
"objects. Unfortunately, this isn't likely to happen either. It would be a "
|
|
"tremendous amount of work, because many object implementations currently "
|
|
"have global state. For example, small integers and short strings are cached; "
|
|
"these caches would have to be moved to the interpreter state. Other object "
|
|
"types have their own free list; these free lists would have to be moved to "
|
|
"the interpreter state. And so on."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:450
|
|
msgid ""
|
|
"And I doubt that it can even be done in finite time, because the same "
|
|
"problem exists for 3rd party extensions. It is likely that 3rd party "
|
|
"extensions are being written at a faster rate than you can convert them to "
|
|
"store all their global state in the interpreter state."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:455
|
|
msgid ""
|
|
"And finally, once you have multiple interpreters not sharing any state, what "
|
|
"have you gained over running each interpreter in a separate process?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:460
|
|
msgid "Input and Output"
|
|
msgstr "Les entrées/sorties"
|
|
|
|
#: ../Doc/faq/library.rst:463
|
|
msgid "How do I delete a file? (And other file questions...)"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:465
|
|
msgid ""
|
|
"Use ``os.remove(filename)`` or ``os.unlink(filename)``; for documentation, "
|
|
"see the :mod:`os` module. The two functions are identical; :func:`~os."
|
|
"unlink` is simply the name of the Unix system call for this function."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:469
|
|
msgid ""
|
|
"To remove a directory, use :func:`os.rmdir`; use :func:`os.mkdir` to create "
|
|
"one. ``os.makedirs(path)`` will create any intermediate directories in "
|
|
"``path`` that don't exist. ``os.removedirs(path)`` will remove intermediate "
|
|
"directories as long as they're empty; if you want to delete an entire "
|
|
"directory tree and its contents, use :func:`shutil.rmtree`."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:475
|
|
msgid "To rename a file, use ``os.rename(old_path, new_path)``."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:477
|
|
msgid ""
|
|
"To truncate a file, open it using ``f = open(filename, \"rb+\")``, and use "
|
|
"``f.truncate(offset)``; offset defaults to the current seek position. "
|
|
"There's also ``os.ftruncate(fd, offset)`` for files opened with :func:`os."
|
|
"open`, where *fd* is the file descriptor (a small integer)."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:482
|
|
msgid ""
|
|
"The :mod:`shutil` module also contains a number of functions to work on "
|
|
"files including :func:`~shutil.copyfile`, :func:`~shutil.copytree`, and :"
|
|
"func:`~shutil.rmtree`."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:488
|
|
msgid "How do I copy a file?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:490
|
|
msgid ""
|
|
"The :mod:`shutil` module contains a :func:`~shutil.copyfile` function. Note "
|
|
"that on MacOS 9 it doesn't copy the resource fork and Finder info."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:495
|
|
msgid "How do I read (or write) binary data?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:497
|
|
msgid ""
|
|
"To read or write complex binary data formats, it's best to use the :mod:"
|
|
"`struct` module. It allows you to take a string containing binary data "
|
|
"(usually numbers) and convert it to Python objects; and vice versa."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:501
|
|
msgid ""
|
|
"For example, the following code reads two 2-byte integers and one 4-byte "
|
|
"integer in big-endian format from a file::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:510
|
|
msgid ""
|
|
"The '>' in the format string forces big-endian data; the letter 'h' reads "
|
|
"one \"short integer\" (2 bytes), and 'l' reads one \"long integer\" (4 "
|
|
"bytes) from the string."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:514
|
|
msgid ""
|
|
"For data that is more regular (e.g. a homogeneous list of ints or floats), "
|
|
"you can also use the :mod:`array` module."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:519
|
|
msgid ""
|
|
"To read and write binary data, it is mandatory to open the file in binary "
|
|
"mode (here, passing ``\"rb\"`` to :func:`open`). If you use ``\"r\"`` "
|
|
"instead (the default), the file will be open in text mode and ``f.read()`` "
|
|
"will return :class:`str` objects rather than :class:`bytes` objects."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:527
|
|
msgid "I can't seem to use os.read() on a pipe created with os.popen(); why?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:529
|
|
msgid ""
|
|
":func:`os.read` is a low-level function which takes a file descriptor, a "
|
|
"small integer representing the opened file. :func:`os.popen` creates a high-"
|
|
"level file object, the same type returned by the built-in :func:`open` "
|
|
"function. Thus, to read *n* bytes from a pipe *p* created with :func:`os."
|
|
"popen`, you need to use ``p.read(n)``."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:616
|
|
msgid "How do I access the serial (RS232) port?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:618
|
|
msgid "For Win32, POSIX (Linux, BSD, etc.), Jython:"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:620
|
|
msgid "http://pyserial.sourceforge.net"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:622
|
|
msgid "For Unix, see a Usenet post by Mitch Chapman:"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:624
|
|
msgid "https://groups.google.com/groups?selm=34A04430.CF9@ohioee.com"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:628
|
|
msgid "Why doesn't closing sys.stdout (stdin, stderr) really close it?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:630
|
|
msgid ""
|
|
"Python :term:`file objects <file object>` are a high-level layer of "
|
|
"abstraction on low-level C file descriptors."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:633
|
|
msgid ""
|
|
"For most file objects you create in Python via the built-in :func:`open` "
|
|
"function, ``f.close()`` marks the Python file object as being closed from "
|
|
"Python's point of view, and also arranges to close the underlying C file "
|
|
"descriptor. This also happens automatically in ``f``'s destructor, when "
|
|
"``f`` becomes garbage."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:639
|
|
msgid ""
|
|
"But stdin, stdout and stderr are treated specially by Python, because of the "
|
|
"special status also given to them by C. Running ``sys.stdout.close()`` "
|
|
"marks the Python-level file object as being closed, but does *not* close the "
|
|
"associated C file descriptor."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:644
|
|
msgid ""
|
|
"To close the underlying C file descriptor for one of these three, you should "
|
|
"first be sure that's what you really want to do (e.g., you may confuse "
|
|
"extension modules trying to do I/O). If it is, use :func:`os.close`::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:652
|
|
msgid "Or you can use the numeric constants 0, 1 and 2, respectively."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:656
|
|
msgid "Network/Internet Programming"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:659
|
|
msgid "What WWW tools are there for Python?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:661
|
|
msgid ""
|
|
"See the chapters titled :ref:`internet` and :ref:`netdata` in the Library "
|
|
"Reference Manual. Python has many modules that will help you build server-"
|
|
"side and client-side web systems."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:667
|
|
msgid ""
|
|
"A summary of available frameworks is maintained by Paul Boddie at https://"
|
|
"wiki.python.org/moin/WebProgramming\\ ."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:670
|
|
msgid ""
|
|
"Cameron Laird maintains a useful set of pages about Python web technologies "
|
|
"at http://phaseit.net/claird/comp.lang.python/web_python."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:675
|
|
msgid "How can I mimic CGI form submission (METHOD=POST)?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:677
|
|
msgid ""
|
|
"I would like to retrieve web pages that are the result of POSTing a form. Is "
|
|
"there existing code that would let me do this easily?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:680
|
|
msgid "Yes. Here's a simple example that uses urllib.request::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:695
|
|
msgid ""
|
|
"Note that in general for percent-encoded POST operations, query strings must "
|
|
"be quoted using :func:`urllib.parse.urlencode`. For example, to send "
|
|
"``name=Guy Steele, Jr.``::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:703
|
|
msgid ":ref:`urllib-howto` for extensive examples."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:707
|
|
msgid "What module should I use to help with generating HTML?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:711
|
|
msgid ""
|
|
"You can find a collection of useful links on the `Web Programming wiki page "
|
|
"<https://wiki.python.org/moin/WebProgramming>`_."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:716
|
|
msgid "How do I send mail from a Python script?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:718
|
|
msgid "Use the standard library module :mod:`smtplib`."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:720
|
|
msgid ""
|
|
"Here's a very simple interactive mail sender that uses it. This method will "
|
|
"work on any host that supports an SMTP listener. ::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:740
|
|
msgid ""
|
|
"A Unix-only alternative uses sendmail. The location of the sendmail program "
|
|
"varies between systems; sometimes it is ``/usr/lib/sendmail``, sometimes ``/"
|
|
"usr/sbin/sendmail``. The sendmail manual page will help you out. Here's "
|
|
"some sample code::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:760
|
|
msgid "How do I avoid blocking in the connect() method of a socket?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:762
|
|
msgid ""
|
|
"The :mod:`select` module is commonly used to help with asynchronous I/O on "
|
|
"sockets."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:765
|
|
msgid ""
|
|
"To prevent the TCP connect from blocking, you can set the socket to non-"
|
|
"blocking mode. Then when you do the ``connect()``, you will either connect "
|
|
"immediately (unlikely) or get an exception that contains the error number as "
|
|
"``.errno``. ``errno.EINPROGRESS`` indicates that the connection is in "
|
|
"progress, but hasn't finished yet. Different OSes will return different "
|
|
"values, so you're going to have to check what's returned on your system."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:772
|
|
msgid ""
|
|
"You can use the ``connect_ex()`` method to avoid creating an exception. It "
|
|
"will just return the errno value. To poll, you can call ``connect_ex()`` "
|
|
"again later -- ``0`` or ``errno.EISCONN`` indicate that you're connected -- "
|
|
"or you can pass this socket to select to check if it's writable."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:778
|
|
msgid ""
|
|
"The :mod:`asyncore` module presents a framework-like approach to the problem "
|
|
"of writing non-blocking networking code. The third-party `Twisted <https://"
|
|
"twistedmatrix.com/trac/>`_ library is a popular and feature-rich alternative."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:785
|
|
msgid "Databases"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:788
|
|
msgid "Are there any interfaces to database packages in Python?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:790
|
|
msgid "Yes."
|
|
msgstr "Oui."
|
|
|
|
#: ../Doc/faq/library.rst:792
|
|
msgid ""
|
|
"Interfaces to disk-based hashes such as :mod:`DBM <dbm.ndbm>` and :mod:`GDBM "
|
|
"<dbm.gnu>` are also included with standard Python. There is also the :mod:"
|
|
"`sqlite3` module, which provides a lightweight disk-based relational "
|
|
"database."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:797
|
|
msgid ""
|
|
"Support for most relational databases is available. See the "
|
|
"`DatabaseProgramming wiki page <https://wiki.python.org/moin/"
|
|
"DatabaseProgramming>`_ for details."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:803
|
|
msgid "How do you implement persistent objects in Python?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:805
|
|
msgid ""
|
|
"The :mod:`pickle` library module solves this in a very general way (though "
|
|
"you still can't store things like open files, sockets or windows), and the :"
|
|
"mod:`shelve` library module uses pickle and (g)dbm to create persistent "
|
|
"mappings containing arbitrary Python objects."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:812
|
|
msgid "Mathematics and Numerics"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:815
|
|
msgid "How do I generate random numbers in Python?"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:817
|
|
msgid ""
|
|
"The standard module :mod:`random` implements a random number generator. "
|
|
"Usage is simple::"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:823
|
|
msgid "This returns a random floating point number in the range [0, 1)."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:825
|
|
msgid ""
|
|
"There are also many other specialized generators in this module, such as:"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:827
|
|
msgid "``randrange(a, b)`` chooses an integer in the range [a, b)."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:828
|
|
msgid "``uniform(a, b)`` chooses a floating point number in the range [a, b)."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:829
|
|
msgid ""
|
|
"``normalvariate(mean, sdev)`` samples the normal (Gaussian) distribution."
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:831
|
|
msgid "Some higher-level functions operate on sequences directly, such as:"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:833
|
|
msgid "``choice(S)`` chooses random element from a given sequence"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:834
|
|
msgid "``shuffle(L)`` shuffles a list in-place, i.e. permutes it randomly"
|
|
msgstr ""
|
|
|
|
#: ../Doc/faq/library.rst:836
|
|
msgid ""
|
|
"There's also a ``Random`` class you can instantiate to create independent "
|
|
"multiple random number generators."
|
|
msgstr ""
|