How to execute a single line of a python script in Terminal? -
i have current simple script saved ex1.py in sublime text 2 ide.
print "hello world!" print "hello again" print "i typing this." print "this fun." print 'yay! printing.' print "i'd rather 'not'." print 'i "said" not touch this.'
i execute single line script in terminal, haven't been able figure out how.
the script executes 7 lines. there way specify, example, want execute line 3?
as @wooble says, odd requirement, anyway, here solution in bash session:
use awk extract line want (e.g. line 2):
$ awk 'nr==2' ex1.py print "hello again"
then feed python interpreter through stdin
.
$ awk 'nr==2' ex1.py | python hello again
you can specify range
$ awk 'nr>=2 && nr<=4' ex1.py | python hello again typing this. fun.
edit: note in case, equivalent sed
command requires fewer keystrokes
$ sed -n '2,4 p' ex1.py | python hello again typing this. fun.
Comments
Post a Comment