Kaydet (Commit) 8856940c authored tarafından UltimateCoder's avatar UltimateCoder Kaydeden (comit) Mariatta

bpo-28315: Improve code examples in docs (GH-1372)

Replace
   File "<stdin>", line 1, in ? 
with 
   File "<stdin>", line 1, in <module>
üst a5c62a8e
...@@ -124,7 +124,7 @@ our objects and in some error messages, for example:: ...@@ -124,7 +124,7 @@ our objects and in some error messages, for example::
>>> "" + noddy.new_noddy() >>> "" + noddy.new_noddy()
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
TypeError: cannot add type "noddy.Noddy" to string TypeError: cannot add type "noddy.Noddy" to string
Note that the name is a dotted name that includes both the module name and the Note that the name is a dotted name that includes both the module name and the
......
...@@ -210,7 +210,7 @@ You can experiment with the iteration interface manually: ...@@ -210,7 +210,7 @@ You can experiment with the iteration interface manually:
3 3
>>> next(it) >>> next(it)
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
StopIteration StopIteration
>>> >>>
...@@ -474,7 +474,7 @@ Here's a sample usage of the ``generate_ints()`` generator: ...@@ -474,7 +474,7 @@ Here's a sample usage of the ``generate_ints()`` generator:
2 2
>>> next(gen) >>> next(gen)
Traceback (most recent call last): Traceback (most recent call last):
File "stdin", line 1, in ? File "stdin", line 1, in <module>
File "stdin", line 2, in generate_ints File "stdin", line 2, in generate_ints
StopIteration StopIteration
...@@ -577,7 +577,7 @@ And here's an example of changing the counter: ...@@ -577,7 +577,7 @@ And here's an example of changing the counter:
9 9
>>> next(it) #doctest: +SKIP >>> next(it) #doctest: +SKIP
Traceback (most recent call last): Traceback (most recent call last):
File "t.py", line 15, in ? File "t.py", line 15, in <module>
it.next() it.next()
StopIteration StopIteration
......
...@@ -97,7 +97,7 @@ Functions are accessed as attributes of dll objects:: ...@@ -97,7 +97,7 @@ Functions are accessed as attributes of dll objects::
<_FuncPtr object at 0x...> <_FuncPtr object at 0x...>
>>> print(windll.kernel32.MyOwnFunction) # doctest: +WINDOWS >>> print(windll.kernel32.MyOwnFunction) # doctest: +WINDOWS
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
File "ctypes.py", line 239, in __getattr__ File "ctypes.py", line 239, in __getattr__
func = _StdcallFuncPtr(name, self) func = _StdcallFuncPtr(name, self)
AttributeError: function 'MyOwnFunction' not found AttributeError: function 'MyOwnFunction' not found
...@@ -135,7 +135,7 @@ functions can be accessed by indexing the dll object with the ordinal number:: ...@@ -135,7 +135,7 @@ functions can be accessed by indexing the dll object with the ordinal number::
<_FuncPtr object at 0x...> <_FuncPtr object at 0x...>
>>> cdll.kernel32[0] # doctest: +WINDOWS >>> cdll.kernel32[0] # doctest: +WINDOWS
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
File "ctypes.py", line 310, in __getitem__ File "ctypes.py", line 310, in __getitem__
func = _StdcallFuncPtr(name, self) func = _StdcallFuncPtr(name, self)
AttributeError: function ordinal 0 not found AttributeError: function ordinal 0 not found
...@@ -168,11 +168,11 @@ although an error is raised the function *has* been called:: ...@@ -168,11 +168,11 @@ although an error is raised the function *has* been called::
>>> windll.kernel32.GetModuleHandleA() # doctest: +WINDOWS >>> windll.kernel32.GetModuleHandleA() # doctest: +WINDOWS
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
ValueError: Procedure probably called with not enough arguments (4 bytes missing) ValueError: Procedure probably called with not enough arguments (4 bytes missing)
>>> windll.kernel32.GetModuleHandleA(0, 0) # doctest: +WINDOWS >>> windll.kernel32.GetModuleHandleA(0, 0) # doctest: +WINDOWS
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
ValueError: Procedure probably called with too many arguments (4 bytes in excess) ValueError: Procedure probably called with too many arguments (4 bytes in excess)
>>> >>>
...@@ -181,13 +181,13 @@ The same exception is raised when you call an ``stdcall`` function with the ...@@ -181,13 +181,13 @@ The same exception is raised when you call an ``stdcall`` function with the
>>> cdll.kernel32.GetModuleHandleA(None) # doctest: +WINDOWS >>> cdll.kernel32.GetModuleHandleA(None) # doctest: +WINDOWS
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
ValueError: Procedure probably called with not enough arguments (4 bytes missing) ValueError: Procedure probably called with not enough arguments (4 bytes missing)
>>> >>>
>>> windll.msvcrt.printf(b"spam") # doctest: +WINDOWS >>> windll.msvcrt.printf(b"spam") # doctest: +WINDOWS
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
ValueError: Procedure probably called with too many arguments (4 bytes in excess) ValueError: Procedure probably called with too many arguments (4 bytes in excess)
>>> >>>
...@@ -200,7 +200,7 @@ argument values:: ...@@ -200,7 +200,7 @@ argument values::
>>> windll.kernel32.GetModuleHandleA(32) # doctest: +WINDOWS >>> windll.kernel32.GetModuleHandleA(32) # doctest: +WINDOWS
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
OSError: exception: access violation reading 0x00000020 OSError: exception: access violation reading 0x00000020
>>> >>>
...@@ -373,7 +373,7 @@ from within *IDLE* or *PythonWin*:: ...@@ -373,7 +373,7 @@ from within *IDLE* or *PythonWin*::
19 19
>>> printf(b"%f bottles of beer\n", 42.5) >>> printf(b"%f bottles of beer\n", 42.5)
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
ArgumentError: argument 2: exceptions.TypeError: Don't know how to convert parameter 2 ArgumentError: argument 2: exceptions.TypeError: Don't know how to convert parameter 2
>>> >>>
...@@ -436,7 +436,7 @@ prototype for a C function), and tries to convert the arguments to valid types:: ...@@ -436,7 +436,7 @@ prototype for a C function), and tries to convert the arguments to valid types::
>>> printf(b"%d %d %d", 1, 2, 3) >>> printf(b"%d %d %d", 1, 2, 3)
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
ArgumentError: argument 2: exceptions.TypeError: wrong type ArgumentError: argument 2: exceptions.TypeError: wrong type
>>> printf(b"%s %d %f\n", b"X", 2, 3) >>> printf(b"%s %d %f\n", b"X", 2, 3)
X 2 3.000000 X 2 3.000000
...@@ -486,7 +486,7 @@ single character Python bytes object into a C char:: ...@@ -486,7 +486,7 @@ single character Python bytes object into a C char::
'def' 'def'
>>> strchr(b"abcdef", b"def") >>> strchr(b"abcdef", b"def")
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
ArgumentError: argument 2: exceptions.TypeError: one character string expected ArgumentError: argument 2: exceptions.TypeError: one character string expected
>>> print(strchr(b"abcdef", b"x")) >>> print(strchr(b"abcdef", b"x"))
None None
...@@ -512,7 +512,7 @@ useful to check for error return values and automatically raise an exception:: ...@@ -512,7 +512,7 @@ useful to check for error return values and automatically raise an exception::
486539264 486539264
>>> GetModuleHandle("something silly") # doctest: +WINDOWS >>> GetModuleHandle("something silly") # doctest: +WINDOWS
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in ValidHandle File "<stdin>", line 3, in ValidHandle
OSError: [Errno 126] The specified module could not be found. OSError: [Errno 126] The specified module could not be found.
>>> >>>
...@@ -583,7 +583,7 @@ Here is a simple example of a POINT structure, which contains two integers named ...@@ -583,7 +583,7 @@ Here is a simple example of a POINT structure, which contains two integers named
0 5 0 5
>>> POINT(1, 2, 3) >>> POINT(1, 2, 3)
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
ValueError: too many initializers ValueError: too many initializers
>>> >>>
...@@ -786,7 +786,7 @@ new type:: ...@@ -786,7 +786,7 @@ new type::
<class 'ctypes.LP_c_long'> <class 'ctypes.LP_c_long'>
>>> PI(42) >>> PI(42)
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
TypeError: expected c_long instead of int TypeError: expected c_long instead of int
>>> PI(c_int(42)) >>> PI(c_int(42))
<ctypes.LP_c_long object at 0x...> <ctypes.LP_c_long object at 0x...>
...@@ -862,7 +862,7 @@ but not instances of other types:: ...@@ -862,7 +862,7 @@ but not instances of other types::
>>> bar.values = (c_byte * 4)() >>> bar.values = (c_byte * 4)()
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
TypeError: incompatible types, c_byte_Array_4 instance instead of LP_c_long instance TypeError: incompatible types, c_byte_Array_4 instance instead of LP_c_long instance
>>> >>>
...@@ -913,7 +913,7 @@ work:: ...@@ -913,7 +913,7 @@ work::
... ("next", POINTER(cell))] ... ("next", POINTER(cell))]
... ...
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in cell File "<stdin>", line 2, in cell
NameError: name 'cell' is not defined NameError: name 'cell' is not defined
>>> >>>
......
...@@ -408,7 +408,7 @@ Simple example:: ...@@ -408,7 +408,7 @@ Simple example::
>>> [1, 2, 3].remove(42) >>> [1, 2, 3].remove(42)
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
ValueError: list.remove(x): x not in list ValueError: list.remove(x): x not in list
That doctest succeeds if :exc:`ValueError` is raised, with the ``list.remove(x): That doctest succeeds if :exc:`ValueError` is raised, with the ``list.remove(x):
...@@ -432,7 +432,7 @@ multi-line detail:: ...@@ -432,7 +432,7 @@ multi-line detail::
>>> raise ValueError('multi\n line\ndetail') >>> raise ValueError('multi\n line\ndetail')
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
ValueError: multi ValueError: multi
line line
detail detail
...@@ -591,7 +591,7 @@ doctest decides whether actual output matches an example's expected output: ...@@ -591,7 +591,7 @@ doctest decides whether actual output matches an example's expected output:
>>> (1, 2)[3] = 'moo' >>> (1, 2)[3] = 'moo'
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
TypeError: object doesn't support item assignment TypeError: object doesn't support item assignment
passes under Python 2.3 and later Python versions with the flag specified, passes under Python 2.3 and later Python versions with the flag specified,
......
...@@ -89,7 +89,7 @@ The following example demonstrates how to start up and test operation of the ...@@ -89,7 +89,7 @@ The following example demonstrates how to start up and test operation of the
>>> import math >>> import math
>>> math.exp(1000) >>> math.exp(1000)
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
FloatingPointError: in math_1 FloatingPointError: in math_1
......
...@@ -76,7 +76,7 @@ The typical usage to inspect a crashed program is:: ...@@ -76,7 +76,7 @@ The typical usage to inspect a crashed program is::
>>> import mymodule >>> import mymodule
>>> mymodule.test() >>> mymodule.test()
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
File "./mymodule.py", line 4, in test File "./mymodule.py", line 4, in test
test2() test2()
File "./mymodule.py", line 3, in test2 File "./mymodule.py", line 3, in test2
......
...@@ -158,7 +158,7 @@ Examples: ...@@ -158,7 +158,7 @@ Examples:
9 9
>>> unicodedata.decimal('a') >>> unicodedata.decimal('a')
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
ValueError: not a decimal ValueError: not a decimal
>>> unicodedata.category('A') # 'L'etter, 'u'ppercase >>> unicodedata.category('A') # 'L'etter, 'u'ppercase
'Lu' 'Lu'
......
...@@ -905,7 +905,7 @@ keyword arguments (and any ``**expression`` arguments -- see below). So:: ...@@ -905,7 +905,7 @@ keyword arguments (and any ``**expression`` arguments -- see below). So::
2 1 2 1
>>> f(a=1, *(2,)) >>> f(a=1, *(2,))
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
TypeError: f() got multiple values for keyword argument 'a' TypeError: f() got multiple values for keyword argument 'a'
>>> f(1, *(2,)) >>> f(1, *(2,))
1 2 1 2
......
...@@ -784,7 +784,7 @@ using the :func:`next` built-in function; this example shows how it all works:: ...@@ -784,7 +784,7 @@ using the :func:`next` built-in function; this example shows how it all works::
'c' 'c'
>>> next(it) >>> next(it)
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
next(it) next(it)
StopIteration StopIteration
......
...@@ -475,7 +475,7 @@ Here's an example that fails due to this restriction:: ...@@ -475,7 +475,7 @@ Here's an example that fails due to this restriction::
... ...
>>> function(0, a=0) >>> function(0, a=0)
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
TypeError: function() got multiple values for keyword argument 'a' TypeError: function() got multiple values for keyword argument 'a'
When a final formal parameter of the form ``**name`` is present, it receives a When a final formal parameter of the form ``**name`` is present, it receives a
......
...@@ -261,7 +261,7 @@ it must be parenthesized. :: ...@@ -261,7 +261,7 @@ it must be parenthesized. ::
[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)] [(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]
>>> # the tuple must be parenthesized, otherwise an error is raised >>> # the tuple must be parenthesized, otherwise an error is raised
>>> [x, x**2 for x in range(6)] >>> [x, x**2 for x in range(6)]
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
[x, x**2 for x in range(6)] [x, x**2 for x in range(6)]
^ ^
SyntaxError: invalid syntax SyntaxError: invalid syntax
......
...@@ -362,7 +362,7 @@ attempts to use the file object will automatically fail. :: ...@@ -362,7 +362,7 @@ attempts to use the file object will automatically fail. ::
>>> f.close() >>> f.close()
>>> f.read() >>> f.read()
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in ? File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file ValueError: I/O operation on closed file
It is good practice to use the :keyword:`with` keyword when dealing with file It is good practice to use the :keyword:`with` keyword when dealing with file
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment