[Tutor] turn a path into nested list

ingo ingoogni at gmail.com
Thu Jan 13 14:19:35 CET 2011


On Thu, Jan 13, 2011 at 1:51 PM, Christian Witts <cwitts at compuscan.co.za> wrote:
> First split your path into segments, then iterate over those segments and
> build your new list (item one being the current segment, and part two a
> joined string of previous segments).
>

thanks Christian,

path = 'Audio/site-packages/pygame/examples/macosx/aliens_app_example/English.lproj'
path=urllib.url2pathname(path)
print '\n',path

pathlist=[]
dir=''
for item in path.split("\\"):
    dir=os.path.join(dir,item)
    a=[item,dir]
    pathlist.append(a)

print pathlist


More information about the Tutor mailing list