Making dir's

Christoph Zwerschke cito at online.de
Sun Jan 22 18:38:44 EST 2006


yawgmoth7 wrote:
> os.mkdir("C")
> os.mkdir("Python")
> os.mkdir("ASM")
> 
> And so on. That is not very practical, and I wish to change it. I was
> wondering if there were any other methods to which I could do this, I
> was thinking maybe I could put the dir names in a dictionary then have
> something like:
> os.mkdir(thedictname)

For what do you need a dictionary? A list or a set should suffice:

[os.mkdir(d) for d in "C Python ASM".split()]

If some of these directories could already exist, this may be safer:

for d in "C Python ASM".split():
     try:
         os.mkdir(d)
     except OSError:
         pass

Another possibility is the following:

os.system("mkdir C Python ASM")

-- Chris



More information about the Python-list mailing list