[Pythonmac-SIG] I stand corrected on BBEdit Python Filters
Daniel Lord
dmlsj@yahoo.com
Wed, 18 Dec 2002 17:50:42 -0800
Blake, Chris, Mark
I had been using the Pythonic construct to access stdin to try to write
a working filter since that is what I had used to filter files from
stdin to stdout in an abstract filter class I wrote,
# ------------------------------------------------------------------ #
# Abstract Class #
# To use: subclass and override filterLine #
# ------------------------------------------------------------------ #
class AbstractStreamFilter:
def __init__(self):
import sys # no explicit files
while 1: # use standard streams
line = sys.stdin.readline() if not line:
break
self.filterLine(line)
# ------------------------------------------------------------------ #
# Overridden in class that implements this abstract class #
# ------------------------------------------------------------------ #
def filterLine(self, line):
raise NotImplementedError, \
"Abstract method filterLine(self, line) not overridden!"
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.
Daniel
--
daniellordATtelocityDOTcom
GPG Fingerprint: C59E 59F5 1C63 5CFB 6161 067E FF00 A4E8 684A 16BB
"My dancing, drinking, and singing weave me the mat
upon which my soul will sleep in the world of spirits"
[Old Man of Halmahera, Indonesia]