Newbie naive question ... int() throws ValueError

John Terrak john.terrak at gmail.com
Fri May 11 01:55:57 EDT 2012


Hi

Sorry for such a naive question.

I couldnt find anywhere in the documentation that int() can throw a ValueError.
I checked the "The Python Language Reference", and the "The Python
Standard Library " to no avail.
Did I missed something?

So here is the question - if it is not in the documentation - how does
one find out the
exceptions that are thrown by a constructor, a method or a function?

Example:  int("not_an_int")
>>> int("not_an_int")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'not_an_int'

>From what I gathered:
class int(object):
  """ int(x[, base]) -> integer

  Convert a string or number to an integer, if possible.  A floating point
  argument will be truncated towards zero (this does not include a string
  representation of a floating point number!)  When converting a string, use
  the optional base.  It is an error to supply a base when converting a
  non-string.  If base is zero, the proper base is guessed based on the
  string content.  If the argument is outside the integer range a
  long object will be returned instead. """

Thanks for your help - and sorry again for such a naive question.

John T.



More information about the Python-list mailing list