[Tutor] script question

Andrew P grouch at gmail.com
Wed Sep 28 17:13:07 CEST 2005

Have you benchmarked it yet? 4000 lines isn't very many, even for an older
machine. Starting the Python interpreter usually takes most of the time with
simple scripts like this. Honestly, benchmark :)

You might find it easier to do::

interface_list = INI.items(section)
for i in interface_list:
if i[1] == interface:
the items method just returns the whole section in a list of tuples, so
don't have to build it yourself.

One last you may also want to consider is lowercasing any input, because
last I checked ConfigParser lowercases what it parses whether you want it to
or not :)

So if somebody searches for NetworkDevice10, ConfigParser will return it as
networkdevice10, and you won't get a match. That certainly bit me a couple

Good luck.

On 9/28/05, Chris Hallman <challman at gmail.com> wrote:
> Thanks for all the input!!! I really appreciate it. I need to post a
> correction to my script. What I sent was an early version. I made a few
> minor modifications:
> import ConfigParser, string, sys, os
> section = sys.argv[1]
> interface = sys.argv[3]
> INI=ConfigParser.ConfigParser()
> INI.read("c:\utils\interfaces.ini")
> interface_entries=[p for p in INI.options(section)]
> interface_list=[INI.get(section, pw) for pw in interface_entries]
> for i in interface_list:
> 	if i == interface:
> 		os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet -n l17aesm1 forward red held " +
> sys.argv[1] + " " + sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])
> I've researched what you all have suggested and I may need to switch to
> reading the ini file line by line or using a different file parser. The ini
> file is only 100 lines long now, but will likely grow to 500 line and maybe
> to 4000 lines. To give you a better background of what I'm doing with this
> script, it's running on a network management system that receives traps.
> After some processing of the raw trap, messages get sent to this script for
> further processing. These messages are for interface down traps from routers
> and switches in our network. I use this script to mitigate the number of
> interface down messages on our console. I need to do this because we do not
> need to know when every port has gone down (i.e. user ports). This script
> searches the ini file for a device name match. Once it has found a match and
> if the interface matches as well, I need to message forwarded to the console
> (the Windows command). If no matching device or interface is found, then the
> script can just exit. - Show quoted text -
> On 9/26/05, Kent Johnson <kent37 at tds.net> wrote:
> >
> > Kent Johnson wrote:
> > > *TEST FIRST* Don't optimize until you know it is too slow and you
> > > have a test case that you can time to see if your 'optimizations' are
> > > making it faster.
> >
> > Pardon my shouting :-)
> >
> > Kent
> >
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050928/6bfafe0a/attachment.html

More information about the Tutor mailing list