SHARE
TWEET

Untitled

a guest Jun 25th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # 1]
  2. # Get the absolute path to directory which contains the Python script you want to/are run(ning)
  3. # Note: Folder <==> Directory
  4. # E.g.: Absolute (abs) path to the directory (dir): C:\Users\John\ProjectXFolder\ProjectXSubFolder
  5. # E.g.: Absolute (abs) path to the Python script: C:\Users\John\ProjectXFolder\ProjectXSubFolder\get_data.py
  6.  
  7. # get_data.py
  8. import os
  9. script_path = os.path.dirname(os.path.abspath(__file__))
  10. print("script_path: ", script_path)
  11. #returns
  12. C:\Users\John\ProjectXFolder\ProjectXSubFolder
  13.  
  14.  
  15. # 2] Same as the above but get the name of the script aswell
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top