You need to call os.path.realpath
on __file__
, so that when __file__
is a filename without the path you still get the dir path:
import os
print(os.path.dirname(os.path.realpath(__file__)))
More Related Contents:
- Importing modules from parent folder
- How can I iterate over files in a given directory?
- How do you get a directory listing sorted by creation date in python?
- Directory-tree listing in Python
- Django optional url parameters
- Iterating through directories with Python
- How to find the real user home directory using python?
- Reading the target of a .lnk file in Python?
- How to receive json data using HTTP POST request in Django 1.6?
- Renaming multiple files in a directory using Python
- How to select a directory and store the location using tkinter in Python
- Import from sibling directory
- Deleting read-only directory in Python
- Class has no objects member
- Django class-based view: How do I pass additional parameters to the as_view method?
- How to change the file name of an uploaded file in Django?
- matching query does not exist Error in Django
- The view didn’t return an HttpResponse object. It returned None instead
- How does the order of mixins affect the derived class?
- Django 1.11 TypeError context must be a dict rather than Context
- Unable to import path from django.urls
- How do I call a Django function on button click?
- How can I extract the folder path from file path in Python?
- Determining Whether a Directory is Writeable
- Find all CSV files in a directory using Python
- Can I make STATICFILES_DIR same as STATIC_ROOT in Django 1.3?
- Creating files and directories via Python
- Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given
- How to redirect from a view to another view In Django
- Handling directories with spaces Python subprocess.call()