Python Forum
what does __file__ mean in getting abspath
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what does __file__ mean in getting abspath
#1
I'm exploring Django framework and in manage.py, I could see statement
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

I can understand till os.path.dirname and os.path.abspath, but what does __file__ mean?. Are we defining it anywhere?
I'm newbie to Python development, please bare my queries Angel Heart
Reply
#2
Did you try to print __file__ and check for yourself? :-)

If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Aug-30-2019, 06:31 AM)buran Wrote: Did you try to print __file__ and check for yourself? :-)


Well.. I just did that Big Grin Big Grin .. its pointing to self (the same file)
Reply
#4
(Aug-30-2019, 08:30 AM)Malt Wrote: Well.. I just did that Big Grin Big Grin .. its pointing to self (the same file)
good. I hope you also go trough other import related module attributes in my link...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(Aug-30-2019, 06:20 AM)Malt Wrote: I'm exploring Django framework and in manage.py, I could see statement
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

you can also use this one:

import sys
print(sys.argv[0])
Reply
#6
Quote: good. I hope you also go trough other import related module attributes in my link...

sorry I missed out the link, can you please share it here
Reply
#7
(Aug-30-2019, 06:31 AM)buran Wrote: Import related module attributes
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
(Sep-02-2019, 05:15 AM)buran Wrote:
(Aug-30-2019, 06:31 AM)buran Wrote: Import related module attributes

Thank you..!! Smile
Reply
#9
This search engine gives very good results too.
Reply
#10
Zeal - offline documentation browser is also a good help.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020