sys.stdin.readline()
Mike Maxwell
maxwell at ldc.upenn.edu
Wed Sep 1 07:56:17 EDT 2004
Alex Martelli wrote:
> Mike Maxwell <maxwell at ldc.upenn.edu> wrote:
> No, I think you're correctly observing that Python isn't oriented to
> one-liners -- not at all. Most interesting things in Python require
> more than one line.
<rant>
I don't care whether it's "interesting", I just want to get some work
done. And since most of the text processing tools in Unixes that I
would otherwise use (grep, sed, tr) don't support Unicode, and are
inconsistent in their regular expression notation to boot, it would be
nice if I could write regex operations in a single, consistent
programming language. Python is a single, consistent programming
language, but as you say, it doesn't lend itself to one-liners.
</rant>
> You could write a "oneliners shell" that takes some
> defined separator and turns it into a newline, of course, e.g.:
>
> bangoneliner.py:
> #!/usr/bin/env python
> import sys
> oneliner = sys.argv.pop(1)
> exec '\n'.join(oneliner.split('!'))
>
> now, sometying like
>
> bangoneliner.py 'for x in xrange(7):! if x%2:! print x'
>
> should work
Hmm, I may give that a try...thanks!
> note that inserting the spaces after the bangs to simulate
> proper indentation IS a silly fuss, but you hafta...:-).
Well, I guess I could translate some other char (one that's easier to
count than spaces) into indents, too.
Mike Maxwell
More information about the Python-list
mailing list