I need to check, whether variable is defined or not. If it is not, then this variable should be created as empty string.
I want to do it by try
and it works fine:
try:
ident
except:
ident = ''
But I need to do that using a function, coz I will do that many, many times and it will became unreadable.
Doing it like below can't work, coz it will not go into the function, if ident
does not exist.
def absence_of_tag(ident):
try:
ident
except:
return ''
I was also trying to do it with *args
, like that:
def absence_of_tag(*args):
try:
args
except:
return ''
and then call it by:
ident = absence_of_tag(ident)
I thought, it will go into the except
in function, but still it gave me NameError: name 'ident' is not defined
Do you have any idea how to do that? Is it even possible?