[BioPython] python equiv of perl's null operator <>
Andrew Dalke
dalke at dalkescientific.com
Tue Jul 15 10:04:24 EDT 2003
Mike Cariaso:
> After moving from perl to python I find I miss the ability to do a
>
> while (<>) { }
Look at 'fileinput' in the standard library.
However, using it will be slower than using, say
try:
args, filenames = getopt.getopt ...
except getopt.error:
...
if not filenames:
filenames = ["-"]
for filename in filenames:
if filename == "-":
infile = sys.stdin
else:
infile = file(filename)
for line in infile:
...
because 'fileinput' also preserves the line number, in-place filtering,
and a few other perl-isms, implemented in Python, and not C as Perl
does it.
Andrew
dalke at dalkescientific.com
More information about the BioPython
mailing list