Python from the command line (was: Choosing Perl/Python for my particular niche)

Fred Ma fma at doe.carleton.ca
Thu Apr 1 01:29:31 EST 2004


Cameron Laird wrote:
> 
> In article <4069F1FD.601C9079 at doe.carleton.ca>,
> Fred Ma  <fma at doe.carleton.ca> wrote:
>                         .
>                         .
>                         .
> >Perl/sed.  About invoking Perl as part of a simple command in a
> >pipeline, I mean that one doesn't even have to write a script for it,
> >similar to sed
> >
> >       Command1 | sed -e Expression1 -e Expression2 ... | Command_N
> >
> >This might also be possible in Python, in which case so much the better.
> >I'll find out (or someone might answer in a follow-up post).  Thanks
>                         .
>                         .
>                         .
>   # python -c "print 3 + 5"
>   8

I was 99.99% sure that it was possible (heck, if tcsh and bash can do
it, python surely can).  It's a little easier to squish it into a simple
command in a pipeline for a terse/compact "language" e.g. sed.  On a
side-note, I've abused sed before by embedded sed scripts into bash
scripts without actually writing the sed script:

	Bash_Command | \
	sed \
		-e 'Expression1' \
		-e 'Expression2' \
		-e 'Conditional1 {' \
		-e	'Body_of_Conditional1' \
		-e 	'More_of_Body' \
		-e '}' \
	| More_Bash_Commands

Not that I want to do everything in sed, of course.  And for
perl/python, there is probably not much reason to mix commands
with bash, since (unlike sed) they have the shell functionality.

I've put in a request to my sysadmin to install python.  The
way to get hooked on it is to start small, with mundane tasks
(same as with any new shell, I suppose).  If it doesn't get
installed due to lack of priority, I can always get it
bundled with my next cygwin update.  Cygwin is an absolute
blessing.  Everything comes prebuilt (lots of stuff) and
you have superuser priveleges, as well as simultaneous
access to Windows.  Just as long as your HDD isn't FAT
(that prevents chmod from working).

But I digress.....

Fred

-- 
Fred Ma
Dept. of Electronics, Carleton University
1125 Colonel By Drive, Ottawa, Ontario
Canada, K1S 5B6



More information about the Python-list mailing list