I have been trying to make a code that returns the users decimal as a fraction but its not working. Not sure what I’m doing wrong
Code Sample:
def text_box_1_pressed_enter(self, **event_args):
"""This method is called when the user presses Enter in this text box"""
user_input=self.text_box_1.text
print(Fraction(user_input))
https://anvil.works/build#clone:PBW6H32RE3HUIEYL=KROPAIT6PT3R3A3532SPQS5O
When you’re posting for help with a problem, you should really post the error message you’re getting, and the code causing the error.
In your case, you’ve copied some fraction handling code from somewhere, and the error is happening inside that code (specifically with the regular expression handling).
You should verify that you can get that code to work without anything Anvil related involved, before trying to incorporate it into Anvil. Trying to copy existing Python code into the client-side in Anvil can cause problems because Skulpt (the engine that runs Python in the browser) doesn’t have a 1:1 match with standard Python.
The other thing you can try to narrow the problem down is to run the code in the server, which is standard Python.
When you try that you’ll find that the Fraction class doesn’t work. It has something to do with the regular expression handling. You can either try to debug that, or try to find another fraction implementation that does what you want.