[PYTHON] Access the file with a relative path from the execution script.

The execution script name can be obtained with __file__. Combine this with the os.path module to access the file with a relative path from the execution script.

base = os.path.dirname(os.path.abspath(__file__))
name = os.path.normpath(os.path.join(base, '../local/local_db'))

Recommended Posts

Access the file with a relative path from the execution script.
Read a file in Python with a relative path from the program
[Python] Get the script execution directory with an absolute path
Process the contents of the file in order with a shell script
Save the Pydrive authentication file in a different directory from the script
Extract lines that match the conditions from a text file with python
Save the object to a file with pickle
Draw a graph with matplotlib from a csv file
Read line by line from a file with Python
Access the variables defined in the script from the REPL
A python script that draws a band diagram from the VASP output file EIGENVAL
Python script to create a JSON file from a CSV file
Run a Python file with relative import in PyCharm
I replaced the Windows PowerShell cookbook with a python script.
[Python] Create a file & folder path specification screen with tkinter
[Linux] Copy data from Linux to Windows with a shell script
Make a gif animation from a serial number file with matplotlib
A shell script that just emails the SQL execution result
Process the files in the folder in order with a shell script
File access under the directory
Conditional branch due to the existence of a shell script file
Create a shell script to run the python file multiple times
How to make a command to read the configuration file with pyramid
Outputs a line containing the specified character string from a text file
Write a script to calculate the distance with Elasticsearch 5 system painless
The idea of feeding the config file with a python file instead of yaml
[Mac] Create a Python3 execution environment from the fully initialized state
Get OCTA simulation conditions from a file and save with pandas
Execute Python script from batch file
Script execution at startup with ipython
Follow the file hierarchy with fts
Build a deb file with Docker
Get the script path in Python
Download the file deployed with appcfg.py
Debug the script with Sakura Editor
Open the file with the default app
Get the file path using Pathlib
Write a batch script with Python3.5 ~
Create a file uploader with Django
Throw GQL with a numeric ID from the App Engine management screen
Replace the directory name and the file name in the directory together with a Linux command.
A memo organized by renaming the file names in the folder with python
Learning record (4th day) #How to get the absolute path from the relative path
View the full path (absolute path) of a file in a directory in Linux Bash
Get the average salary of a job with specified conditions from indeed.com
[Implementation example] Read the file line by line with Cython (Python) from the last line
Tweet the weather forecast with a bot
Access the Docker Remote API with Requests
Creating a simple PowerPoint file with Python
[Note] Read a file from another directory
Script to generate directory from json file
Execute a script from Jupyter to process
Check the existence of the file with python
Search the maze with the python A * algorithm
Let's read the RINEX file with Python ①
Create a large text file with shellscript
Run the Python interpreter in a script
Get the path to the systemd unit file
Create a star system with Blender 2.80 script
[Blender] Use OpenGL from inside the script
Create a VM with a YAML file (KVM)