[Tutor] script question
Kent Johnson
kent37 at tds.net
Mon Sep 26 14:13:38 CEST 2005
Chris Hallman wrote:
> The script is executed in this
> manner:
>
> python search_interface.py device interface interface_name "is down -
> 00:00:00 01/01/06"
>
> Here is the script:
>
> import ConfigParser, string, sys
> section = sys.argv[1]
> port = sys.argv[3]
> INI=ConfigParser.ConfigParser()
Generally all caps names are used for constants, it would be more idiomatic to use ini.
> INI.read("interfaces.ini")
> passwordentries=[p for p in INI.options(section)]
This could just be
passwordentries = INI.options(section), which is already a list. But even better, see below...
> passwordlist=[INI.get(section, pw) for pw in passwordentries]
The above two lines can be replaced with
passwordlist = [value for name, value in INI.items(section)]
which just accesses the section once.
Kent
> print passwordlist
> for i in passwordlist:
> if i == port:
> os.system("d:\\tnd\\bin\\cawto.exe -cat NetNet " + sys.argv[1] +
> " " + sys.argv[2] + " " + sys.argv[3] + " " + sys.argv[4])
>
>
> I'd like to know if there is a more efficient way to do this and if
> there is a way to have these functions performed with the least amount
> of time possible (the ini file could grow quite large).
>
>
>
> Thanks!!
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list