setting path in a python module for distribution

281 views Asked by At

I have module that I am writing in python that needs to download data and store it in a particular directory. Currently, I am doing this by in the manner shown below,

import os
folder = 'd:\data' #location of the root folder directory on my system
DATAPATH = os.path.join(folder, 'download_data')

This works for my module on my system. I am interested in distributing this module to other machines and I am not sure how I can control the location of the root folder when I install the module to a different machine. Are there any best practices on how to do this? Is there some way to do this in the setup file?

2

There are 2 answers

0
msw On

Yes, it should be set by your installer and reside in a configuration file. Use module configparser to extract the value. Look at BasicInterpolation to see your need as an example.

0
Peter Brittain On

From the sounds of things, you need to install your package with a known structure, including some non-Python files, then need to get the location of those files by using their known relative path from your package modules. In which case, you need to combine these two answers

Including non-Python files with setup.py

Retrieving python module path

And then use your existing logic to construct your full path