[Tutor] passing a variable ?

dpotter at nc.rr.com dpotter at nc.rr.com
Thu Oct 19 15:21:51 CEST 2006


I am stumped.  I am trying to pass the variable 'savename' to a string
and get errors.  
can someone tell me why?  Thanks to all on this list.  (The problem
happens in the for loop 1st line)

This is my error
Traceback (most recent call last):
  File "./ArpAcl.py", line 39, in ?
    fout = file('/home/cable/sandbox/%s', 'a''w' % savename)
TypeError: not all arguments converted during string formatting

----------------------------------------------------------------------------

import pexpect
import getpass
import sys

#Go through all the routers and gather Access-list or ARP information,
return the info into it's own file.
print '\n'
print 'Router scrub will take approx 60 Seconds.'
print '\n'
print "For the ARP list enter '1'"
print "For the ACL list enter '2'"
print '\n'

choice = input('Enter 1 or 2: ')
print '\n'
telpass = getpass.getpass('Please enter the telnet password: ')
enablepass = getpass.getpass('Please enter the enable password: ')

if choice == 1:
        command = 'show arp'
        savename = 'arp.txt'
else:
        command = 'sh ip access-l'
        savename = 'acl.txt'

print '\n'
print '-' * 48
print 'You will be notified when program is finished.'
print '-' * 48

x = open('/home/cable/router.list','r')
routers = x.readlines()

for i in routers:
        fout = file('/home/cable/sandbox/%s', 'a''w' % savename)
        c = pexpect.spawn('/usr/bin/telnet %s' %i)
        c.expect('Please Enter Password:')
        c.sendline(telpass +'\r')
        c.sendline('enable\r')
        c.expect('Password:')
        c.sendline(enablepass + '\r')
        c.expect('#')
        c.logfile = fout
        c.sendline('skip\r')
        c.expect('#')
        c.sendline(command + '\r')
        c.expect('#')
        fout.close()
        c.close()
x.close()
print '\n'
print 'Finished!'
print '\n'
print 'File has been save to /home/cable/sandbox/%s' % savename
raw_input('Press any key to exit....')



More information about the Tutor mailing list