Fix Python – Checking if a string can be converted to float in Python

I’ve got some Python code that runs through a list of strings and converts them to integers or floating point numbers if possible. Doing this for integers is pretty easy
if element.isdigit():
newelement = int(element)

Floating point numbers are more difficult. Right now I’m using partition(‘.’) to split the string and checking to make sure tha….

Fix Python – Convert string to Enum in Python

What’s the correct way to convert a string to a corresponding instance of an Enum subclass? Seems like getattr(YourEnumType, str) does the job, but I’m not sure if it’s safe enough.
As an example, suppose I have an enum like
class BuildType(Enum):
debug = 200
release = 400

Given the string ‘debug’, how can I get BuildType.debug as a resul….