On Wed, 05 Nov 2008 14:39:36 +1100, Ben Finney wrote:
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] writes:
On Wed, 05 Nov 2008 13:18:27 +1100, Ben Finney wrote:
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] writes:
Your example shows only that they're important for grouping the
On Tue, 04 Nov 2008 15:36:23 -0600, Larry Bates [EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] wrote:
tmallen:
I'm parsing some text files, and I want to strip blank lines in the
process. Is there a simpler way to do this than what I have here?
lines = filter(lambda line: len(line.strip()) 0,
Why do I feel like the coding style in Lutz' Programming Python is
very far from idiomatic Python? The content feels dated, and I find
that most answers that I get for Python questions use a different
style from the sort of code I see in this book.
Thomas
On Nov 5, 7:15 am, Jorgen Grahn [EMAIL
On Nov 5, 4:56 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
On Wed, 05 Nov 2008 14:39:36 +1100, Ben Finney wrote:
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] writes:
On Wed, 05 Nov 2008 13:18:27 +1100, Ben Finney wrote:
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] writes:
Your
Lie [EMAIL PROTECTED] writes:
What makes a generator expression is exp for var-or-tuple in
exp.
Parenthesis is generally required because without it, it's almost
impossible to differentiate it with the surrounding. But it is not
part of the formally required syntax.
... But *every*
On Wed, 05 Nov 2008 21:23:57 +, Arnaud Delobelle wrote:
Lie [EMAIL PROTECTED] writes:
What makes a generator expression is exp for var-or-tuple in
exp.
Parenthesis is generally required because without it, it's almost
impossible to differentiate it with the surrounding. But it is not
Arnaud Delobelle wrote:
Lie [EMAIL PROTECTED] writes:
What makes a generator expression is exp for var-or-tuple in
exp.
Parenthesis is generally required because without it, it's almost
impossible to differentiate it with the surrounding. But it is not
part of the formally required syntax.
Ben Finney wrote:
Falcolas writes:
Using the surrounding parentheses creates a generator object
No. Using the generator expression syntax creates a generator object.
Parentheses are irrelevant to whether the expression is a generator
expression. The parentheses merely group the expression
Steven D'Aprano [EMAIL PROTECTED] writes:
I'm surprised that nobody yet has RTFM:
http://docs.python.org/reference/expressions.html
generator_expression ::= ( expression genexpr_for )
...
The parentheses can be omitted on calls with only one argument.
It's a fair cop. Thanks for setting
I'm parsing some text files, and I want to strip blank lines in the
process. Is there a simpler way to do this than what I have here?
lines = filter(lambda line: len(line.strip()) 0, lines)
Thomas
--
http://mail.python.org/mailman/listinfo/python-list
tmallen:
I'm parsing some text files, and I want to strip blank lines in the
process. Is there a simpler way to do this than what I have here?
lines = filter(lambda line: len(line.strip()) 0, lines)
xlines = (line for line in open(filename) if line.strip())
Bye,
bearophile
--
[EMAIL PROTECTED] wrote:
tmallen:
I'm parsing some text files, and I want to strip blank lines in the
process. Is there a simpler way to do this than what I have here?
lines = filter(lambda line: len(line.strip()) 0, lines)
xlines = (line for line in open(filename) if line.strip())
Bye,
On Nov 4, 4:30 pm, [EMAIL PROTECTED] wrote:
tmallen:
I'm parsing some text files, and I want to strip blank lines in the
process. Is there a simpler way to do this than what I have here?
lines = filter(lambda line: len(line.strip()) 0, lines)
xlines = (line for line in open(filename) if
On Tue, 04 Nov 2008 13:27:00 -0800, tmallen wrote:
I'm parsing some text files, and I want to strip blank lines in the
process. Is there a simpler way to do this than what I have here?
lines = filter(lambda line: len(line.strip()) 0, lines)
Thomas
lines = filter(lambda line:
On Tue, Nov 4, 2008 at 2:30 PM, tmallen [EMAIL PROTECTED] wrote:
On Nov 4, 4:30 pm, [EMAIL PROTECTED] wrote:
tmallen:
I'm parsing some text files, and I want to strip blank lines in the
process. Is there a simpler way to do this than what I have here?
lines = filter(lambda line:
Larry Bates [EMAIL PROTECTED] writes:
[EMAIL PROTECTED] wrote:
xlines = (line for line in open(filename) if line.strip())
Of if you want to filter/loop at the same time, or if you don't want
all the lines in memory at the same time
The above implementation creates a generator; so it, too,
tmallen [EMAIL PROTECTED] writes:
On Nov 4, 4:30 pm, [EMAIL PROTECTED] wrote:
xlines = (line for line in open(filename) if line.strip())
I must be missing something:
xlines = (line for line in open(new.data) if line.strip())
xlines
generator object at 0x6b648
A generator
tmallen
I must be missing something:
xlines = (line for line in open(new.data) if line.strip())
xlines
generator object at 0x6b648
xlines.sort()
Traceback (most recent call last):
File stdin, line 1, in module
AttributeError: 'generator' object has no attribute 'sort'
What do you
On Nov 4, 3:30 pm, tmallen [EMAIL PROTECTED] wrote:
On Nov 4, 4:30 pm, [EMAIL PROTECTED] wrote:
tmallen:
I'm parsing some text files, and I want to strip blank lines in the
process. Is there a simpler way to do this than what I have here?
lines = filter(lambda line: len(line.strip())
Between this info and
http://www.python.org/doc/2.5.2/tut/node11.html#SECTION0011100
, I'm starting to understand how I'll use generators (I've seen them
mentioned before, but never used them knowingly).
list_o_lines = [line for line in open(filename) if line.strip()]
+1 for
Falcolas [EMAIL PROTECTED] writes:
Using the surrounding parentheses creates a generator object
No. Using the generator expression syntax creates a generator object.
Parentheses are irrelevant to whether the expression is a generator
expression. The parentheses merely group the expression from
tmallen wrote:
On Nov 4, 4:30 pm, [EMAIL PROTECTED] wrote:
tmallen:
I'm parsing some text files, and I want to strip blank lines in the
process. Is there a simpler way to do this than what I have here?
lines = filter(lambda line: len(line.strip()) 0, lines)
xlines = (line for line in
On Wed, 05 Nov 2008 12:06:42 +1100, Ben Finney wrote:
Falcolas [EMAIL PROTECTED] writes:
Using the surrounding parentheses creates a generator object
No. Using the generator expression syntax creates a generator object.
Parentheses are irrelevant to whether the expression is a generator
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] writes:
On Wed, 05 Nov 2008 12:06:42 +1100, Ben Finney wrote:
Falcolas [EMAIL PROTECTED] writes:
Using the surrounding parentheses creates a generator object
No. Using the generator expression syntax creates a generator
object.
Steve Holden [EMAIL PROTECTED] writes:
I think there'd be no advantage to a sort method on a generator,
since theoretically the last item could be the first required in the
sorted sequence
Worse, generators don't necessarily *have* a finite set of items, and
there's no way in general of
On Tue, 04 Nov 2008 20:25:09 -0500, Steve Holden wrote:
I think there'd be no advantage to a sort method on a generator, since
theoretically the last item could be the first required in the sorted
sequence, so it's necessary to hold all items in memory to ensure the
sort is correct. So
On Wed, 05 Nov 2008 13:18:27 +1100, Ben Finney wrote:
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] writes:
Your example shows only that they're important for grouping the
expression from surrounding syntax. As I said.
They are *not* important for making the expresison be a generator
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] writes:
On Wed, 05 Nov 2008 13:18:27 +1100, Ben Finney wrote:
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] writes:
Your example shows only that they're important for grouping the
expression from surrounding syntax. As I said.
They are
28 matches
Mail list logo