[Tutor] Windows file structure
Kent Johnson
kent_johnson at skillsoft.com
Sun Oct 31 02:44:47 CET 2004
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]))
More information about the Tutor
mailing list