B
B
beginer1232016-09-09 18:23:59
Django
beginer123, 2016-09-09 18:23:59

Python3 os.path.abspath(os.path.dirname(__file__)) returns wrong?

I need to return the very beginning of the site for different OSes,
Google writes that this should return it,
os.path.abspath(os.path.dirname(__file__))
i.e. if the site is located on D: / python_proj / mysite.com
Then it should return this address
But it grows the address of the folder where the script that executes this lies command

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xSkyFoXx, 2016-09-09
@xSkyFoXx

Which is absolutely logical. You are asking for the location of the file where you are executing the code: os.path.dirname(__file__). If you need to get the value of the top level address:

  • Initialize the constant at the entry point and include it in the required module. OR
  • Manually specify how many levels up to return from the current file.

S
sim3x, 2016-09-09
@sim3x

i.e. if the file is located at D:/python_proj/mysite.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question