On 27/04/13 08:57, Rajlaxmi Swain wrote:
How can I fix this.

Don't call float(foo) when foo is not a string or number.


To debug this, you need to follow these steps:

1) Look at the error message. It will tell you the line number that fails.

2) Look at that line of code. What are you calling float() on?

3) What type of object is it? If you don't know, put a line just before the 
call to float and print the object and its type. E.g.:

    print(type(foo), foo)
    result = float(foo)


4) Think hard about why you are calling float() on something that is not a 
string or a number. This is the bug, you now just have to understand it. Is it 
a typo? Are you using the wrong variable? Maybe you haven't initialised it to a 
good value? Or there is a path through your code where the wrong value is used?

5) Write code to fix the bug.



Notice writing code is the *least* important part of debugging. First you 
investigate what causes the bug; then you think about how it happens; then and 
only then do you write code.


Also notice that *we cannot do any of this for you*. You don't show us the full error, or 
the code, or give us any context. There is no magic wand we can wave and say "do 
this and the bug will go away".


--
Steven
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to