DeepSpace
DeepSpace

Reputation: 153

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?

Upvotes: 3

Views: 1695

Answers (1)

john-hen
john-hen

Reputation: 4866

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.

Upvotes: 2

Related Questions