Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current path when running Python from Notepad++

I run Python scripts in Notepad++ using this command

cmd.exe /K "C:\InstallPython\python.exe" "$(FULL_CURRENT_PATH)" 

it works, but it works not great. When I run

exec(open("raw_ticker_list.lua").read())

it doesn't see the file, but it is in the same folder where the script lies. When I run

import os
print(os.getcwd())

it prints

enter image description here

How can I make python see files in current folder?

like image 404
DeepSpace Avatar asked Jul 26 '26 00:07

DeepSpace


1 Answers

Use this command instead:

cmd.exe /K "cd /D "$(CURRENT_DIRECTORY)" & python "$(FULL_CURRENT_PATH)""

To recap, open the "Run" menu, select the "Run" entry, and enter the above command as "The Program to Run". Possibly "Save…" it and assign a name (and keyboard shortcut) so that it permanently appears in the "Run" menu going forward.

What it does is, it opens a command window, changes the working directory to that of the script currently active in the editor (across hard drives, hence the /D parameter), then runs the Python interpreter on the script, but keeps the command window open afterwards (the /K parameter).

Use the full path to python.exe instead of just python in case it's not on the Windows search path for executables.

like image 189
john-hen Avatar answered Jul 28 '26 13:07

john-hen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!