newbie playing with glob

Steve Holden sholden at holdenweb.com
Fri Jan 18 10:20:00 EST 2002


"Jason Orendorff" <jason at jorendorff.com> wrote ...
> Steve Holden wrote:
> >    for file in glob.glob("/home/*/*"):
> >        open(file+"/.forward", "w")
>
> Do not run this code as root on your system!
> It will erase everybody's .forward file.
>
Well, he did say he wanted to *create* a .forward file ...

I suppose the Pythonic spelling of touch woud involve:

    for file in glob.glob("/home/*/*"):
        open(file+"/.forward", "a")

> The version with os.system might be what you want.
> But you probably also want to make sure that each
> user owns his/her .forward file; I don't think touch
> will do that automatically...

That's correct. When a file is being created it will be created with the
current process' uid, gid and umask applied. Hence my mention of the other
os functions. Touch will, of course, leave the ownerships and permissions
alone on the existing file, as should the Python equivalent quoted above.

regards
 Steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Python Web Programming: http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list