[Tutor] Problems ugh help please
Steven D'Aprano
steve at pearwood.info
Sun Oct 14 05:02:41 CEST 2012
On 14/10/12 07:17, Amanda Colley wrote:
> I am trying to add the total pounds that will be shipped. I keep getting an
> error of unknown format code 'f' for object of type 'str' when I try to
> float the pounds.
My guess is that here you are doing something like:
"weight is {:f}".format(weight)
but weight is a string, not a number. It's only a guess because you don't
show us the actual error you get, or the actual code you run. Luckily I
love guessing games!
Actually, I don't, I hate them. Please, we're volunteering our time to help
you for free. Make it easy for us to help you: always copy and paste the
complete traceback, starting with the line
Traceback (most recent call last):
all the way to the end.
>and when I dont float it it gives me a total weight of
> <function pounds at 0x00000000032B92CB> when it exicutes.
That tells me that instead of *calling* the function "pounds", you are just
giving it by name.
weight = pounds # makes "weight" another name for the function "pounds"
What you need is to call the function:
weight = pounds()
Note the round brackets (parentheses for Americans), which tells Python
to call the function.
--
Steven
More information about the Tutor
mailing list