Explorar el Código

Added python check to see if variable is defined

George Jones hace 1 año
padre
commit
38a66dde7d
Se han modificado 1 ficheros con 13 adiciones y 0 borrados
  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"