M
Matthew Wilson
One thing I miss about perl was the builtin $. variable that gets
increased after each call to perl's file iterator object. For example:
while ( my $line = <IN>) {
print "$. $line";
}
or, more perlish:
while (<IN>) {
print "$. $_";
}
Tracking line numbers is such a common thing to do when parsing files
that it makes sense for there to be a builtin for it.
Is there an equivalent construct in python? Or are people doing
something like this:
linenum = 0
for line in open('blah.txt'):
linenum += 1
print linenum, ". ", line
Better ideas are welcomed.
increased after each call to perl's file iterator object. For example:
while ( my $line = <IN>) {
print "$. $line";
}
or, more perlish:
while (<IN>) {
print "$. $_";
}
Tracking line numbers is such a common thing to do when parsing files
that it makes sense for there to be a builtin for it.
Is there an equivalent construct in python? Or are people doing
something like this:
linenum = 0
for line in open('blah.txt'):
linenum += 1
print linenum, ". ", line
Better ideas are welcomed.