-1

I am analyzing some old code in python and found this somewhere

from tools import bool_dir

I tried searching it but could not find anything. All I know is that maybe it is deprecated now and weblib is used instead of it. Can anyone please tell me the usage of this bool_dir.

minhaj
  • 78
  • 9
  • 1
    Your question is severely lacking in context and/or relevant tags. – ekhumoro Feb 25 '18 at 17:58
  • Sorry, I was just examining some old python code and didn't understood much of it and was just stuck at this part. I am still a beginner. – minhaj Feb 25 '18 at 18:44

1 Answers1

1

I found some likely code that matches your description.

The implementation from that is:

def bool_dir(path):
    """
    Check if directories exist else it create all the dirs

    """
    if not os.path.exists(path):
        os.makedirs(path)
    return path

Note that this has a race condition so I'd suggest against using it.

If you're using python3 you can use:

os.makedirs(path, exist_ok=True)

for a race-free version.

For more information on the subject, check out this SO answer.

Anthony Sottile
  • 40,161
  • 9
  • 79
  • 122