What is the most efficient way to create a folder with permissions in python (vs. running bash/shell commands)?

I'm converting some bash/shell scripts to Python. I'd like to only create a directory/folder on a CentOS system if it doesn't exist already and then set 777 permissions on it.

I can easily do this with one command in bash:

mkdir -m 777 "/PATH/TO/DIRECTORY/GOES/HERE";

Right now i'm running this command as a subprocess in python, but I was wondering if there was a cleaner, faster, and/or more efficient way of doing it?

Any help or even hits will be appreciated! :)

Answers


You can set the permissions directly when using os.mkdir:

mkdir(...)
    mkdir(path [, mode=0777])

    Create a directory.

Need Your Help

How can I search a string for multiple characters?

python python-2.7

I am trying to extract info from a page with a lot of spaces in it, so pretty much I want to search for ANY letter and get its position, not just one letter. How can this be accomplished?

How to fan out an I/O bound task in Ruby?

ruby parallel-processing

I'm making a bunch of AWS calls to create/delete rules from security groups and want to speed things up with parallelization.