0

I am passing a floating exponent value to a python function and later using it:

def estimateFit(infile, fsrmin):
    test=isfloat(fsrmin)
    print "fsrmin test for isfloat: %s" %test
    flimit = 30e9;
    print "flimit = %.3e" %flimit
    float(fsrmin)
    print "fsrmin = %.3e" %fsrmin

I am calling this function from another python program as:

     fsrmin = sys.argv[3]
R, I, w = srf.estimateFit(infile,fsrmin)

I am always getting this error:

>     print "fsrmin = %.3e" %fsrmin 
TypeError: float argument required, not str

As you can see I tried to convert to float in the program. Anything I am missing

1
  • I am doing it inside the final function estimateFit.. line 6 Commented Feb 7, 2018 at 14:50

1 Answer 1

1

you do not assign fsrmin to float(fsrmin). i suggest you use:

fsrmin = sys.argv[3]    # fsrmin is a str for now
fsrmin = float(fsrmin)  # here we convert to float
R, I, w = srf.estimateFit(infile,fsrmin)

the statement float(fsrmin) does not change the variable fsrmin. it will raise a ValueError if the string fsrmin can not be interpreted as float.

Sign up to request clarification or add additional context in comments.

2 Comments

But I am already doing this before the print, but still getting the error
Oh, sorry I misunderstood the first time. I will try it and confirm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.