Created
January 6, 2021 09:59
-
-
Save mberz/41c7a86ee08a93cc9e2be9af0a8470e3 to your computer and use it in GitHub Desktop.
Create directories if they do not exist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dir_name = 'my_dir' | |
| try: | |
| os.makedirs(dir_name) | |
| except OSError: | |
| if os.path.exists(dir_name): | |
| pass | |
| else: | |
| # Raise the exception on everything other than OSError | |
| raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment