I am developing an API in Unix environment for virtual machines. Most of the modules are developed in python. I have few questions on this.Inside the API I am using absolute path like '/root/virtman/manager/' . Consider running this API in any unix environment , how can I make this absolute path generic to any OS/machine. Or should I have to assume some location where the API will get installed and give that path everywhere?I read a lot of articles but I didn't get the clear picture,so any hints/suggestions would be helpful.
Maintain the path in installable UnixAPI
command line;python;path
If the path is only pointing to executables you call, you should consider putting links in standard locations during install (/usr/bin/ or /usr/local/bin) and have the executable find out where they were invoked from and then have them derive the path to any data files from that.You would use the following:/usr/bin/myprog    /opt/myprog/bin/myprog/opt/myprog/data/picture_01.imghave /usr/bin/myprog be a link to /opt/myprog/bin/myprog and /opt/myprog/bin/ should not be in your $PATH. Setup the link by doing sudo ln -s /opt/myprog/bin/myprog /usr/bin, and have in /opt/myprog/bin/myprog do:import sysimport osbase_dir = os.path.realpath(sys.argv[0]).rsplit('/bin/', 1)[0]To determine /opt/myprog dynamically at run-timeIf the python API is based on some included module, make sure that module gets installed in the PYTHONPATH search path of a systems python, then you can just do import yourapimodule in a python executable and use it. If these are data files that can be installed anywhere, consider having a configuration file that you read and that could be ~/.config/yourapimodule/config.ini, ~/.yourapimodule/config.ini or ~/.yourapimodule.ini. (Instead of .ini you could use other formats like .json, whatever you prefer). Shameless plug: If you are using Python's argparse to handle commandline arguments, then have a look at the package ruamel.appconfig, that I wrote, it sets up the config for you and allows you to specify defaults in the config file for commandline parsing.