Reputation: 1588
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?
Upvotes: 4
Views: 6235
Reputation: 31
You should ensure that TEST is initialized.
TEST = 'TEST'
if 'TEST' not in globals():
TEST = "test"
print(TEST)
Upvotes: 0