Feedback
Got a suggestion for improvement? Anything goes.
Found a bug? Let us know. For other inquries feel free to contact us about anything at all.
Depvana •
about •
legal •
contact •
contribute •
Depvana is independent. Help keep it that way.
© 2024 Depvana aps.
Login to add a hashtag.
Hashtags
Tags
Bookmark Mark
Topic python essentials
Public room public room
Moderators •   sys
Depth •  Tech > programming > python essentials
Purpose • 
Essential python knowledge sharing.
View Subtopics: click above  
21
1
0
More
Copy link
Report
Visible to the public Public post
Attachments • images • webm video • max size 4096KB.
Attachments • images • webm video • max 4MB.
Filter by  •  Newest
Newest
Sort posts in decending order by date
Oldest
Sort posts in ascending order by date
sys@335 
More
Copy link
Report
Existence of variables!

To check the existence of a local variable:

if 'myVar' in locals():
  # myVar exists.

To check the existence of a global variable:

if 'myVar' in globals():
  # myVar exists.

To check if an object has an attribute:

if hasattr(obj, 'attr_name'):
  # obj.attr_name exists.