Python Forum

Full Version: my latest function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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.
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.