Home > Net >  ValueError: invalid literal for int() with base 10: '' from Python 2.X to 3.X
ValueError: invalid literal for int() with base 10: '' from Python 2.X to 3.X

Time:09-30

I'm trying to work on a project and I have a code but it's written in python 2.X I'm currently working on Python 3.X and when i try to

X= abs(int(f'fractionfactor:e'.split('e')[-1]))

in Python 2.X the result of .split will send back just the decimal part for exemple int(str(5/2)) will give me in return "2" but in python 3.X i'll get "2.5" for the same code here is the full part i'm currently stuck in

def format_value(valuetoformatx, fractionfactorx):
    value= valuetoformatx
    fractionfactor= fractionfactorx
    Precision= abs(int(f'fractionfactor:e'.split('e')[-1]))
    FormattedValue= float(':0.0{}f'.format(value,Precision))
    return FormattedValue

def parPriceinfo(ticker,client):
    info= client.get_symbol_info(ticker)
    minPrice= pd.to_numeric(info['filters'][0]["minPrice"])
    return minPrice

def pairQtyinfo(ticker,client):
    info= client.get_symbol_info(ticker)
    minQty= pd.to_numeric(info['filters'][2]['minQty'])
    return minQty

error:

invalid literal for int() with base 10: ''

I hope that i've provided enough information. thanks in advance !

CodePudding user response:

In an f-string, you need to put {} around the variable to format and the format expression.

Precision= abs(int(f'fractionfactor:e'.split('e')[-1]))

should be

Precision= abs(int(f'{fractionfactor:e}'.split('e')[-1]))
  • Related