Add an example.
This commit is contained in:
parent
1a1c52fa59
commit
872230b693
24
pep-0237.txt
24
pep-0237.txt
|
@ -205,6 +205,30 @@ Transition
|
|||
B4. Python 3.0 (at least two years in the future).
|
||||
|
||||
|
||||
Example
|
||||
|
||||
If you pass a long int to a C function or built-in operation that
|
||||
takes an integer, it will be treated the same as as a short int as
|
||||
long as the value fits (by virtue of how PyArg_ParseTuple() is
|
||||
implemented). If the long value doesn't fit, it will still raise
|
||||
an OverflowError. For example:
|
||||
|
||||
def fact(n):
|
||||
if n <= 1:
|
||||
return 1
|
||||
return n*fact(n-1)
|
||||
|
||||
A = "ABCDEFGHIJKLMNOPQ"
|
||||
n = input("Gimme an int: ")
|
||||
print A[fact(n)%17]
|
||||
|
||||
For n >= 13, this currently raises OverflowError (unless the user
|
||||
enters a trailing 'L' as part of their input), even though the
|
||||
calculated index would always be in range(17). With the new
|
||||
approach this code will do the right thing: the index will be
|
||||
calculated as a long int, but its value will be in range.
|
||||
|
||||
|
||||
Open Issues
|
||||
|
||||
We expect that these issues will be resolved over time, as more
|
||||
|
|
Loading…
Reference in New Issue