By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,192 Members | 1,783 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,192 IT Pros & Developers. It's quick & easy.

Command-line tool able to take multiple commands at one time?

P: n/a
Per subject - I realize I can copy/paste a line at a time into an interactive
session when I'm trying to debug, but was wondering if there is any tool out
there that allows me to copy sections of working Python scripts to paste into my
interactive console and let those run so I don't have to copy line-by-line.

Not sure if iPython would meet that criteria or not or even if such a beast
exists. It would be helpful for debugging some of my simpler, yet still lengthy
at times, scripts.

Thanks in advance.

-Pete Schott
Nov 11 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a

Peter A. Schott wrote:
Per subject - I realize I can copy/paste a line at a time into an interactive
session when I'm trying to debug, but was wondering if there is any tool out
there that allows me to copy sections of working Python scripts to paste into my
interactive console and let those run so I don't have to copy line-by-line.

Not sure if iPython would meet that criteria or not or even if such a beast
exists. It would be helpful for debugging some of my simpler, yet still lengthy
at times, scripts.

Thanks in advance.

-Pete Schott


It's called IDLE (At least, the interactive session with it). Some
people dislike IDLE, though.

Nov 11 '05 #2

P: n/a
Peter A. Schott <pa******@no.yahoo.spamm.com> writes:
Per subject - I realize I can copy/paste a line at a time into an interactive
session when I'm trying to debug, but was wondering if there is any tool out
there that allows me to copy sections of working Python scripts to paste into my
interactive console and let those run so I don't have to copy line-by-line.


Um, just curious - doesn't copying multiple lines at a time work now?
That works fine for me on both OS X and Unix.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Nov 11 '05 #3

P: n/a
Peter A.Schott wrote:
Per subject - I realize I can copy/paste a line at a time into an interactive
session when I'm trying to debug, but was wondering if there is any tool out
there that allows me to copy sections of working Python scripts to paste into
my interactive console and let those run so I don't have to copy line-by-line.

Not sure if iPython would meet that criteria or not or even if such a beast
exists. It would be helpful for debugging some of my simpler, yet still
lengthy at times, scripts.


ipython has a %run command designed precisely to do this. You can keep your
favorite editor open and work on your code. You just need to save and type
into ipython 'run scriptname', to re-execute the code each time just as if
you'd typed it. Note that ipython uses readline, so you just need to type 'r'
and hit the up-arrow key to retrieve the previous command starting with the
letter r.

Type 'run?' (without the quotes) into ipython to get the gory details on the run
command, or have a look at the manual here (scroll down to the %run part):

http://ipython.scipy.org/doc/manual/...00000000000000

Feel free to ask further questions on the ipython list, I don't keep up with
c.l.py too well these days, unfortunately.

Cheers,

f

Nov 11 '05 #4

P: n/a
Peter A. Schott wrote:
Per subject - I realize I can copy/paste a line at a time into an interactive
session when I'm trying to debug, but was wondering if there is any tool out
there that allows me to copy sections of working Python scripts to paste into my
interactive console and let those run so I don't have to copy line-by-line.


There's much better than that : emacs + python-mode let you evaluate
either the whole script, a single class or def statement, or an
arbitrary region in an interactive Python interpreter running as an
emacs sub-process. Of course, this interpreter don't die after, so you
can inspect/play with/do whatever with the results of this evaluation.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Nov 11 '05 #5

P: n/a
I'll give it a try. I've been using PythonWin and SPE recently and hadn't
really messed with IDLE too much as I liked the somewhat more advanced features
of the other IDEs. I'll check it out again.

Also thanks to all for the IP hints - I may check those out as well.

-Pete

"Devan L" <de****@gmail.com> wrote:

Peter A. Schott wrote:
Per subject - I realize I can copy/paste a line at a time into an interactive
session when I'm trying to debug, but was wondering if there is any tool out
there that allows me to copy sections of working Python scripts to paste into my
interactive console and let those run so I don't have to copy line-by-line.

Not sure if iPython would meet that criteria or not or even if such a beast
exists. It would be helpful for debugging some of my simpler, yet still lengthy
at times, scripts.

Thanks in advance.

-Pete Schott


It's called IDLE (At least, the interactive session with it). Some
people dislike IDLE, though.

Nov 11 '05 #6

P: n/a
OK - I justed tested and may be doing something wrong, but it didn't work when I
just tried it.

I have something like this:

X = "Value1"
Y = "Value2"
Z = "Value3"

etc at the top of my script. When I copy/paste those three lines all at once
into IDLE's interactive window, X is defined, Y and Z are not.

That's more the behaviour I was hoping for - the ability to run parts of my code
at a time in order to work through issues without too much trouble in
mostly-working code.

TIA,

-Pete Schott

Mike Meyer <mw*@mired.org> wrote:
Peter A. Schott <pa******@no.yahoo.spamm.com> writes:
Per subject - I realize I can copy/paste a line at a time into an interactive
session when I'm trying to debug, but was wondering if there is any tool out
there that allows me to copy sections of working Python scripts to paste into my
interactive console and let those run so I don't have to copy line-by-line.


Um, just curious - doesn't copying multiple lines at a time work now?
That works fine for me on both OS X and Unix.

<mike

Nov 11 '05 #7

P: n/a
Peter A. Schott wrote:
OK - I justed tested and may be doing something wrong, but it didn't work when I
just tried it.

I have something like this:

X = "Value1"
Y = "Value2"
Z = "Value3"

etc at the top of my script. When I copy/paste those three lines all at once
into IDLE's interactive window, X is defined, Y and Z are not.

