Object Not Callable, float?
W. eWatson
wolftracks at invalid.com
Sun Nov 29 23:14:15 EST 2009
Ben Finney wrote:
> "W. eWatson" <wolftracks at invalid.com> writes:
>
>> "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py",
>> line 467, in ShowHistogram
>> mean = sum(hist)
>> TypeError: 'float' object is not callable
>
> It means you're calling an object of type ‘float’. The line where it
> occurred shows that you're accessing that object through the name ‘sum’,
> which means you've bound the name ‘sum’ to a float object.
>
>> for the code:
>> ----------------------
>> sum = 0.0
>
> Here you clobber the existing binding of ‘sum’, binding it to the float
> value 0.0.
>
>> avg = 0.0
>> nplt_bins = 32
>> for i in range(len(hist)):
>> # msg = "%5d %6d\n" % (i,hist[i])
>> msg = "%5d %6d\n" % (i,hist[i])
>> sum = sum + hist[i]
>
> Here you keep re-binding the name ‘sum’ to new float objects of
> different value.
>
>> text.insert( END, msg )
>> for i in range(len(hist)):
>> avg = avg + (i*hist[i]/sum)
>>
>> mean = sum(hist) <-------------- faulty line
>
> Here you try to call the object referenced by the name ‘sum’, which is a
> float object.
>
>> hist is a list of 256 integers. What does float have to do with this?
>
> You explicitly bound the name ‘sum’ to an object of type ‘float’.
>
> Solution: Choose names wisely, and if you want to use a built-in name
> like ‘sum’ for its built-in putpose, don't clobber that binding before
> using it.
>
Yikes. Thanks very much. Python seems to act unlike other language in
which words like float are reserved. I'll use asum.
More information about the Python-list
mailing list