If you want to persist data, it will "eventually" be to disk files (though there might be intermediate steps, e.g. via a network or database system, eventually if the data is to be persistent it will be somewhere in disk files).
To "find out where you are",
import os
print os.path.dirname(os.path.abspath(__file__))
There are variants, but this is the basic idea. __file__
in any .py
script or module gives the file path in which that file resides (won't work on the interactive command line, of course, since there's no file involved then;-).
The os.path
module in Python's standard library has many useful function to manipulate path strings -- here, we're using two: abspath
to give an absolute (not relative) version of the file's path, so you don't have to care about what your current working directory is; and dirname
to extract just the directory name (actually, the whole directory path;-) and drop the filename proper (you don't care if the module's name is foo.py
or bar.py
, only in what directory it is;-).