[Tutor] useful function or reinventing the wheel??

Mark Lybrand mlybrand at gmail.com
Tue Nov 29 09:37:40 CET 2011


>
>
> You're welcome.  I'd look forward to seeing your rewrite, and whether it's
> really shorter and more straightforward.
>
> Another advantage is doing less disk I/O if you start by trying the
> requested directory directly, and only recursing to parents if you can't
> make the requested directory.
>
> I took a quick stab at it  (ask me later for mark.py)  and it wasn't as
> straightforward as I expected.  The main problem comes down to how to
> define the base case.  I think you might have the same problem also. You
> assume that you can safely go back to the mount point.  But if the path
> given is relative, you have to allow for that as well. Perhaps a call to
> os.path.abspath is in order.  I also think that ismount() might not be
> legal on Windows, if you care about that.
>
> Also, we have to worry about what happens when one of the directories
> cannot be made for reasons unrelated to the syntax of the string.  For
> example, the user might not have write permissions for one or more of the
> directories.  In fact, the user might not have read permissions either.
>
>
I am actually passing in the path already os.path.abspath-ed.  So, I should
probably move that into the function for better encapsulation.  I am on
Windows, so ismount is behaving correctly (I tested it in Idle before going
with that as my base case).  Since this will end up being a throw-away, I
will probably not worry too much about permissions and failures, but I can
appreciate the need for such checks, should I decide to keep this for more
widespread use.

Thanks again.  I will send my solution when I get a chance to get back to
it (gotta get myself ahead in machine learning before the weekend gets too
close :)

Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111129/991cc3a9/attachment.html>


More information about the Tutor mailing list