Python Forum
my latest function - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: my latest function (/thread-18959.html)



my latest function - Skaperen - Jun-08-2019

i just wrote a function and will be writing tests for it soon. i wrote it because i frequently need this. it mimics open() (by calling it at the end) but creates any needed parent directories along with support for a named parameter parentsmode= to set the creation mode for all the parents being created (existing ones are not changed). i call it opend(). it uses pathlib to work out the parents. do you think i wasted my time?

one thing i noticed with error messages and exception messages from pathlib is that messages like to reference the full original argument path that was passed as an argument. since i had to run my own loop to set the mode on each directory being created, i chose to add the parent directory path in my messages.


RE: my latest function - heiner55 - Jun-08-2019

So your open function is a combination
from python functions: open() and os.makedirs() ?

You should publish it here ?
Maybe I can use it also.


RE: my latest function - Skaperen - Jun-08-2019

almost! with those 2 functions you have to derive the parent if one is in the path. you can't succeed by making a directory where the file should be other than by removing it afterwards (but at least you have made the parent that way).

i do plan to publish it after i have tested it. i need to try it out on some symlinks with "/../" to see how well it behaves, for example. then i will need to have someone test it on Windows and Mac.