I have a folder
with a README.md
and a run.py
that looks like this:
import os
assert __name__ == '__main__'
print('■', __file__)
print('●', os.getcwd())
try:
os.mkdir('DELETE_ME')
except FileExistsError:
pass
The readme contains the code line python -m a001_misc.b006_cwd.folder.run
.
PyCharm shows a green triangle next to it.
When I click on it, the output tells me, that folder
is my CWD.
This is the desired behavior. (Above all, DELETE_ME
is created in folder
.)
But I do not find a one-line console command to reproduce this (i.e. without cd
).
I would like to know, what actually happens, when I do that click.
The closest equivalent I have found is to do python -m run
in folder
.
(While running the whole command in folder
creates a ModuleNotFoundError
.)
The readme also contains the code line python run.py
.
Normally it raises no questions. Clicking it does the same as running the command in folder
.
But there is a small bug, and maybe it can help to answer the question.
I have renamed the parent of folder
from b006_mswitch_confusion
to b006_cwd
.
But somehow the old name is still connected with this button in the readme.
Where is that old name still hidden?
(I have already deleted the __pycache__
in folder
.)
The example code can also be found here.
(The readme file contains the outputs for different ways to run the script.)
The answer and comments by Ahmed AEK contain all the important facts.
Anyway, I think the answer to my question can be simplified to the following:
Clicking on the command will cd
into the folder of the markdown file and run the command.
But this happens in an environment, where PyCharm has added the project folder to PYTHONPATH
.
One could say, that there is no exact console equivalent of the click, because there is probably no way to figure out from the console, what PyCharm considers to be the project folder.