title: In python, Is it possible to get the path of the invoked from the invoked file?
body: <p>I want to invoke config.py from ./, but I want config.py to recognize the path where it is located (&quot;./second/config.py&quot;)</p>
  <p>I want to invoke config.py from &quot;./&quot; and I want config.py to recognize and read file.json, but I dont want to send any paths as argument, nor append &quot;./second&quot; to sys.path.
  Is there a piece of code that can allow config.py recognize its relative path, and in this way join this path to the json's filename and read it?</p>
  <pre><code>./
  ├── main.py
  └── second
        ├── config.py
        └── file.json
  </code></pre>
  <p>I tried this on config.py</p>
  <pre><code>def test():
   print(pathlib.Path().absolute())
   print(os.getcwd())
  </code></pre>
  <p>However, it returns</p>
  <pre><code>./
  </code></pre>
  <p>and I am expecting it to return</p>
  <pre><code>/second/config.py
  </code></pre>