-1

In the piece of code I have, there are many instances where I have the following line

'/home/myname/directory'

For example, I have the following lines of code

filepath = os.listdir('/home/myname/directory')

for content in filepath

   # do something

In the next part of the project, I have to share the code with some one else. I know this person runs openSUSE. If I want code to create that specific directory with the same path to the directory as mine, what do I need to include?

I know its going to involve the OS module but i am not sure which functions and methods to use.

4

1 Answer 1

2

Your code can check the existence of the directory and create it if not found:

if not os.path.exists("/home/myname/directory"):
    os.makedirs("/home/myname/directory")
    # do something
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.