#πŸ”’ Currency Exchange value error

34 messages Β· Page 1 of 1 (latest)

timid wing
paper zincBOT
#

@timid wing

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

timid wing
valid frigate
#

could you send a copy of the error that you're getting?

timid wing
#

im not getting an error because i have an except block

#

i can't tell if the error is in my code or vs itself

storm lance
#

Comment it out and send what you get

unkempt hill
#

Have u try and re did the code

timid wing
#

well

#

uh

#

the same thing

#

i guess the problem isnt in float(val)

valid frigate
#

do you have a traceback now?

timid wing
#

its at all_symblos = f.read()

#

wait its a UnicodeDecodeError?

#

oh yeah why is the encoding cp1252

#

alr i put the encoding as utf-8

#

and it works 😭

#

ig that was the issue

#

thank you

valid frigate
#

yeah, UnicodeDecodeError is a subtype of ValueError, so catching ValueError suppresses it

#

generally you want your try/except blocks to cover the minimum amount of code that they need to in order to avoid this kind of thing

timid wing
#

what can i use instead of value error?

#

in get_amount_currency

#

if the user inputs a string instead of a numebr

valid frigate
#

catching ValueError is correct if you want to report that the user inputted an invalid float, but the try/except should only cover the line where you expect an error to be raised

#

in your case that would be line 57

timid wing
#

ah

#

yeah that makes sense

#

alright

#

!close

paper zincBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.