Browse Source

Added python check to see if variable is defined

George Jones 1 year ago
parent
commit
38a66dde7d
1 changed files with 13 additions and 0 deletions
  1. 13 0
      home/public/snippits/python/is_defined.py

+ 13 - 0
home/public/snippits/python/is_defined.py

@@ -0,0 +1,13 @@
+del foo
+
+try:
+    print(f"Take 1: foo is defined, value {foo}")
+except NameError:
+    print("Take 1: foo isn't defined")
+    foo="foo"
+
+try:
+    print(f"Take 2: foo is defined, value {foo}")
+except NameError:
+    print("Take 2: foo isn't defined")
+    foo="foo"