"Python String Emptiness Test"
=> What's the most self-explanatory and safest way of checking if a Python string is empty?
Not a simple question, unfortunately, and no universal answer.
@x_cli len(string_in_question) == 0?
@r000t @x_cli Only if it's actually a string :)
object of type 'NoneType' has no len()
@bcl @r000t A string, or any object that implements __len__That's my point on the third answer ;)https://www.broken-by-design.fr/posts/python-string-emptiness/#third
@x_cli @bcl Damn, never thought about someone passing an object that's straight up lying....
But testing for the string type solves a lot of that... maybe? Can you lie about that, too?
@r000tYou could subclass str 😅 But I guess this would be far-fetched. And you would be a str of sorts, so... 🙂@bcl
@r000t @x_cli It's a common problem in python. None is just so easy to use.
A Mastodon instance for info/cyber security-minded people.