[Tutor] useful function or reinventing the wheel??
Mark Lybrand
mlybrand at gmail.com
Tue Nov 29 05:30:13 CET 2011
I am a habitual wheel re-inventor, so it would not surprise me, but I made
this little function that I was kinda proud of (seeing that I have only
been learning python like a week now):
It just takes a directory and checks to see if all the directories,
sub-directories exist and creates them if they don't:
def insure_exists_dir(dir):
grow_path = [dir]
while not os.path.ismount(grow_path[0]):
part_tuple = os.path.split(grow_path[0])
grow_path.insert(0, part_tuple[0])
del(grow_path[0])
while grow_path:
if not os.path.exists(grow_path[0]):
os.mkdir(grow_path[0])
del(grow_path[0])
return(dir)
Opinions? What should I really be using?
--
Mark :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111128/d58b9e61/attachment.html>
More information about the Tutor
mailing list