", line 1, in ? with File "", line 1, in . (cherry picked from commit 8856940cf2e82cb17db2b684cd5732fe658605ca)">

[2.7] bpo-28315: Improve code examples in docs (GH-1372) (#1447) · python/cpython@e1b02ff (original) (raw)

`@@ -87,7 +87,7 @@ Functions are accessed as attributes of dll objects::

`

87

87

` <_FuncPtr object at 0x...>

`

88

88

` >>> print windll.kernel32.MyOwnFunction # doctest: +WINDOWS

`

89

89

` Traceback (most recent call last):

`

90

``

`-

File "", line 1, in ?

`

``

90

`+

File "", line 1, in

`

91

91

` File "ctypes.py", line 239, in getattr

`

92

92

` func = _StdcallFuncPtr(name, self)

`

93

93

` AttributeError: function 'MyOwnFunction' not found

`

`@@ -126,7 +126,7 @@ functions can be accessed by indexing the dll object with the ordinal number::

`

126

126

` <_FuncPtr object at 0x...>

`

127

127

` >>> cdll.kernel32[0] # doctest: +WINDOWS

`

128

128

` Traceback (most recent call last):

`

129

``

`-

File "", line 1, in ?

`

``

129

`+

File "", line 1, in

`

130

130

` File "ctypes.py", line 310, in getitem

`

131

131

` func = _StdcallFuncPtr(name, self)

`

132

132

` AttributeError: function ordinal 0 not found

`

`@@ -159,11 +159,11 @@ although an error is raised the function has been called::

`

159

159

``

160

160

` >>> windll.kernel32.GetModuleHandleA() # doctest: +WINDOWS

`

161

161

` Traceback (most recent call last):

`

162

``

`-

File "", line 1, in ?

`

``

162

`+

File "", line 1, in

`

163

163

` ValueError: Procedure probably called with not enough arguments (4 bytes missing)

`

164

164

` >>> windll.kernel32.GetModuleHandleA(0, 0) # doctest: +WINDOWS

`

165

165

` Traceback (most recent call last):

`

166

``

`-

File "", line 1, in ?

`

``

166

`+

File "", line 1, in

`

167

167

` ValueError: Procedure probably called with too many arguments (4 bytes in excess)

`

168

168

` >>>

`

169

169

``

``` @@ -172,13 +172,13 @@ The same exception is raised when you call an stdcall function with the

```

172

172

``

173

173

` >>> cdll.kernel32.GetModuleHandleA(None) # doctest: +WINDOWS

`

174

174

` Traceback (most recent call last):

`

175

``

`-

File "", line 1, in ?

`

``

175

`+

File "", line 1, in

`

176

176

` ValueError: Procedure probably called with not enough arguments (4 bytes missing)

`

177

177

` >>>

`

178

178

``

179

179

` >>> windll.msvcrt.printf("spam") # doctest: +WINDOWS

`

180

180

` Traceback (most recent call last):

`

181

``

`-

File "", line 1, in ?

`

``

181

`+

File "", line 1, in

`

182

182

` ValueError: Procedure probably called with too many arguments (4 bytes in excess)

`

183

183

` >>>

`

184

184

``

`@@ -191,7 +191,7 @@ argument values::

`

191

191

``

192

192

` >>> windll.kernel32.GetModuleHandleA(32) # doctest: +WINDOWS

`

193

193

` Traceback (most recent call last):

`

194

``

`-

File "", line 1, in ?

`

``

194

`+

File "", line 1, in

`

195

195

` WindowsError: exception: access violation reading 0x00000020

`

196

196

` >>>

`

197

197

``

`@@ -354,7 +354,7 @@ from within IDLE or PythonWin::

`

354

354

` 19

`

355

355

` >>> printf("%f bottles of beer\n", 42.5)

`

356

356

` Traceback (most recent call last):

`

357

``

`-

File "", line 1, in ?

`

``

357

`+

File "", line 1, in

`

358

358

` ArgumentError: argument 2: exceptions.TypeError: Don't know how to convert parameter 2

`

359

359

` >>>

`

360

360

``

`@@ -417,7 +417,7 @@ prototype for a C function), and tries to convert the arguments to valid types::

`

417

417

``

418

418

` >>> printf("%d %d %d", 1, 2, 3)

`

419

419

` Traceback (most recent call last):

`

420

``

`-

File "", line 1, in ?

`

``

420

`+

File "", line 1, in

`

421

421

` ArgumentError: argument 2: exceptions.TypeError: wrong type

`

422

422

` >>> printf("%s %d %f\n", "X", 2, 3)

`

423

423

` X 2 3.000000

`

`@@ -467,7 +467,7 @@ single character Python string into a C char::

`

467

467

` 'def'

`

468

468

` >>> strchr("abcdef", "def")

`

469

469

` Traceback (most recent call last):

`

470

``

`-

File "", line 1, in ?

`

``

470

`+

File "", line 1, in

`

471

471

` ArgumentError: argument 2: exceptions.TypeError: one character string expected

`

472

472

` >>> print strchr("abcdef", "x")

`

473

473

` None

`

`@@ -493,7 +493,7 @@ useful to check for error return values and automatically raise an exception::

`

493

493

` 486539264

`

494

494

` >>> GetModuleHandle("something silly") # doctest: +WINDOWS

`

495

495

` Traceback (most recent call last):

`

496

``

`-

File "", line 1, in ?

`

``

496

`+

File "", line 1, in

`

497

497

` File "", line 3, in ValidHandle

`

498

498

` WindowsError: [Errno 126] The specified module could not be found.

`

499

499

` >>>

`

`@@ -564,7 +564,7 @@ Here is a simple example of a POINT structure, which contains two integers named

`

564

564

` 0 5

`

565

565

` >>> POINT(1, 2, 3)

`

566

566

` Traceback (most recent call last):

`

567

``

`-

File "", line 1, in ?

`

``

567

`+

File "", line 1, in

`

568

568

` ValueError: too many initializers

`

569

569

` >>>

`

570

570

``

`@@ -767,7 +767,7 @@ a new type::

`

767

767

` <class 'ctypes.LP_c_long'>

`

768

768

` >>> PI(42)

`

769

769

` Traceback (most recent call last):

`

770

``

`-

File "", line 1, in ?

`

``

770

`+

File "", line 1, in

`

771

771

` TypeError: expected c_long instead of int

`

772

772

` >>> PI(c_int(42))

`

773

773

` <ctypes.LP_c_long object at 0x...>

`

`@@ -843,7 +843,7 @@ but not instances of other types::

`

843

843

``

844

844

` >>> bar.values = (c_byte * 4)()

`

845

845

` Traceback (most recent call last):

`

846

``

`-

File "", line 1, in ?

`

``

846

`+

File "", line 1, in

`

847

847

` TypeError: incompatible types, c_byte_Array_4 instance instead of LP_c_long instance

`

848

848

` >>>

`

849

849

``

`@@ -894,7 +894,7 @@ work::

`

894

894

` ... ("next", POINTER(cell))]

`

895

895

` ...

`

896

896

` Traceback (most recent call last):

`

897

``

`-

File "", line 1, in ?

`

``

897

`+

File "", line 1, in

`

898

898

` File "", line 2, in cell

`

899

899

` NameError: name 'cell' is not defined

`

900

900

` >>>

`