0

I have created symbolic links for bin and config directories to deployment folder as below:

/opt/app/bin -> /opt/deployments/v1/bin
/opt/app/config -> /opt/deployments/v1/config

I have a Python file as /opt/app/bin/pullfiles.py. I have tried with below code to take abspath of pullfiles.py file:

import os
working_dir = f'{os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]}

It gives me below result:

/opt/deployments/v1

but I need actual result:

/opt/app
khelwood
  • 55,782
  • 14
  • 81
  • 108
  • The point of `os.path.realpath` is to eliminate symbolic links. If you want the path of the link instead of the path to the original, don't use `realpath`. – khelwood May 08 '19 at 12:34
  • Possible duplicate of [Why would one use both, os.path.abspath and os.path.realpath?](https://stackoverflow.com/questions/37863476/why-would-one-use-both-os-path-abspath-and-os-path-realpath) – khelwood May 08 '19 at 12:36
  • @khelwood, thanks for response , i have tried with working_dir = f'{os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]} still same result – Suresh Subramaniyan May 08 '19 at 12:37
  • @khelwood, os.path.abspath is working only for files , its not working for files under linked directory . i have created symbolic link for directory . i m trying to take abspath for files under bin directory . source : /opt/deployement/bin/pythonfiles destination: /opt/app/bin -> /opt/deployment/bin – Suresh Subramaniyan May 08 '19 at 12:46
  • 1
    If `abspath` doesn't work for you, I suggest you figure out exactly what argument you are passing into `abspath` and exactly what you are getting out, and include those in your question. – khelwood May 08 '19 at 12:51

0 Answers0