There are times when the runtime directory is not the directory where the script is located, such as when executing on vscode.
If you perform file processing at that time, the file will not be found and an error will occur unless the file path is set appropriately.
Then add this to the top of the file and it will work.
sample.py
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))
__file__
By doing this, the file can be read only by the file name no matter where it is executed.
Recommended Posts