Re: [Tutor] Parsing /etc/passwd

2011-10-12 Thread Peter Otten
Hugo Arts wrote: >> f = open('/etc/passwd', 'r') > users = f.readlines() > for user in users: ... You can iterate over the file directly: for user in f: ... The version using readlines() reads the whole file into a list of lines where the alternative just has to remember the current

Re: [Tutor] Parsing /etc/passwd

2011-10-12 Thread Gerhardus Geldenhuis
Fantastic, Thanks Hugo that makes 100% sense now! Testing both regex for including / and doing split and when done throwing both away and using the default module. Regards On Wed, Oct 12, 2011 at 2:49 PM, Hugo Arts wrote: > On Wed, Oct 12, 2011 at 3:41 PM, Gerhardus Geldenhuis > wrote: > > Hi

Re: [Tutor] Parsing /etc/passwd

2011-10-12 Thread Hugo Arts
On Wed, Oct 12, 2011 at 3:41 PM, Gerhardus Geldenhuis wrote: > Hi > I wrote the following code: >   f = open('/etc/passwd', 'r') >   users = f.read() >   userelements = re.findall(r'(\w+):(\w+):(\w+):(\w+):(\w+):(\w+):(\w+)', > users) >   print userelements >   for user in userelements: >     (use

[Tutor] Parsing /etc/passwd

2011-10-12 Thread Gerhardus Geldenhuis
Hi I wrote the following code: f = open('/etc/passwd', 'r') users = f.read() userelements = re.findall(r'(\w+):(\w+):(\w+):(\w+):(\w+):(\w+):(\w+)', users) print userelements for user in userelements: (username, encrypwd, uid, gid, gecos, homedir, usershell) = user # unpack the tupl