[Pythonmac-SIG] Re: I stand corrected on BBEdit Python Filters
Mark Day
mday@mac.com
Thu, 19 Dec 2002 09:13:26 -0800
On Wednesday, December 18, 2002, at 05:50 PM, Daniel Lord wrote:
> So naturally, I used the same construct for Python filter for BBEdit,
>
> while 1: # use standard streams
> line = sys.stdin.readline() if not line:
> break
>
> in order read standard input since the Perl filters use the Perlish
> construct for stdin,
>
> while(<>) {
>
> But the Python one doesn't work at all--not a character comes through.
> So I figured it was broken or unsupported.
> But...I was mistaken. I had somehow 'lost' (overlooked is a more harsh
> but more true description) the Python filter example which uses:
>
> for my_line in fileinput.input():
>
> to access the selected text. While I am not sure why one works but the
> other doesn't--they both should IMHO, I am just glad someone pointed
> out my error before I berated someone at BBEdit and then had to eat
> crow. I'd rather have a more palatable bird for Christmas dinner.
BBEdit runs your filter with the input in a temporary file passed as an
argument (not standard input). To see it in action, try the following
trivial Python filter:
import sys
print sys.argv
I think the Perl <> construct reads from the filenames given as
arguments, or standard input if there were no arguments.
-Mark