How can I safely create a nested directory?

What is the most elegant way to check if the directory a file is going to be written to exists, and if not, create the directory using Python? Here is what I tried: import os file_path = “/my/directory/filename.txt” directory = os.path.dirname(file_path) try: os.stat(directory) except: os.mkdir(directory) f = file(filename) Somehow, I missed os.path.exists (thanks kanja, Blair, … Read more

How to structure a plugin

This isn’t a question about how to build a WordPress plugin. Rather, what, if any, guides could be applied to how to put together the file architecture of any plugin. Some other programming languages or libraries have very controlled ways of organizing directories and files. Sometimes this is annoying and highlights the freedom that PHP … Read more