Rakozay Rakozay - 1 year ago 103
Python Question

Ignoring statement names inside parameters

When creating a function in PyCharm an error occurred as I tried to use a statement (in my case the try statement) as a parameter.

I also do get an error at second line due to Python tries to resolve the try as well.

def currency_converter_to_dkk(try):
amount = float(try * 2.25)

def currency_converter_to_try(dkk):
amount = float(DKK * 0.4436)

and since the PEP8 name conventions I 'cannot' change the parameter to uppercase.

Is there any way to circumvent this issue?

Answer Source

try is a keyword in Python used in the try statement. You cannot use keywords as a name.

You need to use another name.

def currency_converter_to_dkk(try_):
    amount = float(try_ * 2.25)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download