[Python] understand __file__

Under py3, __file__it returns the file absolute address ;
and in py2, __file__the return of the file relative address .

Want to get the files in the py2 absolute address, you can help os.path.abspath():

import os
print(os.path.abspath(__file__))

You can get absolute address.

Published 628 original articles · won praise 863 · Views 1.85 million +

Guess you like

Origin blog.csdn.net/JNingWei/article/details/104848649