-1

I am opening a file in my python code. For a particular user, the path is /home/user_name/IB/MAIN where user_name is the personal user name. For testing and stuff I have used my own user name but if I give this code to someone else, it won't run as the path is different for that user, so how do I get a generic path for this file?

  • you will find your answer [here](https://stackoverflow.com/questions/4028904/how-to-get-the-home-directory-in-python) or [here](https://stackoverflow.com/questions/2668909/how-to-find-the-real-user-home-directory-using-python) – Advay Umare Feb 05 '18 at 05:17

1 Answers1

0

Use

'~/IB/MAIN'

to denote relative path to user home.

or

import os
homepath = os.getenv("HOME")
path = os.path.join(homepath, "IB/MAIN")

via environment variable

John R
  • 1,505
  • 10
  • 18