3

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?

3
  • this may help stackoverflow.com/questions/3161989/… Commented Jul 3, 2019 at 18:19
  • 1
    os.getcwd() gets the path where Python is running the script, not where the file sits. What does it say when you print(__ file __)? Commented Jul 3, 2019 at 18:22
  • command exec(open("raw_ticker_list.lua").read()) is not working too. It doesn't see file. Commented Jul 3, 2019 at 18:45

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.