diff --git a/Doc/distutils/examples.rst b/Doc/distutils/examples.rst index af9125a..65b2c35 100644 --- a/Doc/distutils/examples.rst +++ b/Doc/distutils/examples.rst @@ -245,7 +245,9 @@ Let's take an example with a simple script:: setup(name='foobar') -Running the ``check`` command will display some warnings:: +Running the ``check`` command will display some warnings: + +.. code-block:: bash $ python setup.py check running check @@ -274,7 +276,9 @@ For example, if the :file:`setup.py` script is changed like this:: url='http://example.com', long_description=desc) Where the long description is broken, ``check`` will be able to detect it -by using the :mod:`docutils` parser:: +by using the :mod:`docutils` parser: + +.. code-block:: bash $ python setup.py check --restructuredtext running check @@ -286,7 +290,9 @@ Reading the metadata The :func:`distutils.core.setup` function provides a command-line interface that allows you to query the metadata fields of a project through the -``setup.py`` script of a given project:: +``setup.py`` script of a given project: + +.. code-block:: bash $ python setup.py --name distribute diff --git a/Doc/distutils/packageindex.rst b/Doc/distutils/packageindex.rst index 2d7daef..1fa5457 100644 --- a/Doc/distutils/packageindex.rst +++ b/Doc/distutils/packageindex.rst @@ -233,7 +233,9 @@ in the root of the package besides :file:`setup.py`. To prevent registering broken reStructuredText content, you can use the :program:`rst2html` program that is provided by the :mod:`docutils` package and -check the ``long_description`` from the command line:: +check the ``long_description`` from the command line: + +.. code-block:: bash $ python setup.py --long-description | rst2html.py > output.html diff --git a/Doc/distutils/sourcedist.rst b/Doc/distutils/sourcedist.rst index fb70514..35aea1e 100644 --- a/Doc/distutils/sourcedist.rst +++ b/Doc/distutils/sourcedist.rst @@ -133,7 +133,9 @@ described above does not apply in this case. The manifest template has one command per line, where each command specifies a set of files to include or exclude from the source distribution. For an -example, again we turn to the Distutils' own manifest template:: +example, again we turn to the Distutils' own manifest template: + +.. code-block:: none include *.txt recursive-include examples *.txt *.py diff --git a/Doc/extending/building.rst b/Doc/extending/building.rst index 4a30181..7b3a976 100644 --- a/Doc/extending/building.rst +++ b/Doc/extending/building.rst @@ -55,7 +55,9 @@ Since distutils also supports creation of binary packages, users don't necessarily need a compiler and distutils to install the extension. A distutils package contains a driver script, :file:`setup.py`. This is a plain -Python file, which, in the most simple case, could look like this:: +Python file, which, in the most simple case, could look like this: + +.. code-block:: python3 from distutils.core import setup, Extension @@ -95,7 +97,9 @@ file, :file:`demo.c`. In many cases, building an extension is more complex, since additional preprocessor defines and libraries may be needed. This is demonstrated in the -example below. :: +example below. + +.. code-block:: python3 from distutils.core import setup, Extension @@ -160,4 +164,3 @@ commands can be used to do so. :: python setup.py bdist_wininst python setup.py bdist_rpm python setup.py bdist_dumb - diff --git a/Doc/extending/embedding.rst b/Doc/extending/embedding.rst index acd60ae..ba51917 100644 --- a/Doc/extending/embedding.rst +++ b/Doc/extending/embedding.rst @@ -155,7 +155,9 @@ script, such as: c = c + b return c -then the result should be:: +then the result should be: + +.. code-block:: bash $ call multiply multiply 3 2 Will compute 3 times 2 @@ -289,13 +291,17 @@ available). This script has several options, of which the following will be directly useful to you: * ``pythonX.Y-config --cflags`` will give you the recommended flags when - compiling:: + compiling: + +.. code-block:: bash $ /opt/bin/python3.4-config --cflags -I/opt/include/python3.4m -I/opt/include/python3.4m -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes * ``pythonX.Y-config --ldflags`` will give you the recommended flags when - linking:: + linking: + +.. code-block:: bash $ /opt/bin/python3.4-config --ldflags -L/opt/lib/python3.4/config-3.4m -lpthread -ldl -lutil -lm -lpython3.4m -Xlinker -export-dynamic diff --git a/Doc/extending/extending.rst b/Doc/extending/extending.rst index 523dfab..8219707 100644 --- a/Doc/extending/extending.rst +++ b/Doc/extending/extending.rst @@ -792,7 +792,9 @@ the format string is empty, it returns ``None``; if it contains exactly one format unit, it returns whatever object is described by that format unit. To force it to return a tuple of size 0 or one, parenthesize the format string. -Examples (to the left the call, to the right the resulting Python value):: +Examples (to the left the call, to the right the resulting Python value): + +.. code-block:: none Py_BuildValue("") None Py_BuildValue("i", 123) 123 @@ -1348,4 +1350,3 @@ code distribution). .. [#] These guarantees don't hold when you use the "old" style calling convention --- this is still found in much existing code. - diff --git a/Doc/extending/newtypes.rst b/Doc/extending/newtypes.rst index f60e208..e0ce6cd 100644 --- a/Doc/extending/newtypes.rst +++ b/Doc/extending/newtypes.rst @@ -209,7 +209,9 @@ That's it! All that remains is to build it; put the above code in a file called setup(name="noddy", version="1.0", ext_modules=[Extension("noddy", ["noddy.c"])]) -in a file called :file:`setup.py`; then typing :: +in a file called :file:`setup.py`; then typing: + +.. code-block:: bash $ python setup.py build @@ -1513,4 +1515,3 @@ might be something like the following:: .. [#] Even in the third version, we aren't guaranteed to avoid cycles. Instances of string subclasses are allowed and string subclasses could allow cycles even if normal strings don't. - diff --git a/Doc/faq/extending.rst b/Doc/faq/extending.rst index 635f2c1..5ae91a3 100644 --- a/Doc/faq/extending.rst +++ b/Doc/faq/extending.rst @@ -146,7 +146,9 @@ this object to :data:`sys.stdout` and :data:`sys.stderr`. Call print_error, or just allow the standard traceback mechanism to work. Then, the output will go wherever your ``write()`` method sends it. -The easiest way to do this is to use the :class:`io.StringIO` class:: +The easiest way to do this is to use the :class:`io.StringIO` class: + +.. code-block:: pycon >>> import io, sys >>> sys.stdout = io.StringIO() @@ -156,7 +158,9 @@ The easiest way to do this is to use the :class:`io.StringIO` class:: foo hello world! -A custom object to do the same would look like this:: +A custom object to do the same would look like this: + +.. code-block:: pycon >>> import io, sys >>> class StdoutCatcher(io.TextIOBase): @@ -222,11 +226,15 @@ How do I debug an extension? When using GDB with dynamically loaded extensions, you can't set a breakpoint in your extension until your extension is loaded. -In your ``.gdbinit`` file (or interactively), add the command:: +In your ``.gdbinit`` file (or interactively), add the command: + +.. code-block:: none br _PyImport_LoadDynamicModule -Then, when you run GDB:: +Then, when you run GDB: + +.. code-block:: bash $ gdb /local/bin/python gdb) run myscript.py diff --git a/Doc/howto/clinic.rst b/Doc/howto/clinic.rst index b04edea..68d7e47 100644 --- a/Doc/howto/clinic.rst +++ b/Doc/howto/clinic.rst @@ -152,7 +152,9 @@ Let's dive in! For my example I'm using ``_pickle.Pickler.dump()``. 2. If the call to the ``PyArg_Parse`` function uses any of the - following format units:: + following format units: + + .. code-block:: none O& O! diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst index 582a034..a070d9a 100644 --- a/Doc/howto/logging-cookbook.rst +++ b/Doc/howto/logging-cookbook.rst @@ -376,7 +376,9 @@ An example of using these two classes follows (imports omitted):: root.warning('Look out!') listener.stop() -which, when run, will produce:: +which, when run, will produce: + +.. code-block:: none MainThread: Look out! @@ -1858,7 +1860,9 @@ script, ``chowntest.py``:: logger = logging.getLogger('mylogger') logger.debug('A debug message') -To run this, you will probably need to run as ``root``:: +To run this, you will probably need to run as ``root``: + +.. code-block:: bash $ sudo python3.3 chowntest.py $ cat chowntest.log diff --git a/Doc/howto/logging.rst b/Doc/howto/logging.rst index d66770f..e60ce99 100644 --- a/Doc/howto/logging.rst +++ b/Doc/howto/logging.rst @@ -106,7 +106,9 @@ A very simple example is:: logging.warning('Watch out!') # will print a message to the console logging.info('I told you so') # will not print anything -If you type these lines into a script and run it, you'll see:: +If you type these lines into a script and run it, you'll see: + +.. code-block:: none WARNING:root:Watch out! @@ -230,7 +232,9 @@ append the variable data as arguments. For example:: import logging logging.warning('%s before you %s', 'Look', 'leap!') -will display:: +will display: + +.. code-block:: none WARNING:root:Look before you leap! @@ -594,7 +598,9 @@ logger, a console handler, and a simple formatter using Python code:: logger.error('error message') logger.critical('critical message') -Running this module from the command line produces the following output:: +Running this module from the command line produces the following output: + +.. code-block:: bash $ python simple_logging_module.py 2005-03-19 15:10:26,618 - simple_example - DEBUG - debug message @@ -653,7 +659,9 @@ Here is the logging.conf file:: format=%(asctime)s - %(name)s - %(levelname)s - %(message)s datefmt= -The output is nearly identical to that of the non-config-file-based example:: +The output is nearly identical to that of the non-config-file-based example: + +.. code-block:: bash $ python simple_logging_config.py 2005-03-19 15:38:55,977 - simpleExample - DEBUG - debug message @@ -1073,4 +1081,3 @@ take up any memory. Useful handlers included with the logging module. :ref:`A logging cookbook ` - diff --git a/Doc/howto/regex.rst b/Doc/howto/regex.rst index 909420b..11c3d2b 100644 --- a/Doc/howto/regex.rst +++ b/Doc/howto/regex.rst @@ -74,7 +74,9 @@ of the RE by repeating them or changing their meaning. Much of this document is devoted to discussing various metacharacters and what they do. Here's a complete list of the metacharacters; their meanings will be discussed -in the rest of this HOWTO. :: +in the rest of this HOWTO. + +.. code-block:: none . ^ $ * + ? { } [ ] \ | ( ) diff --git a/Doc/howto/unicode.rst b/Doc/howto/unicode.rst index 8776e3c..7a66a01 100644 --- a/Doc/howto/unicode.rst +++ b/Doc/howto/unicode.rst @@ -613,7 +613,9 @@ program:: print(os.listdir(b'.')) print(os.listdir('.')) -will produce the following output:: +will produce the following output: + +.. code-block:: bash amk:~$ python t.py [b'filename\xe4\x94\x80abc', ...] diff --git a/Doc/library/2to3.rst b/Doc/library/2to3.rst index 31f681d..2c3c80c 100644 --- a/Doc/library/2to3.rst +++ b/Doc/library/2to3.rst @@ -33,14 +33,18 @@ Here is a sample Python 2.x source file, :file:`example.py`:: name = raw_input() greet(name) -It can be converted to Python 3.x code via 2to3 on the command line:: +It can be converted to Python 3.x code via 2to3 on the command line: + +.. code-block:: bash $ 2to3 example.py A diff against the original source file is printed. 2to3 can also write the needed modifications right back to the source file. (A backup of the original file is made unless :option:`-n` is also given.) Writing the changes back is -enabled with the :option:`-w` flag:: +enabled with the :option:`-w` flag: + +.. code-block:: bash $ 2to3 -w example.py @@ -57,17 +61,23 @@ Comments and exact indentation are preserved throughout the translation process. By default, 2to3 runs a set of :ref:`predefined fixers <2to3-fixers>`. The :option:`-l` flag lists all available fixers. An explicit set of fixers to run can be given with :option:`-f`. Likewise the :option:`-x` explicitly disables a -fixer. The following example runs only the ``imports`` and ``has_key`` fixers:: +fixer. The following example runs only the ``imports`` and ``has_key`` fixers: + +.. code-block:: bash $ 2to3 -f imports -f has_key example.py -This command runs every fixer except the ``apply`` fixer:: +This command runs every fixer except the ``apply`` fixer: + +.. code-block:: bash $ 2to3 -x apply example.py Some fixers are *explicit*, meaning they aren't run by default and must be listed on the command line to be run. Here, in addition to the default fixers, -the ``idioms`` fixer is run:: +the ``idioms`` fixer is run: + +.. code-block:: bash $ 2to3 -f all -f idioms example.py @@ -113,7 +123,9 @@ This option implies the :option:`-w` flag as it would not make sense otherwise. The :option:`--add-suffix` option specifies a string to append to all output filenames. The :option:`-n` flag is required when specifying this as backups -are not necessary when writing to different filenames. Example:: +are not necessary when writing to different filenames. Example: + +.. code-block:: bash $ 2to3 -n -W --add-suffix=3 example.py @@ -122,7 +134,9 @@ Will cause a converted file named ``example.py3`` to be written. .. versionadded:: 3.2.3 The :option:`--add-suffix` option was added. -To translate an entire project from one directory tree to another use:: +To translate an entire project from one directory tree to another use: + +.. code-block:: bash $ 2to3 --output-dir=python3-version/mycode -W -n python2-version/mycode diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 2877437..4d796c6 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -44,7 +44,9 @@ produces either the sum or the max:: print(args.accumulate(args.integers)) Assuming the Python code above is saved into a file called ``prog.py``, it can -be run at the command line and provides useful help messages:: +be run at the command line and provides useful help messages: + +.. code-block:: bash $ python prog.py -h usage: prog.py [-h] [--sum] N [N ...] @@ -59,7 +61,9 @@ be run at the command line and provides useful help messages:: --sum sum the integers (default: find the max) When run with the appropriate arguments, it prints either the sum or the max of -the command-line integers:: +the command-line integers: + +.. code-block:: bash $ python prog.py 1 2 3 4 4 @@ -67,7 +71,9 @@ the command-line integers:: $ python prog.py 1 2 3 4 --sum 10 -If invalid arguments are passed in, it will issue an error:: +If invalid arguments are passed in, it will issue an error: + +.. code-block:: bash $ python prog.py a b c usage: prog.py [-h] [--sum] N [N ...] @@ -117,7 +123,9 @@ Parsing arguments :meth:`~ArgumentParser.parse_args` method. This will inspect the command line, convert each argument to the appropriate type and then invoke the appropriate action. In most cases, this means a simple :class:`Namespace` object will be built up from -attributes parsed out of the command line:: +attributes parsed out of the command line: + +.. code-block:: pycon >>> parser.parse_args(['--sum', '7', '-1', '42']) Namespace(accumulate=, integers=[7, -1, 42]) @@ -193,7 +201,9 @@ invoked on the command line. For example, consider a file named args = parser.parse_args() The help for this program will display ``myprogram.py`` as the program name -(regardless of where the program was invoked from):: +(regardless of where the program was invoked from): + +.. code-block:: bash $ python myprogram.py --help usage: myprogram.py [-h] [--foo FOO] @@ -595,7 +605,9 @@ the parser's help message. For example, consider a file named args = parser.parse_args() If ``-h`` or ``--help`` is supplied at the command line, the ArgumentParser -help will be printed:: +help will be printed: + +.. code-block:: bash $ python myprogram.py --help usage: myprogram.py [-h] [--foo FOO] diff --git a/Doc/library/asyncio-dev.rst b/Doc/library/asyncio-dev.rst index 156c5c0..b9557af 100644 --- a/Doc/library/asyncio-dev.rst +++ b/Doc/library/asyncio-dev.rst @@ -321,14 +321,18 @@ operations:: print("Pending tasks at exit: %s" % asyncio.Task.all_tasks(loop)) loop.close() -Expected output:: +Expected output: + +.. code-block:: none (1) create file (2) write into file (3) close file Pending tasks at exit: set() -Actual output:: +Actual output: + +.. code-block:: none (3) close file (2) write into file @@ -369,13 +373,17 @@ Pending task destroyed If a pending task is destroyed, the execution of its wrapped :ref:`coroutine ` did not complete. It is probably a bug and so a warning is logged. -Example of log:: +Example of log: + +.. code-block:: none Task was destroyed but it is pending! task: wait_for=> :ref:`Enable the debug mode of asyncio ` to get the -traceback where the task was created. Example of log in debug mode:: +traceback where the task was created. Example of log in debug mode: + +.. code-block:: none Task was destroyed but it is pending! source_traceback: Object created at (most recent call last): diff --git a/Doc/library/cgi.rst b/Doc/library/cgi.rst index 7e496ca..678a31d 100644 --- a/Doc/library/cgi.rst +++ b/Doc/library/cgi.rst @@ -443,7 +443,9 @@ installing a copy of this module file (:file:`cgi.py`) as a CGI script. When invoked as a script, the file will dump its environment and the contents of the form in HTML form. Give it the right mode etc, and send it a request. If it's installed in the standard :file:`cgi-bin` directory, it should be possible to -send it a request by entering a URL into your browser of the form:: +send it a request by entering a URL into your browser of the form: + +.. code-block:: none http://yourhostname/cgi-bin/cgi.py?name=Joe+Blow&addr=At+Home @@ -535,4 +537,3 @@ Common problems and solutions order the field values should be supplied in, but knowing whether a request was received from a conforming browser, or even from a browser at all, is tedious and error-prone. - diff --git a/Doc/library/cmd.rst b/Doc/library/cmd.rst index 1ab2d74..3318226 100644 --- a/Doc/library/cmd.rst +++ b/Doc/library/cmd.rst @@ -313,7 +313,9 @@ immediate playback:: Here is a sample session with the turtle shell showing the help functions, using -blank lines to repeat commands, and the simple record and playback facility:: +blank lines to repeat commands, and the simple record and playback facility: + +.. code-block:: none Welcome to the turtle shell. Type help or ? to list commands. @@ -372,4 +374,3 @@ blank lines to repeat commands, and the simple record and playback facility:: (turtle) bye Thank you for using Turtle - diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index d46f850..519a091 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -155,7 +155,9 @@ value of that integer or float. Decimal numbers include special values such as If the :exc:`FloatOperation` signal is trapped, accidental mixing of decimals and floats in constructors or ordering comparisons raises -an exception:: +an exception: + +.. code-block:: pycon >>> c = getcontext() >>> c.traps[FloatOperation] = True diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst index 9f7d12c..9d3152b 100644 --- a/Doc/library/doctest.rst +++ b/Doc/library/doctest.rst @@ -84,14 +84,18 @@ Here's a complete but small example module:: doctest.testmod() If you run :file:`example.py` directly from the command line, :mod:`doctest` -works its magic:: +works its magic: + +.. code-block:: bash $ python example.py $ There's no output! That's normal, and it means all the examples worked. Pass ``-v`` to the script, and :mod:`doctest` prints a detailed log of what -it's trying, and prints a summary at the end:: +it's trying, and prints a summary at the end: + +.. code-block:: bash $ python example.py -v Trying: @@ -105,7 +109,9 @@ it's trying, and prints a summary at the end:: [1, 1, 2, 6, 24, 120] ok -And so on, eventually ending with:: +And so on, eventually ending with: + +.. code-block:: none Trying: factorial(1e100) @@ -192,7 +198,9 @@ file. This can be done with the :func:`testfile` function:: That short script executes and verifies any interactive Python examples contained in the file :file:`example.txt`. The file content is treated as if it were a single giant docstring; the file doesn't need to contain a Python -program! For example, perhaps :file:`example.txt` contains this:: +program! For example, perhaps :file:`example.txt` contains this: + +.. code-block:: none The ``example`` module ====================== diff --git a/Doc/library/email-examples.rst b/Doc/library/email-examples.rst index cbbcb78..7fb409c 100644 --- a/Doc/library/email-examples.rst +++ b/Doc/library/email-examples.rst @@ -59,7 +59,9 @@ way we could process it: .. literalinclude:: ../includes/email-read-alternative-new-api.py -Up to the prompt, the output from the above is:: +Up to the prompt, the output from the above is: + +.. code-block:: none To: Penelope Pussycat <"penelope@example.com">, Fabrette Pussycat <"fabrette@example.com"> From: Pepé Le Pew diff --git a/Doc/library/html.parser.rst b/Doc/library/html.parser.rst index 824995e..77c52bf 100644 --- a/Doc/library/html.parser.rst +++ b/Doc/library/html.parser.rst @@ -60,7 +60,9 @@ as they are encountered:: parser.feed('Test' '

