How to use standard Python libs


https://forum.reallusion.com/Topic399269.aspx
Print Topic | Close Window

By RobertoColombo - 6 Years Ago
Hi,

the following code generates an error at the line where isdigit() is used.
isdigit() is part of standard Python libs, so I wonder how to get it working.

import RLPy

def run_script():
    val = 100
    
    if val.isdigit():
        print("it is a digit")
    else:
        print("it is not a digit")

Thanks

  Roberto

By Kelleytoons - 6 Years Ago
Actually, isdigit() refers to a string.

This works in iClone Python:
str = "1234"
print(str.isdigit())

returns true.
By RobertoColombo - 6 Years Ago
Hi Mike,

oh... that's right.
So, I need to check how to use for a function input parameter (that's the diea: to check whether it is a number)...

  Roberto
By Kelleytoons - 6 Years Ago
Well, it has to be *something* to begin with -- either it's a number, or it's a string that may or may not contain numbers.

If it's a string and you're not sure if it's all digits, you can use that function (so "A103" would return false).  

And if you're not sure what type it is, use the function type().
By RobertoColombo - 6 Years Ago
Ok, my point is to check function parameters for type consistency.
I am an old C programmer and I learnt to use strict conventions... that's why Python for me is just too loose...
By Kelleytoons - 6 Years Ago
Yeah, Python won't do that.  

Here's some explanation of this process: https://stackoverflow.com/questions/402504/how-to-determine-a-python-variables-type
By justaviking - 6 Years Ago
@Roberto and Mike,

It's fun and fascination watching the two of you work together.  I'm sorry you need to do all this reverse engineering and forensic discovery to figure out how it should work, and never knowing for sure if it's a bug, a documentation error, or user error.

On behalf of all the people who will benefit from your pioneering efforts, "Thank you!"
By RobertoColombo - 6 Years Ago
Yeah...

Mike has promised to invite me in Florida if I can help him... right Mike ? Wink
By Kelleytoons - 6 Years Ago
You and Dennis are always welcome here (we don't have a ton of guest room, but I'm sure we can work something out).
By RobertoColombo - 6 Years Ago
Could be more than just an idea... Smile

By Kelleytoons - 6 Years Ago
And I'm serious about it (I'm a pretty great host :>Wink.