Converting a String to a Boolean in Python
Today, while writing an AWS Lambda function, I needed to read a setting from an environment variable and convert it from a string to a boolean so I could use it in a condition. The obvious guesses are that Python will convert it automatically, or that bool("True") will do the job. But first of all, Python does not do automatic type conversion. This is important! It simply raises an error without any fuss. But surely you’d expect bool() to solve it, right?! In fact, this landmine cost me half an hour today… ...