Is any easy way to quickly initialize path format to list variables in python Such as:
dir = "/root/path/file"
to
p[0] = "root"
p[1] = "path"
p[3] = "file"
Is any easy way to quickly initialize path format to list variables in python Such as:
dir = "/root/path/file"
to
p[0] = "root"
p[1] = "path"
p[3] = "file"
You can try like this,
>>> dir="/root/path/file"
>>> p = filter(lambda x: x != '', dir.split('/'))
>>> print(p)
['root', 'path', 'file']