[Tutor] useful function or reinventing the wheel??
Emile van Sebille
emile at fenx.com
Tue Nov 29 17:32:18 CET 2011
On 11/28/2011 8:30 PM Mark Lybrand said...
> I am a habitual wheel re-inventor,
For anyone who hasn't yet discovered effbot's guide to the python
library, it's a good place to start as you expand your python skills.
see http://effbot.org/librarybook and in particular for your current
question, you'll find makedirs with sample code at
http://effbot.org/media/downloads/librarybook-core-modules.pdf
Although dated, it's still a great place to start as most internal
functions have changed little over the years.
Emile
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 :)
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list