Python: Is there a way to keep an automatic conversion from int to long int from happening?
Python is more strongly typed than other scripting languages. For example, in Perl:

    perl -E '$c=5; $d="6"; say $c+$d'   #prints 11

But in Python:

    >>> c="6"
    >>> d=5
    >>> print c+d
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: cannot concatenate 'str' and 'int' objects

Perl will inspect a string and convert to a number, and the `+ - / * **` operators work as you expect with a number. PHP is similar. 

Python uses `+` to concatenate strings so the the attempted operation of `c+d` fails because c is a string, d an int. Python has stronger sense of [numeric types][1] than does Perl. OK -- I can deal with that. 

But consider:

    >>> from sys import maxint
    >>> type(maxint)
    <type 'int'>
    >>> print maxint
    9223372036854775807
    >>> type(maxint+2)
    <type 'long'>
    >>> print maxint+2
    9223372036854775809
    >>> type((maxint+2)+maxint)
    <type 'long'>
    >>> print ((maxint+2)+maxint)
    18446744073709551616


Now Python will [autopromote][2] from an int, which in this case is a 64 bit long (OS X, python 2.6.1) to a python long int which is of arbitrary precision. Even though the types are not the same, they are similar and Python allows the usual numeric operators to be used. Usually this is helpful. It is helpful with smoothing the differences between 32 bit and 64 bit for example. 

The conversion is one way:

    >>> type((maxint+2)-2)
    <type 'long'>

Once the conversion is made, all operations on that variable are now done in arbitrary precision. The arbitrary precision operations are orders of magnitude slower than the native int operations. On a script I am working on, I would have some execution be snappy and other that extended into hours because of this. Consider:

    >>> print maxint**maxint        # execution so long it is essentially a crash

So my question: Is there a way to defeat or not allow the auto-promotion of a Python `int` to a Python `long`? 


  [1]: http://docs.python.org/library/stdtypes.html#typesnumeric
  [2]: http://www.python.org/dev/peps/pep-0237/
Python: Is there a way to keep an automatic conversion from int to long int from happening?
===

Python is more strongly typed than other scripting languages. For example, in Perl:

    perl -E '$c=5; $d="6"; say $c+$d'   #prints 11

But in Python:

    >>> c="6"
    >>> d=5
    >>> print c+d
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: cannot concatenate 'str' and 'int' objects

Perl will inspect a string and convert to a number, and the `+ - / * **` operators work as you expect with a number. PHP is similar. 

Python uses `+` to concatenate strings so the the attempted operation of `c+d` fails because c is a string, d an int. Python has stronger sense of [numeric types][1] than does Perl. OK -- I can deal with that. 

But consider:

    >>> from sys import maxint
    >>> type(maxint)
    <type 'int'>
    >>> print maxint
    9223372036854775807
    >>> type(maxint+2)
    <type 'long'>
    >>> print maxint+2
    9223372036854775809
    >>> type((maxint+2)+maxint)
    <type 'long'>
    >>> print ((maxint+2)+maxint)
    18446744073709551616


Now Python will [autopromote][2] from an int, which in this case is a 64 bit long (OS X, python 2.6.1) to a python long int which is of arbitrary precision. Even though the types are not the same, they are similar and Python allows the usual numeric operators to be used. Usually this is helpful. It is helpful with smoothing the differences between 32 bit and 64 bit for example. 

The conversion is one way:

    >>> type((maxint+2)-2)
    <type 'long'>

Once the conversion is made, all operations on that variable are now done in arbitrary precision. The arbitrary precision operations are orders of magnitude slower than the native int operations. On a script I am working on, I would have some execution be snappy and other that extended into hours because of this. Consider:

    >>> print maxint**maxint        # execution so long it is essentially a crash

So my question: Is there a way to defeat or not allow the auto-promotion of a Python `int` to a Python `long`? 


  [1]: http://docs.python.org/library/stdtypes.html#typesnumeric
  [2]: http://www.python.org/dev/peps/pep-0237/