in Education by
Is there a way to get functionality similar to mkdir -p on the shell from within Python. I am looking for a solution other than a system call. I am sure the code is less than 20 lines, and I am wondering if someone has already written it? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Other alternate way of writing mkdir -p is by using pathlib.path() function which is as follows:- import pathlib pathlib.Path("/tmp/path/to/desired/directory").mkdir(parents=True, exist_ok=True) The third parameter exist_ok was added in Python 3.5.

Related questions

0 votes
    I looked into the Python os interface, but was unable to locate a method to move a file. How ... mv source_files destination_folder Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    Is this the cleanest way to write a list to a file, since writelines() doesn't insert newline characters? file. ... be a standard way. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    What is the best way to open a file as reading/write if it exists, or if it does not, then create it and ... to do the opening part. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I want to change a couple of files at one time, iff I can write to all of them. I'm wondering if I ... to this problem look like? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Can someone tell me how to find all the files in directory with .txt extension in Python? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I am getting an 'access is denied' error when I attempt to delete a folder that is not empty. I used the ... that is not empty? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I am writing a Python script in Windows. I want to do something based on the file size. For example, if the ... I check the file size? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    How to copy a file in python? I already read this but found nothing. Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    Anyone know any special function that appends to the file instead of overwriting it? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Can someone tell me any methods to read every line of a file in Python and store each line as an element in a ... till the end of list. Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Say I'm in a Git repository. I delete a file and commit that change. I continue working and make some ... my original project checkout. Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I'm following @zdim's recursive solution in this question fastest way to sum the file sizes by owner in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    We currently use multiple web servers accessing one MySQL server and fileserver. Looking at moving to the cloud, ... another solution? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: asynchronous python itertools chain multiple generators (2 answers) Closed 2 ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I've always laughed to myself when I've looked back at my VB6 days and thought, "What modern language doesn't ... ++/-- notation? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
...