Follow

broken-by-design.fr/posts/pyth

"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.

@r000t That's only of one the possible answers :) Your proposal was my first answer. Then, I thought about the other ways :)

@r000t @x_cli Only if it's actually a string :)

object of type 'NoneType' has no len()

@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?

@r000t
You 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.

Sign in to participate in the conversation
Infosec Exchange

A Mastodon instance for info/cyber security-minded people.