George Sakkis wrote:
> "Steven Bethard" wrote:
>
>>py> def bin(n):
>>... s = []
>>... def bin(n):
>>... if n == 0:
>>... yield s
>>... else:
>>... s.append(0)
>>... for s1 in bin(n - 1):
>>... yield s1
>>... s.p
Thanks a lot! This clarified [I think] my misunderstanding about yield,
and I also learned something about efficiency from George's code --
Thanks.
So, The function tel(aString) takes a string (or a number) that denote
a phone number, using digits or letters, and returns a generator for
the set of
"Steven Bethard" wrote:
> It would help if you explained what you expected. But here's code
that
> prints about the same as your non-generator function.
>
> py> def bin(n):
> ... s = []
> ... def bin(n):
> ... if n == 0:
> ... yield s
> ... else:
> ...
Mayer wrote:
> Hello:
>
> I need some help in understanding generators. I get them to work in
> simple cases, but the following example puzzles me. Consider the
> non-generator, "ordinary" procedure:
>
> def foo(n):
> s = []
> def foo(n):
> if n == 0:
> print s
>
In article <[EMAIL PROTECTED]>,
Andrea Griffini <[EMAIL PROTECTED]> wrote:
> Isn't the handling of StopIteration confined in the very moment of
> calling .next() ? This was what I expected... and from a simple test
> looks also what is happening...
Not if someone farther back in the call chain i
Christopher J. Bottaro wrote:
Wow, good advice. One question, how is the generator class implemented so
that if assigned to a tuple/list, it knows what to do? Is it possible to
overload the assignment operator kinda like in C++?
Tuple unpacking works with generators because generators implement t
Steven Bethard wrote:
> I don't do much with SQL/databases stuff, but if you really know the
> result will be a single row, you can take advantage of tuple unpacking
> and do something like:
>
> row, = obj.ExecSQLQuery(sql, args)
>
> or
>
> [row] = obj.ExecSQLQuery(sql, args)
>
> This has the a
David Eppstein wrote:
In article <[EMAIL PROTECTED]>,
"Robert Brewer" <[EMAIL PROTECTED]> wrote:
But I'm guessing that you can't index into a generator as if
it is a list.
row = obj.ExecSQLQuery(sql, args).next()
I've made it a policy in my own code to always surround explicit calls
to next()
Robert Brewer wrote:
Christopher J. Bottaro wrote:
I have a generator that works like this:
for row in obj.ExecSQLQuery(sql, args):
# process the row
Now there are some querys that run where I know the result
will only be a
single row. Is there anyway to get that single row from the genera
In article <[EMAIL PROTECTED]>,
"Robert Brewer" <[EMAIL PROTECTED]> wrote:
> > But I'm guessing that you can't index into a generator as if
> > it is a list.
>
> row = obj.ExecSQLQuery(sql, args).next()
I've made it a policy in my own code to always surround explicit calls
to next() with try
Christopher J. Bottaro wrote:
> I have a generator that works like this:
>
> for row in obj.ExecSQLQuery(sql, args):
> # process the row
>
> Now there are some querys that run where I know the result
> will only be a
> single row. Is there anyway to get that single row from the generato
11 matches
Mail list logo