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
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
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
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