I wrote a python code to give a value to a variable if it is not defined, but nevertheless PyCharm warns me that the variable can be not defined:
if 'TEST' not in globals():
TEST = "test"
print(TEST)
Name 'TEST' can be not defined
Is there an other way to define undefined variables such that PyCharm understand it?
You can use a nonconditional initializer, e.g. with get, to get rid of the warning:
TEST = globals().get('TEST', 'test')
print(TEST)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With