0
Good evening, create an excerpt from a script that performs the creation of a variable through exec(), however, how can I verify that the variable exists through a for in range?
# criando a variável: host5 = 'ativo'
number = 5
foo = f"host{number}"
exec(foo + " = 'ativo'")
# verificando se a variável existe
for e in range(10):
if f'host{e}' == 'ativo':
print('ok')
The variable check part is only to demonstrate + or - as expected. Thank you staff.
Well-remembered
dir()
. However, I believe the goal was also to test the value. It would be possible with thedir()
?– Paulo Marques
Fala @Paulo Marques , boa noite! I believe that with dir() you do not have this option. I answered by the statement that asks if the variable exists. Hug!
– lmonferrari