@@ -33,14 +33,18 @@ Here is a sample Python 2.x source file, :file:`example.py`::
33
33
name = raw_input()
34
34
greet(name)
35
35
36
- It can be converted to Python 3.x code via 2to3 on the command line::
36
+ It can be converted to Python 3.x code via 2to3 on the command line:
37
+
38
+ .. code-block :: shell-session
37
39
38
40
$ 2to3 example.py
39
41
40
42
A diff against the original source file is printed. 2to3 can also write the
41
43
needed modifications right back to the source file. (A backup of the original
42
44
file is made unless :option: `-n ` is also given.) Writing the changes back is
43
- enabled with the :option: `-w ` flag::
45
+ enabled with the :option: `-w ` flag:
46
+
47
+ .. code-block :: shell-session
44
48
45
49
$ 2to3 -w example.py
46
50
@@ -57,17 +61,23 @@ Comments and exact indentation are preserved throughout the translation process.
57
61
By default, 2to3 runs a set of :ref: `predefined fixers <2to3-fixers >`. The
58
62
:option: `!-l ` flag lists all available fixers. An explicit set of fixers to run
59
63
can be given with :option: `-f `. Likewise the :option: `!-x ` explicitly disables a
60
- fixer. The following example runs only the ``imports `` and ``has_key `` fixers::
64
+ fixer. The following example runs only the ``imports `` and ``has_key `` fixers:
65
+
66
+ .. code-block :: shell-session
61
67
62
68
$ 2to3 -f imports -f has_key example.py
63
69
64
- This command runs every fixer except the ``apply `` fixer::
70
+ This command runs every fixer except the ``apply `` fixer:
71
+
72
+ .. code-block :: shell-session
65
73
66
74
$ 2to3 -x apply example.py
67
75
68
76
Some fixers are *explicit *, meaning they aren't run by default and must be
69
77
listed on the command line to be run. Here, in addition to the default fixers,
70
- the ``idioms `` fixer is run::
78
+ the ``idioms `` fixer is run:
79
+
80
+ .. code-block :: shell-session
71
81
72
82
$ 2to3 -f all -f idioms example.py
73
83
@@ -113,7 +123,9 @@ This option implies the :option:`-w` flag as it would not make sense otherwise.
113
123
114
124
The :option: `--add-suffix ` option specifies a string to append to all output
115
125
filenames. The :option: `-n ` flag is required when specifying this as backups
116
- are not necessary when writing to different filenames. Example::
126
+ are not necessary when writing to different filenames. Example:
127
+
128
+ .. code-block :: shell-session
117
129
118
130
$ 2to3 -n -W --add-suffix=3 example.py
119
131
@@ -122,7 +134,9 @@ Will cause a converted file named ``example.py3`` to be written.
122
134
.. versionadded :: 3.2.3
123
135
The :option: `--add-suffix ` option was added.
124
136
125
- To translate an entire project from one directory tree to another use::
137
+ To translate an entire project from one directory tree to another use:
138
+
139
+ .. code-block :: shell-session
126
140
127
141
$ 2to3 --output-dir=python3-version/mycode -W -n python2-version/mycode
128
142
0 commit comments