Interaktives Ausführen von Python / Ruby in Notepad ++ (NppExec-Konsole)

4604
Assad Ebrahim

Ich habe die NppExec-Konsole in Notepad verwendet, um Python- und Ruby-Skripts mit python script_name.pyoder auszuführen. ruby script_name.rbDies funktioniert größtenteils gut: Die Ausgabe wird in die NppExec-Konsole umgeleitet, und ich muss zum Testen nicht Notepad ++ wechseln mein Drehbuch

Was ich jedoch wirklich gerne tun könnte, ist, eine interaktive Sitzung mit Python oder Ruby von der NppExec-Konsole aus auszuführen. Zum Beispiel, einfach pythonoder einfach irbnicht interaktiv in der Konsole arbeiten.

Hat jemand Glück gehabt?

Wenn dies möglich wäre, würde dies bedeuten, dass Sie Funktionen / Methoden in einem bestimmten Skript von der Konsole aus ausführen können, ohne Notepad ++ zu verlassen.

0
Sie können "pry" (für Ruby) verwenden und die Zeilen "required" pry "" und "binding.pry" zu Ihrem Code hinzufügen, um die interaktive Konsole im aktuellen Bereich zu öffnen. itdoesntwork vor 11 Jahren 0
@itdoesntwork: scheint falsch zu sagen, aber ... es funktioniert nicht! Im Ernstfall, sind Sie sicher, dass Sie diese Funktion zum Aufruf von pry von ** aus dem Konsolenfenster in Notepad ++ (NppExec) haben? ** Den Tipp zu pry schätzen - habe den Edelstein gerade installiert, und er scheint besser zu sein als irb. Aber ich glaube nicht, dass es mir das gibt, worauf ich hoffe: Ruby interaktiv von Notepad ++ aus ausführen. Lass mich wissen, wenn mir etwas fehlt. Assad Ebrahim vor 11 Jahren 0

3 Antworten auf die Frage

1
prrao

This doesn't look like it's possible. From the NppExec documentation, I quote:

NppExec is NOT...

  • NppExec is not a console emulator. NppExec redirects the running process'es output to its Console window, and can redirect the Console window's input to the running process (with some limitations). The NppExec's Console is not a "real" console window (actually, it uses RichEdit control for text input/output), it does not provide a console screen buffer. Thus, a console application which requires a "real" console screen buffer must be run in its own console window (using NPP_RUN command).

  • NppExec is not a command interpreter. NppExec does not understand such commands as 'copy', 'call', 'for' and so on because it is neither a "real" console nor a console emulator. However, NppExec has its own internal implementation of such commands as 'cls', 'cd', 'dir', 'echo', 'set' ('env_set') and introduces other, specific, commands. Also you can use "cmd /c " to execute any cmd's command inside NppExec.

  • NppExec is not a compiler. NppExec allows you to use external tools and compilers to process/compile your current file, but it has no ability to do it by itself. No magic here :)

Since there is no console screen buffer, the NppExec console cannot qualify as a "real" console.

You're much better off trying an application that was designed for interactive testing of code, such as IPython for Python.

Danke für die Antwort. Ihr Zitat über Konsolenpuffer, NppExec und Npp_run veranlasste mich, dies erneut zu untersuchen und zu testen, was genau die Konsolenpuffer von NppExec in Bezug auf E / A tun. Anscheinend nehmen sie sowohl Eingabe als auch Ausgabe auf. Also das einfache Python-Programm `print (" Alles eingeben: ", end =" "); Antwort = Eingabe (); print (response) `funktioniert, wenn von Npp_Execs Konsole aus mit` python $ (FILE_NAME) `aufgerufen wird. Dies hat mich zu einer Lösung geführt, die funktioniert - siehe Antwort. Also (+1) für eine Teilantwort, die dazu motiviert war, eine tatsächliche Lösung zu finden! Vielen Dank. Assad Ebrahim vor 11 Jahren 0
0
Assad Ebrahim

Bearbeiten (Hinzufügen von -u ungepuffertem Schalter für bessere Leistung)

Es stellt sich heraus, dass dies für Python mit dem -iSchalter (inspect) und dem Schalter -u (ungepufferter Ausgang) möglich ist, obwohl Npp_Exec keine echte Konsole ist :

 python -u -i $(FULL_CURRENT_PATH) 

Dadurch wird die aktuelle Datei in der Npp_Exec-Konsole im Python-Interpreter ausgeführt. Aufgrund des -iWechsels springt der Benutzer direkt in den interaktiven Modus, in dem Sie dann innerhalb der NppExec-Konsole fortfahren können, um alle vom Skript bereitgestellten Variablen oder Definitionen zu prüfen / verwenden.

Wenn Sie Ihre Npp_Exec-Konsole so einstellen, dass sie dem aktuellen Verzeichnis folgt Notepad++ Menu > Plugins > NppExec > Follow $(CURRENT_DIRECTORY, ist die Lösung noch einfacher:

 python -u -i $(FILE_NAME) 

(Hinweis: Für Ruby ist dies immer noch eine offene Frage, da Ruby und sein interaktiver Interpreter aus irbzwei separaten Binärdateien bestehen und anscheinend keinen Inspect-Typ sowie einige andere Ungewöhnlichkeiten aufweisen, wenn Skripts ausgeführt werden, die sowohl Eingabe als auch Ausgabe haben.) .)

0
Mortaza Toufigh

I'm new to python and tried to learn python programming and because of some issues in IDLE(like line-numbering) I decided to use Notepad++ and of course NPP_EXEC plugin to ease code compiling. I had succeeded in some others like compiling *.vbs files but this time for python it was not triumph for some reason despite all the solution presented here and else where.

I tried first the python -u "$(FULL_CURRENT_PATH)" in NPP_EXEC. For some python scripts the result was satisfactory and as I proceeded in learning more in python I encountered a problem again because the output was not as I expected. I ran into the solution here by [AKE]. unfortunately none of these worked out to me up to now.

suppose the following code.

#------------------------------------------------- my_dict = dict({'Alice':1, 'John':2, 'Emma':3}) name = raw_input("enter the name: ") name = name.capitalize() if name in my_dict: #do something here else: print("The name does not exist!") #-------------------------------------------------

I used both:

python -u "$(FULL_CURRENT_PATH)"
and
python -u -i "$(FULL_CURRENT_PATH)"

but the result's always the same, whatever you enter as name in the above code the output is always:
[The name does not exist!]

I believe it's because of the -u switch, so I tried to omit it and use just -i as

python -i "$(FULL_CURRENT_PATH)"

It turned out to work but this time after you observed the output you have to press Ctrl+C to terminate the process manually and exit python interactive mode in NPP_EXEC console.

I know of some other work-arounds like using Notepad++ Run menu and adding some commands there or even using PyNPP plugin (although these two do almost identical procedure by redirecting python on cmd), but none of these had the convenience as I liked. Maybe I Expect too much of NPP_EXEC, because as it has in its help it's not a real console, but I wanted to do it all in Notepad++ without dealing with some other processes like IDLE or cmd or ....

Despite this I would appreciate any help if someone had any other successful experience.