Use __file__
module attribute:
import os
with open(os.path.join(os.path.dirname(__file__), 'package.txt'), 'w'):
pass
According to the documentation:
Modules
...
__file__
is the pathname of the file from which the module was loaded, if it was loaded from a file.