exceptions.TypeError an integer is required

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Jul 28 02:46:00 EDT 2009


En Mon, 27 Jul 2009 12:44:40 -0300, jakecjacobson  
<jakecjacobson at gmail.com> escribió:
>
> You are quite correct in your statements.  My goal was not to make
> great code but something that I could quickly test.  My assumption was
> that the httplib.HTTPSConnection() would do the cast to int for me.
> As soon as I cast it to an int, I was able to get past that issue.

A few remarks that may help learning the language:

Note that Python is a strongly typed (and dynamic) language. All objects  
have a defined type: "443" is not the same thing as 443, and "2" + 2  
raises a TypeError.

If a function expects an integer, you must provide an integer (or  
something that at least "acts" as an integer; a string isn't  
"integer-alike" at all from Python's POV)

Also, you don't "cast" an object into another: the expression int("443")  
is a constructor, and it returns a new object (an integer) based upon its  
argument. (so it's quite different from, say, casting "short" to "unsigned  
short" in C, that only changes the way the compiler treats the same bytes  
in memory).

-- 
Gabriel Genellina




More information about the Python-list mailing list