help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

running Python code with interaction


From: Stefan Vollmar
Subject: running Python code with interaction
Date: Wed, 09 Feb 2011 22:22:55 +0100

Hello,

I have been using the following code for developing simple Python programs with 
Emacs (mostly copied from some very helpful postings on this list - thanks):

(defun py-run-arg (arg)
  "run code in current buffer with Python interpreter"
  (interactive "sarg: \n")
  (save-buffer)
  (condition-case nil (delete-process "*compilation*") (error nil))
  (condition-case nil (kill-buffer "*compilation*") (error nil))
  (compile
   (format "python \"%s\" %s"
                   (buffer-file-name) arg)))

(global-set-key [(f1)] 'py-run-arg)

In case of errors, offending lines will be displayed in red colour and can be 
used as links to the offending code (courtesy of "compile") - neat!

This version also takes an argument which is passed to the Python interpreter. 
However, while this approach covers a lot of cases well, I occasionally wish to 
interactively enter data while a program is running and waiting for user input. 
Sometimes it is also desirable to have a special input mode for passwords and 
this is what you get when you run something like this code (Python) in a shell:
PASSWD = getpass.getpass()

Yes, I can switch to an Emacs shell and execute my Python code in commandline 
fashion (without leaving Emacs, which is the point). However, I want to start 
the code as conveniently as the above example (press <f1> to run the code of 
the current buffer) and, if possible, have automatic links to error lines (as 
compile mode provides). Is this possible?

Many thanks in advance.
Warm regards,
 Stefan
-- 
Dr. Stefan Vollmar, Dipl.-Phys.
Head of IT group
Max-Planck-Institut für neurologische Forschung
Gleuelerstr. 50, 50931 Köln, Germany
Tel.: +49-221-4726-213  FAX +49-221-4726-298
Tel.: +49-221-478-5713  Mobile: 0160-93874279
Email: vollmar@nf.mpg.de   http://www.nf.mpg.de






Attachment: smime.p7s
Description: S/MIME cryptographic signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]