eval_expr
eval_expr copied to clipboard
Invalid number format
I keep getting an "Invalid number format" exception on line 38 when calling either function. I have everything set up correctly, and it works on the Student Software, but not on my Nspire. I'm not sure what's going wrong.
Aww, the fact that it works on the computer software but not on the actual calculator is worrying :( Is TI somehow using different build options (feature-wise) for MicroPython...?
I’ll try to take a look soon, thanks for the report.
It works correctly when using the functions within the original document, just not in any other document. The same is true for using it on the computer software. So it does work on the calculator, but it looks like you need to use the original document.
Ah, ok, thanks for the details, that’s helpful. For now I guess users will have to copy/paste the python snippet in their own documents.
Having similar issue here
Ok thanks, I'll check what's going on with my own calc now updated to OS 5.3
I tried it on the latest OS version and the error is still present.
It works correctly when using the functions within the original document, just not in any other document. The same is true for using it on the computer software. So it does work on the calculator, but it looks like you need to use the original document.
Like I also noted earlier, this is still the case. It works if you copy the source code into your Python document, just not if you import the module.
Alright, so I've been digging into this a bit, let me explain what's going on:
In order to evaluate an expression, I store then recall the expression (which gets evaluated) on the math engine's side via call ti_system's writeST/readST.
The problem is that when reading back the value, anything with a / will error with "TypeError: Invalid number format".
To prevent that, the script made the evaluated expression replace / by a magic token, on the Basic/math-engine side, then replaced back to a / on the Python side. However evaluating a Basic function (even if defined as LibPub) seems broken from the ti_system helpers if it's not in the same doc :(
So right now, I'm not sure what to do to make it easy for users.
I just developed a fix to both issues:
I created a forked version named xpy which you can see here.
It works when you import the Python module in separate documents, and it solves the "Invalid number format" error.
This was the fix:
def eval_expr2(name):
return _cleanstr(readST("string("+name+")"))
It looks like you just removed the replacements, which was in fact the very first version I had.
Are you sure you version handles the division character in the output? For instance (x+x)/y should give 2*x/y.
I see what you mean. Neither version works with the division character in the string output. It still works with other output and in separate documents, though.
However, I'm not sure what to do regarding the division character, as you pointed out.
Yes, that's the root of all the other issues :(