> On Behalf Of Bruno Desthuilliers
> >> for line in open("/etc/passwd"):
> 
> NB : this idiom relies on the VM automatically closing files, 
> which is not garanteed on each and every implementation 
> (IIRC, jython won't do it). This is ok for Q&D throwaway 
> scripts targeting CPython, but should not go into production code.

You're right. For production, I'd probably do this.

def create_user_dirs(lines):
    for line in lines:
        pass # process lines here

with open("/etc/passwd") as fp:
    create_user_dirs(fp)

This has the benefit of allowing me to test create_user_dirs without
touching the file system (by passing in a list of lines).

Regards,
Ryan Ginstrom

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to