Python Forum

Full Version: what does __file__ mean in getting abspath
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Did you try to print __file__ and check for yourself? :-)

(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)
(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...
(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])
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
(Aug-30-2019, 06:31 AM)buran Wrote: [ -> ]Import related module attributes
(Sep-02-2019, 05:15 AM)buran Wrote: [ -> ]
(Aug-30-2019, 06:31 AM)buran Wrote: [ -> ]Import related module attributes

Thank you..!! Smile
This search engine gives very good results too.