Parse me!

') -The output will then be:: +The output will then be: + +.. code-block:: none Encountered a start tag: html Encountered a start tag: head diff --git a/Doc/library/idle.rst b/Doc/library/idle.rst index 4384d56..1e6449f 100644 --- a/Doc/library/idle.rst +++ b/Doc/library/idle.rst @@ -520,7 +520,7 @@ functions to be used from IDLE's Python shell. Command line usage ^^^^^^^^^^^^^^^^^^ -:: +.. code-block:: none idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ... diff --git a/Doc/library/logging.config.rst b/Doc/library/logging.config.rst index fd6a477..6eb33f3 100644 --- a/Doc/library/logging.config.rst +++ b/Doc/library/logging.config.rst @@ -244,7 +244,9 @@ otherwise, the context is used to determine what to instantiate. handler. All *other* keys are passed through as keyword arguments to the - handler's constructor. For example, given the snippet:: + handler's constructor. For example, given the snippet: + + .. code-block:: yaml handlers: console: @@ -353,7 +355,9 @@ it unambiguously, and then using the id in the source object's configuration to indicate that a connection exists between the source and the destination object with that id. -So, for example, consider the following YAML snippet:: +So, for example, consider the following YAML snippet: + +.. code-block:: yaml formatters: brief: @@ -781,5 +785,3 @@ condensed format. Module :mod:`logging.handlers` Useful handlers included with the logging module. - - diff --git a/Doc/library/optparse.rst b/Doc/library/optparse.rst index 160c29d..a62c15b 100644 --- a/Doc/library/optparse.rst +++ b/Doc/library/optparse.rst @@ -677,7 +677,9 @@ automatically adds a ``--version`` option to your parser. If it encounters this option on the command line, it expands your ``version`` string (by replacing ``%prog``), prints it to stdout, and exits. -For example, if your script is called ``/usr/bin/foo``:: +For example, if your script is called ``/usr/bin/foo``: + +.. code-block:: bash $ /usr/bin/foo --version foo 1.0 @@ -727,14 +729,18 @@ program's usage message and an error message to standard error and exits with error status 2. Consider the first example above, where the user passes ``4x`` to an option -that takes an integer:: +that takes an integer: + +.. code-block:: bash $ /usr/bin/foo -n 4x Usage: foo [options] foo: error: option -n: invalid integer value: '4x' -Or, where the user fails to pass a value at all:: +Or, where the user fails to pass a value at all: + +.. code-block:: bash $ /usr/bin/foo -n Usage: foo [options] diff --git a/Doc/library/pickletools.rst b/Doc/library/pickletools.rst index 4c0a148..ba82cd5 100644 --- a/Doc/library/pickletools.rst +++ b/Doc/library/pickletools.rst @@ -30,7 +30,9 @@ However, when the pickle file that you want to examine comes from an untrusted source, ``-m pickletools`` is a safer option because it does not execute pickle bytecode. -For example, with a tuple ``(1, 2)`` pickled in file ``x.pickle``:: +For example, with a tuple ``(1, 2)`` pickled in file ``x.pickle``: + +.. code-block:: bash $ python -m pickle x.pickle (1, 2) @@ -106,4 +108,3 @@ Programmatic Interface Returns a new equivalent pickle string after eliminating unused ``PUT`` opcodes. The optimized pickle is shorter, takes less transmission time, requires less storage space, and unpickles more efficiently. - diff --git a/Doc/library/pyexpat.rst b/Doc/library/pyexpat.rst index bb95431..1ba1ec3 100644 --- a/Doc/library/pyexpat.rst +++ b/Doc/library/pyexpat.rst @@ -84,7 +84,9 @@ The :mod:`xml.parsers.expat` module contains two functions: separator. For example, if *namespace_separator* is set to a space character (``' '``) and - the following document is parsed:: + the following document is parsed: + + .. code-block:: xml >> make_archive(archive_name, 'gztar', root_dir) '/Users/tarek/myarchive.tar.gz' -The resulting archive contains:: +The resulting archive contains: + +.. code-block:: bash $ tar -tzvf /Users/tarek/myarchive.tar.gz drwx------ tarek/staff 0 2010-02-01 16:23:40 ./ @@ -645,4 +647,3 @@ Querying the size of the output terminal .. _`Other Environment Variables`: http://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html#tag_002_003 - diff --git a/Doc/library/socketserver.rst b/Doc/library/socketserver.rst index f0cfc80..14a8f17 100644 --- a/Doc/library/socketserver.rst +++ b/Doc/library/socketserver.rst @@ -483,7 +483,9 @@ This is the client side:: The output of the example should look something like this: -Server:: +Server: + +.. code-block:: bash $ python TCPServer.py 127.0.0.1 wrote: @@ -491,7 +493,9 @@ Server:: 127.0.0.1 wrote: b'python is nice' -Client:: +Client: + +.. code-block:: bash $ python TCPClient.py hello world with TCP Sent: hello world with TCP @@ -606,7 +610,9 @@ An example for the :class:`ThreadingMixIn` class:: server.server_close() -The output of the example should look something like this:: +The output of the example should look something like this: + +.. code-block:: bash $ python ThreadedTCPServer.py Server loop running in thread: Thread-1 diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 36e8ee4..bf635f5 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1281,7 +1281,9 @@ always available. A dictionary of the various implementation-specific flags passed through the :option:`-X` command-line option. Option names are either mapped to - their values, if given explicitly, or to :const:`True`. Example:: + their values, if given explicitly, or to :const:`True`. Example: + + .. code-block:: bash $ ./python -Xa=b -Xc Python 3.2a3+ (py3k, Oct 16 2010, 20:14:50) diff --git a/Doc/library/sysconfig.rst b/Doc/library/sysconfig.rst index 535ac54..b8a62a7 100644 --- a/Doc/library/sysconfig.rst +++ b/Doc/library/sysconfig.rst @@ -228,7 +228,9 @@ Other functions Using :mod:`sysconfig` as a script ---------------------------------- -You can use :mod:`sysconfig` as a script with Python's *-m* option:: +You can use :mod:`sysconfig` as a script with Python's *-m* option: + +.. code-block:: bash $ python -m sysconfig Platform: "macosx-10.4-i386" diff --git a/Doc/library/tarfile.rst b/Doc/library/tarfile.rst index 7a233c1..446515f 100644 --- a/Doc/library/tarfile.rst +++ b/Doc/library/tarfile.rst @@ -655,25 +655,35 @@ The :mod:`tarfile` module provides a simple command line interface to interact with tar archives. If you want to create a new tar archive, specify its name after the :option:`-c` -option and then list the filename(s) that should be included:: +option and then list the filename(s) that should be included: + +.. code-block:: bash $ python -m tarfile -c monty.tar spam.txt eggs.txt -Passing a directory is also acceptable:: +Passing a directory is also acceptable: + +.. code-block:: bash $ python -m tarfile -c monty.tar life-of-brian_1979/ If you want to extract a tar archive into the current directory, use -the :option:`-e` option:: +the :option:`-e` option: + +.. code-block:: bash $ python -m tarfile -e monty.tar You can also extract a tar archive into a different directory by passing the -directory's name:: +directory's name: + +.. code-block:: bash $ python -m tarfile -e monty.tar other-dir/ -For a list of the files in a tar archive, use the :option:`-l` option:: +For a list of the files in a tar archive, use the :option:`-l` option: + +.. code-block:: bash $ python -m tarfile -l monty.tar diff --git a/Doc/library/zipimport.rst b/Doc/library/zipimport.rst index 58e0b7c..20afa4a 100644 --- a/Doc/library/zipimport.rst +++ b/Doc/library/zipimport.rst @@ -145,7 +145,9 @@ Examples -------- Here is an example that imports a module from a ZIP archive - note that the -:mod:`zipimport` module is not explicitly used. :: +:mod:`zipimport` module is not explicitly used. + +.. code-block:: bash $ unzip -l example.zip Archive: example.zip diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 99fa037..b33a71d 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -1388,7 +1388,9 @@ Lambdas Lambda expressions (sometimes called lambda forms) are used to create anonymous functions. The expression ``lambda arguments: expression`` yields a function -object. The unnamed object behaves like a function object defined with :: +object. The unnamed object behaves like a function object defined with: + +.. code-block:: none def (arguments): return expression diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index 8ad975f..21266e2 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -717,12 +717,16 @@ of the list, the augmented assignment operators, serve lexically as delimiters, but also perform an operation. The following printing ASCII characters have special meaning as part of other -tokens or are otherwise significant to the lexical analyzer:: +tokens or are otherwise significant to the lexical analyzer: + +.. code-block:: none ' " # \ The following printing ASCII characters are not used in Python. Their -occurrence outside string literals and comments is an unconditional error:: +occurrence outside string literals and comments is an unconditional error: + +.. code-block:: none $ ? ` diff --git a/Doc/tutorial/controlflow.rst b/Doc/tutorial/controlflow.rst index 813c828..f4fed6c 100644 --- a/Doc/tutorial/controlflow.rst +++ b/Doc/tutorial/controlflow.rst @@ -501,7 +501,9 @@ It could be called like this:: client="John Cleese", sketch="Cheese Shop Sketch") -and of course it would print:: +and of course it would print: + +.. code-block:: none -- Do you have any Limburger ? -- I'm sorry, we're all out of Limburger diff --git a/Doc/tutorial/interpreter.rst b/Doc/tutorial/interpreter.rst index e966085..15c6e68 100644 --- a/Doc/tutorial/interpreter.rst +++ b/Doc/tutorial/interpreter.rst @@ -94,7 +94,9 @@ mode*. In this mode it prompts for the next command with the *primary prompt*, usually three greater-than signs (``>>>``); for continuation lines it prompts with the *secondary prompt*, by default three dots (``...``). The interpreter prints a welcome message stating its version number and a copyright notice -before printing the first prompt:: +before printing the first prompt: + +.. code-block:: bash $ python3.5 Python 3.5 (default, Sep 16 2015, 09:25:04) diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst index 5fbd879..af3d4a0 100644 --- a/Doc/tutorial/modules.rst +++ b/Doc/tutorial/modules.rst @@ -140,7 +140,9 @@ the end of your module:: you can make the file usable as a script as well as an importable module, because the code that parses the command line only runs if the module is -executed as the "main" file:: +executed as the "main" file: + +.. code-block:: bash $ python fibo.py 50 1 1 2 3 5 8 13 21 34 diff --git a/Doc/whatsnew/2.3.rst b/Doc/whatsnew/2.3.rst index cde028d..adffa88 100644 --- a/Doc/whatsnew/2.3.rst +++ b/Doc/whatsnew/2.3.rst @@ -291,7 +291,9 @@ PEP 273: Importing Modules from ZIP Archives The new :mod:`zipimport` module adds support for importing modules from a ZIP- format archive. You don't need to import the module explicitly; it will be automatically imported if a ZIP archive's filename is added to ``sys.path``. -For example:: +For example: + +.. code-block:: bash amk@nyman:~/src/python$ unzip -l /tmp/example.zip Archive: /tmp/example.zip @@ -1761,7 +1763,9 @@ This returns an object containing all of the option values, and a list of strings containing the remaining arguments. Invoking the script with the various arguments now works as you'd expect it to. -Note that the length argument is automatically converted to an integer. :: +Note that the length argument is automatically converted to an integer. + +.. code-block:: bash $ ./python opt.py -i data arg1 @@ -1771,7 +1775,9 @@ Note that the length argument is automatically converted to an integer. :: [] $ -The help message is automatically generated for you:: +The help message is automatically generated for you: + +.. code-block:: bash $ ./python opt.py --help usage: opt.py [options] @@ -2078,4 +2084,3 @@ Michael Hudson, Chris Lambert, Detlef Lannert, Martin von Löwis, Andrew MacIntyre, Lalo Martins, Chad Netzer, Gustavo Niemeyer, Neal Norwitz, Hans Nowak, Chris Reedy, Francesco Ricciardi, Vinay Sajip, Neil Schemenauer, Roman Suzi, Jason Tishler, Just van Rossum. - diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst index c4322db..ee71e23 100644 --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -2266,7 +2266,9 @@ There is an existing data type already used for this, written in pure Python could cause a segmentation fault by taking a :c:type:`PyCObject` from module A and somehow substituting it for the :c:type:`PyCObject` in module B. Capsules know their own name, -and getting the pointer requires providing the name:: +and getting the pointer requires providing the name: + +.. code-block:: c void *vtable; @@ -2586,4 +2588,3 @@ The author would like to thank the following people for offering suggestions, corrections and assistance with various drafts of this article: Nick Coghlan, Philip Jenvey, Ryan Lovett, R. David Murray, Hugh Secker-Walker. - diff --git a/Doc/whatsnew/3.0.rst b/Doc/whatsnew/3.0.rst index f6d1a47..f375e01 100644 --- a/Doc/whatsnew/3.0.rst +++ b/Doc/whatsnew/3.0.rst @@ -117,7 +117,9 @@ You can also customize the separator between items, e.g.:: print("There are <", 2**32, "> possibilities!", sep="") -which produces:: +which produces: + +.. code-block:: none There are <4294967296> possibilities! diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst index 4242f22..1909be5 100644 --- a/Doc/whatsnew/3.2.rst +++ b/Doc/whatsnew/3.2.rst @@ -160,6 +160,8 @@ each with their own argument patterns and help displays:: parser_m.add_argument('-c', '--course', type=int, required=True) parser_m.add_argument('-s', '--speed', type=int, default=0) +.. code-block:: bash + $ ./helm.py --help # top level help (launch and move) $ ./helm.py launch --help # help for launch options $ ./helm.py launch --missiles # set missiles=True and torpedos=False @@ -477,7 +479,9 @@ Some smaller changes made to the core Python language are: * The interpreter can now be started with a quiet option, ``-q``, to prevent the copyright and version information from being displayed in the interactive - mode. The option can be introspected using the :attr:`sys.flags` attribute:: + mode. The option can be introspected using the :attr:`sys.flags` attribute: + + .. code-block:: bash $ python -q >>> sys.flags @@ -572,7 +576,9 @@ Some smaller changes made to the core Python language are: by Benjamin Peterson in :issue:`8413`.) * Warnings are now easier to control using the :envvar:`PYTHONWARNINGS` - environment variable as an alternative to using ``-W`` at the command line:: + environment variable as an alternative to using ``-W`` at the command line: + + .. code-block:: bash $ export PYTHONWARNINGS='ignore::RuntimeWarning::,once::UnicodeWarning::' @@ -594,7 +600,9 @@ Some smaller changes made to the core Python language are: object ensures it closes the underlying operating system resource (usually, a file descriptor), the delay in deallocating the object could produce various issues, especially under Windows. Here is an example - of enabling the warning from the command line:: + of enabling the warning from the command line: + + .. code-block:: bash $ python -q -Wdefault >>> f = open("foo", "wb") @@ -1718,7 +1726,9 @@ names. test discovery can find tests within packages, locating any test importable from the top-level directory. The top-level directory can be specified with the `-t` option, a pattern for matching files with ``-p``, and a directory to - start discovery with ``-s``:: + start discovery with ``-s``: + + .. code-block:: bash $ python -m unittest discover -s my_proj_dir -p _test.py @@ -1893,7 +1903,9 @@ pydoc The :mod:`pydoc` module now provides a much-improved Web server interface, as well as a new command-line option ``-b`` to automatically open a browser window -to display that server:: +to display that server: + +.. code-block:: bash $ pydoc3.2 -b @@ -1931,7 +1943,9 @@ object. The former returns a string and the latter prints it:: In addition, the :func:`~dis.dis` function now accepts string arguments so that the common idiom ``dis(compile(s, '', 'eval'))`` can be shortened -to ``dis(s)``:: +to ``dis(s)``: + +.. code-block:: pycon >>> dis('3*x+1 if x%2==1 else x//2') 1 0 LOAD_NAME 0 (x) @@ -1983,7 +1997,7 @@ details of a given Python installation. * :func:`~site.getusersitepackages` reveals the user-specific site-packages directory path. -:: +.. code-block:: pycon >>> import site >>> site.getsitepackages() @@ -1996,7 +2010,9 @@ details of a given Python installation. '/Users/raymondhettinger/Library/Python/3.2/lib/python/site-packages' Conveniently, some of site's functionality is accessible directly from the -command-line:: +command-line: + +.. code-block:: bash $ python -m site --user-base /Users/raymondhettinger/.local @@ -2029,7 +2045,9 @@ seven named schemes used by :mod:`distutils`. Those include *posix_prefix*, * :func:`~sysconfig.get_config_vars` returns a dictionary of platform specific variables. -There is also a convenient command-line interface:: +There is also a convenient command-line interface: + +.. code-block:: none C:\Python32>python -m sysconfig Platform: "win32" @@ -2098,7 +2116,9 @@ which has in turn been renamed to :class:`~configparser.ConfigParser`. Support for inline comments is now turned off by default and section or option duplicates are not allowed in a single configuration source. -Config parsers gained a new API based on the mapping protocol:: +Config parsers gained a new API based on the mapping protocol: + +.. code-block:: pycon >>> parser = ConfigParser() >>> parser.read_string(""" @@ -2134,7 +2154,9 @@ can specify alternative option/value delimiters and comment prefixes, change the name of the *DEFAULT* section or switch the interpolation syntax. There is support for pluggable interpolation including an additional interpolation -handler :class:`~configparser.ExtendedInterpolation`:: +handler :class:`~configparser.ExtendedInterpolation`: + +.. code-block:: pycon >>> parser = ConfigParser(interpolation=ExtendedInterpolation()) >>> parser.read_dict({'buildout': {'directory': '/home/ambv/zope9'}, @@ -2191,7 +2213,9 @@ The :func:`~urllib.parse.urlparse` function now supports `IPv6 query='', fragment='') -The :func:`~urllib.parse.urldefrag` function now returns a :term:`named tuple`:: +The :func:`~urllib.parse.urldefrag` function now returns a :term:`named tuple`: + +.. code-block:: pycon >>> r = urllib.parse.urldefrag('http://python.org/about/#target') >>> r @@ -2204,7 +2228,9 @@ The :func:`~urllib.parse.urldefrag` function now returns a :term:`named tuple`:: And, the :func:`~urllib.parse.urlencode` function is now much more flexible, accepting either a string or bytes type for the *query* argument. If it is a string, then the *safe*, *encoding*, and *error* parameters are sent to -:func:`~urllib.parse.quote_plus` for encoding:: +:func:`~urllib.parse.quote_plus` for encoding: + +.. code-block:: pycon >>> urllib.parse.urlencode([ ('type', 'telenovela'), @@ -2263,7 +2289,9 @@ turtledemo The demonstration code for the :mod:`turtle` module was moved from the *Demo* directory to main library. It includes over a dozen sample scripts with lively displays. Being on :attr:`sys.path`, it can now be run directly -from the command-line:: +from the command-line: + +.. code-block:: bash $ python -m turtledemo @@ -2699,4 +2727,3 @@ require changes to your code: * Due to the new :term:`GIL` implementation, :c:func:`PyEval_InitThreads()` cannot be called before :c:func:`Py_Initialize()` anymore. - diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst index 779f7f4..d5e8469 100644 --- a/Doc/whatsnew/3.3.rst +++ b/Doc/whatsnew/3.3.rst @@ -871,7 +871,9 @@ signal. Call :func:`faulthandler.enable` to install fault handlers for the :envvar:`PYTHONFAULTHANDLER` environment variable or by using :option:`-X` ``faulthandler`` command line option. -Example of a segmentation fault on Linux: :: +Example of a segmentation fault on Linux: + +.. code-block:: bash $ python -q -X faulthandler >>> import ctypes @@ -997,7 +999,9 @@ byte of an invalid byte sequence. For example, ``b'\xff\n'.decode('gb2312', (:issue:`12016`) Incremental CJK codec encoders are no longer reset at each call to their -encode() methods. For example:: +encode() methods. For example: + +.. code-block:: bash $ ./python -q >>> import codecs diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst index ffe6ae4..955092e 100644 --- a/Doc/whatsnew/3.5.rst +++ b/Doc/whatsnew/3.5.rst @@ -729,7 +729,9 @@ publicized, either at the time or since. With the new module, bundling your application is as simple as putting all the files, including a ``__main__.py`` file, into a directory ``myapp`` -and running:: +and running: + +.. code-block:: bash $ python -m zipapp myapp $ python myapp.pyz @@ -2492,4 +2494,3 @@ Changes in the C API :c:type:`PyTypeObject` was replaced with a :c:member:`tp_as_async` slot. Refer to :ref:`coro-objects` for new types, structures and functions. -