python - Is there a pythonic way to add a file name to absolute path? -
i using sqlite3
database django. learning right now, wanted know best way of adding file name existing path. example django settings.py
file:
base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) # creating base directory db_name = os.path.join(base_dir, 'database') # adding database name if os.sep != '/': # cases (bullet-proofing) db_name.replace(os.sep, '/') # replacing db_name += (os.sep + 'sqlite3db.db') # adding file name manually
what did in order add name of database file, simple added /
, name of file, in case is sqlite3db.db
. doing this, because following django tutorial pages @ database setup. there more elegant way of doing this? more pythonic way, because feels hard-coding things. appreciated.
i have not created sqlite3db.db
, since in tutorial says created me django.
not sure what's problem can use os.path.join
directly file name produce absolute path
os.path.join(db_name, 'sqlite3db.db')
is you're looking ?
Comments
Post a Comment