On Sun, 24 Apr 2005 23:40:22 +0200,
Thomas KÃllmann <[EMAIL PROTECTED]> wrote:

> Hi, everybody!
> I'm teaching myself Python, and I have no experience in programming
> apart from some years of shell scripting. So, please bear with me.

> These two funktions are part of an administrative script I've set
> myself as a first lesson, and, as you will see, they're practically
> the same, except for one variable. So I'd like to weld them together
> -- but I can't find out how to.

[ two very similar functions snipped ]


> I feel it should be possible to use something like

> def writeFile(ip,keyword):
>     ...

Absolutely.

> but how would I construct expressions like

>     netmaskLineNum = conf.index(netmaskLine)

> in that case (netmask being the keyword here)?

netmaskLineNum and addressLineNum are just names.  They may mean
something to you and to people who read your program, but they mean
nothing to Python.  So just use generic names:

    for line in conf:
        if regex.search( line )
            theLine = line
    theLineNum = conf.index( theLine )

    etc.

HTH,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>
Îâ à Îâ à c = 1
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to