I'm using telnetlib
to communicate with some equipment which has Telnet implemented as single user.
Therefore, I have to detect and remove the telnet object created from a previous attempt to establish communication.(Ex: tn = telnetlib.Telnet(HOST)
)
My attempt is something like bellow but it does not work:
if 'tn' in loccals() or 'tn' in globals():
print "Telnet object exists. Remove it."
tn.close()
del tn
else:
print "Create a Telnet object."
global tn
tn = telnetlib.Telnet(HOST)
print tn