D
D
Daniil Shevkunov2021-06-06 15:12:08
Python
Daniil Shevkunov, 2021-06-06 15:12:08

When running the script from notepad++, there is no file in the same folder, what should I do?

Of course, I am aware of different IDEs, I mainly use PyCharm myself, but for scripts for a couple of lines I usually

take

notepad

++ those that open files not by the full path,

for example, there is a simple script:

with open('file.txt') as f:
    print(f.read())


next to the folder is the same file.txt file, and if I run the script simply from the folder, by double-clicking the mouse, it works fine,
but if I try to run it and Notepad ++ it says that the file was not found. I understand that the script is, as it were, executed from the folder with the python - it tries to find the specified file in it.

Does anyone know how to fix this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-06-06
@danila763

Esteem about concept "current directory". If the file path is relative, then it is relative to the current directory.
I suspect that the current directory when NPP is running is the directory where NPP itself is located, and it doesn't change it on startup (because it doesn't know if it should).
Try changing the launch command to something like
cmd /K cd "$(CURRENT_DIRECTORY)" && python "$(FULL_CURRENT_PATH)
" first you change the current directory to the script directory, and then you start the python with the options you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question