How to deal with the problem that the current directory moves when Python is executed from Atom

You can run Python on Atom using atom-runner, one of Atom's packages. However, since the current directory at runtime becomes the project folder, the current directory changes depending on the open folder. This behavior is a bit annoying when you simply want to use a relative path.

Countermeasures

Align the current directory with the directory where the file exists.

import sys
import os
os.chdir(os.path.dirname(sys.argv[0]))

I wonder if this is enough for a write-down script that cannot be read from other files.

Recommended Posts

How to deal with the problem that the current directory moves when Python is executed from Atom
How to deal with the problem that build fails when CI / CD of Python Function with AWS Amplify
How to deal with the phenomenon that Python (Jupyter notebook) executed on WSL becomes Aborted
[VLC] How to deal with the problem that it is not in the foreground during playback
How to deal with OAuth2 error when using Google APIs from Python
How to know the current directory in Python in Blender
How to deal with the problem that Japanese characters are garbled when outputting logs using JSON log formatter
[systemd] How to deal with the problem that fancontrol does not work after suspending
A story about how to deal with the CORS problem
How to deal with the problem that pandas 1.1.0 or later build fails on Alpine Linux
How to deal with errors when installing Python and pip with choco
I made something with python that NOW LOADING moves from left to right on the terminal
How to deal with the error "Failed to load module" canberra-gtk-module "that appears when you run OpenCV
Workaround for the problem that? Is displayed when checking the version when using non-standard perl | python with pkg version
[Python] How to deal with module errors
The 16th offline real-time how to write problem was solved with Python
[PostgreSQL] How to grant superuser authority when the user (role) with superuser authority is 0
The 16th offline real-time how to write reference problem to solve with Python
How to deal with SSL error when connecting to S3 with boto of Python
The 19th offline real-time how to write reference problem to solve with Python
The 15th offline real-time how to write problem was solved with python
How to automatically notify by phone when the python system is down
[Python] What to do when PEP8 is violated in the process of importing from the directory added to sys.path
How to deal with errors when hitting pip ②
How to deal with SessionNotCreatedException when using Selenium
Introduction to Python with Atom (on the way)
[Python] Solution to the problem that elements are linked when copying a list
[AWS] Wordpress How to deal with "The response is not a correct JSON response"
[Python Tips] How to retrieve multiple keys with the maximum value from the dictionary
How to get a list of files in the same directory with python
How to correctly upgrade the software when building Linux (CentOS) with Vagrant ~ Using the example of upgrading from Python 2.7 to Python 3.6 ~
[Python] How to deal with the is instance error "is instance () arg 2 must be a type or tuple of types"
How to deal with "^ [[A ^ [[B ^ [[C ^ [[D"] when you press the arrow keys when executing python on mac
[Python] How to remove duplicate values from the list
A story that failed when trying to remove the suffix from the string with rstrip
How to scrape image data from flickr with python
Try to find the probability that it is a multiple of 3 and not a multiple of 5 when one is removed from a card with natural numbers 1 to 100 using Ruby and Python.
Try to solve the internship assignment problem with Python
The first algorithm to learn with Python: FizzBuzz problem
[Reintroduction to python] How to import via the parent directory
[Python] How to specify the download location with youtube-dl
Find the part that is 575 from Wikipedia in Python
[Python] How to deal with pandas read_html read error
How to pass arguments when invoking python script from blender on the command line
I tried to solve the problem with Python Vol.1
[Python] How to rewrite the table style with python-pptx [python-pptx]
[Introduction to Python] What is the important "if __name__ =='__main__':" when dealing with modules?
Try to create a waveform (audio spectrum) that moves according to the sound with python
The 15th offline real-time I tried to solve the problem of how to write with python
How to deal with "fatal: destination path''already exists and is not an empty directory." When trying to clone on Git hub
Two solutions to the problem that it is hard to see the vector field when writing a vector field with quiver () of matplotlib pyplot
How to write offline real time I tried to solve the problem of F02 with Python
How to scrape stock prices of individual stocks from the Nikkei newspaper website with Python
How to know the number of GPUs from python ~ Notes on using multiprocessing with pytorch ~
How to deal with the error that Docker's MySQL container fails to start on Docker Toolbox
How to deal with the terminal getting into the pipenv environment without permission when using pipenv with vscode
How to delete "(base)" that appears in the terminal when Anaconda is installed on Mac
How to test that Exception is raised in python unittest
I tried to simulate how the infection spreads with Python
Problem not knowing parameters when dealing with Blender from Python
[Linux] How to deal with garbled characters when viewing files