That's more the behaviour I was hoping for - the ability to run parts of my code
at a time in order to work through issues without too much trouble in
mostly-working code.

TIA,

-Pete Schott


Oh, that kind of multi-line input. I thought you were talking about
def foo(bar):

.... long_statement_here
.... even_longer_statement_here
.... return something

I would just put it into a .py and run it through IDLE, change it, and
rerun it. There are probably other IDEs which can already do that, but
I just use IDLE.

Nov 11 '05 #8

P: n/a
On Fri, 11 Nov 2005 01:05:56 GMT, Peter A. Schott <pa******@no.yahoo.spamm.com> wrote:
Per subject - I realize I can copy/paste a line at a time into an interactive
session when I'm trying to debug, but was wondering if there is any tool out
there that allows me to copy sections of working Python scripts to paste into my
interactive console and let those run so I don't have to copy line-by-line. What are you pasting into? Idle? win32 console? via telnet?
The win32 console you get by running python.exe from the cmd.exe windows shell
permits multi-line copying and pasting (Alt-spacebar,e,k,<hold shift down>
<select-motions></hold shift down>,Enter and Alt-spacebar,e,p respectively).
(You can also use <hold left mouse down> and move mouse for <select-motions>
instead of arrow keys, as a substitute for <hold shift down>)

The trick is that unlike executing file-based source lines as in import or execfile,
compilation has to be triggered by something acting like EOF. In the interactive mode
that is statement by statement until a statement is followed by an indented suite.
Then the compilation and execution of the indented suite is postponed until a blank line.

This is not really a good substitute for EOF or some other explicit EOF-emulating escape
from the suite input mode, because you can't switch to an editor and copy something that might have
arbitrary blank lines and compacted code that would import fine and expect it to paste fine.
IMO this is a wart of the interactive mode that could be improved (e.g, once into a multiline
sequence of input, terminate on ctl-something instead of blank line).

By experimentation you can see what chunks you can paste. E.g., try two function defs in a
single paste of the four lines:
def foo():
print 'foo'
def bar():
print 'bar'
def foo(): ... print 'foo'
... def bar():
File "<stdin>", line 3
def bar():
^
SyntaxError: invalid syntax print 'bar' File "<stdin>", line 1
print 'bar'
^
SyntaxError: invalid syntax

vs pasting them as five lines including a separting blank line:
def foo():
print 'foo'

def bar():
print 'bar'
def foo(): ... print 'foo'
... def bar(): ... print 'bar'
...


(I indent the paste here of interactive stuff one space to avoid
false quote highlighting in newsreaders).

Not sure if iPython would meet that criteria or not or even if such a beast
exists. It would be helpful for debugging some of my simpler, yet still lengthy
at times, scripts.


Plain vanilla gvim (popular editor) will let you invoke a program as filter on
anything you select in your editing window, and it will cut the selection and paste
the execution output in its place, so e.g., the above, starting with a screen like

# select starts on next line
def foo():
print 'foo'
def bar():
print 'bar'
#select ends at end of last line

and selecting the four lines and then typing :!python and pressing Enter,

what you get is
# select starts on next line
#select ends at beginning of this line (includes \n of last line)

Seems not very useful, since no output was generated by correct execution of the defs.
If there had been a syntax error, the same would have happened, unless stderr is captured
into the output stream.

Since my version of windows (ancient NT4) has the infamous redirection problem, I have to
invoke scripts via a single-line command file that runs python explicitly in order to capture
output by piping or redirection. So I have two versions, one that redirects stderr also. E.g.,

py24.cmd contains the single line
@d:\python-2.4b1\mingw\python24.exe %*

and py24e.cmd contains the single line
@d:\python-2.4b1\mingw\python24.exe %* 2>&1

So, now if there had been a syntax error, e.g., (restoring previous by hitting u key for undo
and editing in and example error)

# select starts on next line
def foo():
print 'foo'
def bar() # make syntax error (:)
print 'bar'
#select ends at beginning of this line (includes \n of last line)

Then we do the same and use py24e and get:

# select starts on next line
File "<stdin>", line 3
def bar() # make syntax error (:)
^
SyntaxError: invalid syntax
#select ends at beginning of this line (includes \n of last line)

And an undo will get us back.
Executing this way (as a filter action) you don't have to worry about
putting blank lines or not in the pasted material.

If we fix the error and put in a print for actual output, we'll get that:

# select starts on next line
def foo():
print 'foo'
def bar(): # fixed syntax error (:)
print 'bar'
foo(); bar() # expect output
#select ends at beginning of this line (includes \n of last line)

And then :!py24e after selecting the five lines gets

# select starts on next line
foo
bar
#select ends at beginning of this line (includes \n of last line)
Of course, you can do these two things in parallel. Not to mention extremely
flexible possibilities of mapping keys or key-sequences to almost anything
imaginable, if you want to go beyond plain vanilla. E.g., non-destructive
results in a split window is nicer.

But filters are easy and fun to invoke.

Of csuroe, you can do tsehe two thgnis
in paellarl. Not to menotin emxteerly
fblleixe pistisibleios of mpipang keys
or kqs-ycuneeees to aosmlt annhytig
inmgibalae, if you wnat to go bnyoed
pilan vlnaila. E.g., nnoi-csudvttere
rteluss in a spilt wdionw is neicr.

(last paragraph filtered through scramble and a paragraph-justifying
script specifying 8 margin 40 wide and justify to both edges ;-)

So what platform are you on?

Regards,
Bengt Richter
Nov 12 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.