Where is the folder the following code is creating on different operating systems?
data_dir = os.path.join(os.path.dirname(__file__), 'data')
if not os.path.exists(data_dir):
import generate_data
os.mkdir(data_dir)
Is it /path/to/file/data?
os.path.dirnamegives you the directory its argument is in, andos.path.joinappends a file or directory to the given directory.os.pathprovides you with a platform-independent way to modify file and directory paths, making use of the appropriate types of slashes.So yes, this will create a ‘data’ directory (if it doesn’t already exist) within the same directory as the source file from which this code is run.