How to do safe cast in python
In c# I can safe cast by keyword as, e.g.:
string word=\"15\";
var x=word as int32// here I get 15
string word=\"fifte
There is something similar:
>>> word="15"
>>> x=int(word)
>>> x
15
>>> word="fifteen"
>>> x=int(word)
Traceback (most recent call last):
File "", line 1, in
ValueError: invalid literal for int() with base 10: 'fifteen'
>>> try:
... x=int(word)
... except ValueError:
... x=None
...
>>> x is None
True