Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
my latest function
#1
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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.
Reply
#3
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to install the latest version of Python on RHEL 8? devlocalca 7 5,315 Feb-17-2020, 01:49 AM
Last Post: snippsat
  Any command to upgrade Python version 2.X to latest KarthiK 7 4,045 Feb-15-2020, 07:25 PM
Last Post: DeaD_EyE
  Latest news on Tim Berners-Lee's Inrupt Larz60+ 2 2,507 Mar-07-2019, 11:35 PM
Last Post: Larz60+
  latest astroid dependencies break mypy astir13 2 2,360 Feb-28-2019, 02:14 PM
Last Post: astir13

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020