You are not logged in.
Pages: 1
import easygui, sys, telnetlib, time
while True:
vpc = easygui.enterbox(message='Enter VCI.', title='Enter VCI', argDefaultText='')
if vpc == 'None':
sys.exit()
if vpc[0] in ('1', '2'):
vpc = vpc[0] + '01' + vpc[2:]
HOST = "0.0.0.0"
password = "password"
tn = telnetlib.Telnet(HOST)
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("sh int atm6/0." + str(vpc) + "\n")
tn.write("sh arp | in " + str(vpc) + "\n")
tn.write("exit\n")
outstring = tn.read_all()
#print tn.read_all()
#time.sleep(10)
#sys.exit(0)
easygui.codebox(message='Results' , title='VCI Results', text=outstring)
else:
#print "Wrong Server ( 3/ VPI ) or invalid VCI"
easygui.textbox(message='Error', title='ERROR', text='Wrong Server ( 3/ VPI ) or invalid VCI', codebox=0)
time.sleep(1)
-- that works fine for me, except it loads a windows command prompt in the background, that closes when the program closes, is there any way to stop this from happening?
Last edited by axion419 (2008-04-15 14:58:49)
Offline
Equality is with '=='.
I don't think your code is valid as you're using assignment ('=') in your if, which other languages let you do, but I'm sure Python doesn't (I've rarely tried as I always thinks it's an example of conciseness over readability).
More readable ways to check the start of a string include: mystring.startswith('1')
And remember when testing multiple truths in a single statement, you need to be a little more verbose. Assuming that you had converted your string to an int first:
elif int(vpc[:1]) > 3 or int(vpc[:1]) < 0:
and so on. Of course, it could be written as if number is not 0-3
elif vpc[:1] not in [0,1,2,3]
or elif vpc[:1] not in range(4)
etc
Offline
changed the thread title and the orig question.
Offline
Pages: 1