[Note] Import of a file in the parent directory in Python

If you want to import a script file located in the parent directory, you can do it as follows. In this example, we are importing the tools.py file located in the parent directory.

>>> import sys,os
>>> sys.path.append(os.pardir)
>>> import tools

Recommended Posts

[Note] Import of a file in the parent directory in Python
Get the caller of a function in Python
Make a copy of the list in Python
A note about the python version of python virtualenv
[Note] About the role of underscore "_" in Python
Output in the form of a python array
Test & Debug Tips: Create a file of the specified size in Python
View the full path (absolute path) of a file in a directory in Linux Bash
I made a program to check the size of a file in Python
[Reintroduction to python] How to import via the parent directory
Run a Python file with relative import in PyCharm
A reminder about the implementation of recommendations in Python
Python Note: The mystery of assigning a variable to a variable
Various ways to read the last line of a csv file in Python
How to get a list of files in the same directory with python
A note on the default behavior of collate_fn in PyTorch
Find out the apparent width of a string in python
[Python] The stumbling block of import
Save the binary file in Python
Change the standard output destination to a file in Python
Different from the import type of python. from A import B meaning
A memo that implements the job of loading a GCS file into BigQuery in Python
How to import a file anywhere you like in Python
Get the number of specific elements in a python list
Create a binary file in Python
The story of the "hole" in the file
Google search for the last line of the file in Python
Find the eigenvalues of a real symmetric matrix in Python
Process the contents of the file in order with a shell script
Set the last modified date of the child file to the modified date of the parent directory
How to determine the existence of a selenium element in Python
How to check the memory size of a variable in Python
Read the standard output of a subprocess line by line in Python
Save the Pydrive authentication file in a different directory from the script
How to check the memory size of a dictionary in Python
Read a file in Python with a relative path from the program
The idea of feeding the config file with a python file instead of yaml
Dig the directory and create a list of directory paths + file names
Get the formula in an excel file as a string in Python
[python] A note that started to understand the behavior of matplotlib.pyplot
Get the number of readers of a treatise on Mendeley in Python
Trial of writing the configuration file in Python instead of .ini etc.
I can't import modules in the parent directory even with sys.path.append ('..')
Check the behavior of destructor in Python
[Note] Read a file from another directory
Write the test in a python docstring
Display a list of alphabets in Python 3
Check the existence of the file with python
Run the Python interpreter in a script
The result of installing python in Anaconda
Read the file line by line in Python
Read the file line by line in Python
[python] [meta] Is the type of python a type?
The basics of running NoxPlayer in Python
[GPS] Create a kml file in Python
In search of the fastest FizzBuzz in Python
[Python] Get the character code of the file
Get the filename of a directory (glob)
The story of blackjack A processing (python)
Python Note: The secret role of commas
Install the Python module in any directory