Thread: Python Error

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Python Error


    I got this error from python any assistance would be greatly appreciate it.

    print "YOU PAY: $",(float(pc)-total)
    ValueError: invalid literal for float(): 8over20
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    /dev/null
    Posts
    163
    Rep Power
    19
    Before you pass on variable 'pc' to the float function, may be, it would be a good idea to know what 'pc' refers to. Try putting a print statement before you use it in float and see if 'pc' really refers to a valid float.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    pc seems to have been the literal
    8over20

    Often times printing a value is insufficient. You need the type as well. When debugging go straight for the throat,
    Code:
    def dbg(arg,title=''):
        print(title,'type:',type(arg),'    ','str',str(arg))
        return arg
    
    #...
    
    print "YOU PAY: $",(float(dbg(pc,'trouble with pc!'))-total)
    Gosh I wonder why I never before this wrote dbg in python. Of course in J (www.jsoftware.com) dbg without the title is the hook

    dbg =: [smoutput
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo