How to create/read file from current working directory instead of project root?


#1

I have a file structure like this: Company/SQLite/Database.py. The python program creates a .db file to be read from later. When I run the program in Atom, instead of creating the file in Company/SQLite/ it creates it in Company/. When I run the program outside of Atom (such as double clicking on the Database.py file in File Explorer) it creates the .db file in Company/SQLite/Database.py. Even when I change the current working directory in Database.py to Company/SQLite/ it still doesn’t create the .db file in the correct location.

When I had other projects open (like HomeProjects/Scripts/Program.py) it created the .db file in HomeProjects/, even though I didn’t have any files within HomeProjects/ open.

Why does this happen and how can I fix it? I would like for my file to be created in the current working directory of the file that is running.


#2

Atom has no ability to run Python code, so you must be using a package. When asking for help with a package, you always need to identify the package by name so that everybody knows what you’re talking about. Without the package name, I can’t tell you why it happens except for the obvious and general (the default CWD is the package root and you haven’t specified another or the package doesn’t give you that option). I can, however, suggest a solution which is generally applicable whenever you’re doing a more advanced use of automation through Atom: process-palette. You can define whatever command you like and have full control over what the CWD ends up being, then that command is bound to an Atom command which you can attach to a keybinding, a menu item, or even a tool-bar button.


#3

I am using the packages atom-runner 2.7.1 and minimap 4.29.8 (newest versions for both).

Within atom-runner settings it explains “Hit Ctrl+R (Alt+R on Win/Linux) to launch the runner for the active window.”, so it must be something to do with that. I’ve googled the issue, but I haven’t been able to find any solutions to getting it to run how I intend.


#4

The atom-runner documentation has no mention of changing CWD. Instead of attempting to make a package do something that its docs don’t say it can do, you should use a package that gives you what you want. Like process-palette.