[Tutor] Windows file structure

Liam Clarke cyresse at gmail.com
Sun Oct 31 03:26:00 CET 2004


Heh, I'm going to update my standard disclaimer to -


This is a quick and dirty way to do it, there's probably a simpler,
cleaner way to do it, which will be posted shortly by someone more
knowledgeable.

For secondslot in names[1:] means secondslot is a slice of names,
doesn't it? I get confused about slices sometimes.

On Sat, 30 Oct 2004 21:44:47 -0400, Kent Johnson
<kent_johnson at skillsoft.com> wrote:
> A few notes:
> 
> - Instead of
> for slot in range(len(folderlist)):
>          # do something with folderlist[slot]
> 
> it is better to write
> for names in folderlist:
>          # do something with names
> 
> - os.makedirs() will make all the directories needed to reach a path, so
> you don't have to make the intermediate paths.
> 
> - A more portable way to join paths is with os.path.join(); this will work
> on a wider variety of platforms that code that assumes that / is the separator.
> 
> So you could write your loop as
> for names in folderlist:
>             for secondslot in names[1:]:
>                   os.makedirs(os.path.join('..', names[0], secondslot))
> 
> Kent
> 
> 
> 
> At 01:46 PM 10/31/2004 +1300, Liam Clarke wrote:
> >folderlist=[["English", "data", "temporary", "main", "archive"],
> >                ["Español", "datos", "temporal", "principal", "archivo"],
> >                ["Italiano", "dati", "provvisorio", "principale", "archivio"]]
> >
> >And then a wee loop -
> >
> >for slot in range(len(folderlist)):
> >            os.mkdir("../%s" % folderlist[slot][0])
> >            for secondslot in range(1,len(folderlist[slot])):
> >                  os.mkdir("../%s/%s" % (folderlist[slot][0],
> >folderlist[slot][secondslot]))
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


More information about the Tutor mailing list