Get it from globalsdict in this case:
def get_path():
return globals()['__file__']
Change in response to comment: taking into account the following files:
def get_path():
return 'Path from a.py: ' + globals()['__file__']
import a
def get_path():
return 'Path from b.py: ' + globals()['__file__']
print get_path()
print a.get_path()
Running this will give me the following result:
C:\workspace>python b.py
Path from b.py: b.py
Path from a.py: C:\workspace\a.py
/ , ( , ), .