[Tutor] did I lose the value of record?

Karl Pflästerer sigurd at 12move.de
Tue Mar 2 12:04:44 EST 2004


On  2 Mar 2004, Eric L. Howard <- elh at outreachnetworks.com wrote:

> I have a file that contains two columns delimited by ":".

> I can open the file for reading, re.search through the lines for a
> particular record and string.split the record into two parts which are
> assigned to two different variables.  It's the third assignment that's
> causing the script to fall over on it's face [the pwd.getpwnam]

> In the interpreter - this works:


>>>> record  = "elhtest:elh"
>>>> userhome = pwd.getpwnam(string.split(record, ":")[1])[5]
>>>> print userhome
> /home/elh

> However - this doesn't appear to work:

> #!/usr/bin/env python

> import re, string, pwd

> listingsfile = open("listings","r")
> for record in listingsfile.readlines():
>     if re.search("elhtest", record):
>         listing = string.split(record, ":")[0]
>         owner = string.split(record, ":")[1]

What is the value of owner here?

[...]

> I get the following:

> Traceback (most recent call last):
>   File "./sa_setup.py", line 10, in ?
>     ownerhome = pwd.getpwnam(string.split(record, ":")[1])[5]
> KeyError: 'getpwnam(): name not found'

That means it can't find the name in your passwd file.  Look at the
value of owner and look in your passwd file.


   Karl
-- 
Please do *not* send copies of replies to me.
I read the list




More information about the Tutor mailing list