isset() php function equivalent in python


simple-diagram-tree-125x125

If you need this, you’re probably doing it wrong. But if you really must check to see if a variable has been assigned yet, there’s nothing really stopping you. Here’s one way of implementing it.

Just wrap what you’re doing in a short try/except clause. Simple. Now you can tell if “variable” is defined without dying in a fire.

Too bad you can’t wrap this in a function definition. Well, you can – sort of. If you make this a function, it will work as long as the variable you give it is already defined. If not, you’ll still get a NameError. If you wrap the function call in try/except, it will work! I guess if you’re trying really hard to fail and you need isset() several times in your code, at least it will look nice.

Disclaimer: writing in one language while thinking in another is probably a bad idea…


Posted on June 20th, by admica in fail, programming.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">