Reading the documentation

bob gailer bgailer at gmail.com
Thu Aug 24 19:21:23 EDT 2017


On 8/24/2017 3:54 PM, Nathan Ernst wrote:
> You passed a string to "math.floor", not anything resembling a numeric
> type. Try using an actual float, int or Decimal:
It would seem you did not understand the OP's question. It was not "why 
did I get this traceback."
He showed the traceback as leading him to use the help builtin.
He was questioning what help() returned.
>
> Python 3.5.2 (default, Nov 17 2016, 17:05:23)
> [GCC 5.4.0 20160609] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from math import floor
>>>> from decimal import Decimal
>>>> floor("2.3")
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: a float is required
>
>>>> floor(2.3)
> 2
>
>>>> floor(Decimal("2.3"))
> 2
>
>>>> floor(2)
> 2
>
> Remember that Python is strongly typed; you do not get automatic type
> conversions from strings to numeric types such as in Perl.
>
> Regards,
> Nathan
>
> On Thu, Aug 24, 2017 at 2:24 PM, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
>
>>    This is a transcript:
>>
>>>>> from math import floor
>>>>> floor( "2.3" )
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in <module>
>> TypeError: must be real number, not str
>>>>> help(floor)
>> Help on built-in function floor in module math:
>>
>> floor(...)
>>      floor(x)
>>
>>      Return the floor of x as an Integral.
>>      This is the largest integer <= x.
>>
>>    Is the output of »help(floor)« supposed to be a kind of
>>    normative documentation, i.e., /the/ authoritative
>>    documentation of »floor«?
>>
>>    Is there any hint in the documentation about the type
>>    expected of arguments in a call?
>>
>>    Is a parameter name »x« (as used above) described
>>    somewhere to express the requirement of a real number?
>>
>>    It seems, »real« means »int or float«. Is this meaning
>>    of »real« documented somewhere?
>>
>>    Thanks in advance!
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>

-- 
Image and video hosting by TinyPic



More information about the Python-list mailing list