inheriting a large python code base

Chris Angelico rosuav at gmail.com
Sun Feb 16 08:26:55 EST 2014


On Sun, Feb 16, 2014 at 11:59 PM, Rita <rmorgan466 at gmail.com> wrote:
> when I do profiling is it possible to find out if I am spending a lot of
> time in type conversion?
> it seems I am not.

I would guess that you don't. But in Python, type conversion is like
any other function call:

value = int("12345")

So you can test for it the same way you would any other.

> Also, is it possible to predeclare a type in python?
> Similar to C: int i=0;
>

No, because in Python, variables/names don't have types - only
objects/values do. You can simply initialize i to 0, in the obvious
way:

i = 0

And if you never put anything but an integer into i, it'll always be
an integer. That's about as close as you'll get to an "integer
variable" like C has. (Python's idea of an integer is rather better
than C's, of course; C's 'int' type is a machine word, so it can't
store values greater than 2**32 or 2**64 or whatever the limit is, but
Python's int can store any integer you have RAM enough to store.)

ChrisA



More information about the Python-list mailing list