How do I check if a variable exists?
tomtetlaw -1 Posting Pro
Recommended Answers
Jump to PostFirst of all python has no variables. Here's how to check if a name is defined in local namespace:
"name" in locals()
and global namespace:
"name" in globals()
Jump to PostVariables in Python are officially names/identifiers (keys in a dictionary) of object references. I still like to refer to them with the old fashioned name variables, this way other folks know what we are talking about.
All 5 Replies
AceofSpades19 51 Junior Poster in Training
tomtetlaw -1 Posting Pro
scru 909 Posting Virtuoso Featured Poster
tomtetlaw -1 Posting Pro
sneekula 969 Nearly a Posting Maven
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.