Tom Plunket wrote:

> For enrichment purposes, is there a way to do this sort of thing with
> a generator?  E.g. something like:
> 
> def SentenceGenerator():
>    words = ['I', 'have', 'been', 'to', 'the', 'fair']
>    for w in words: 
>       yield w
> 
> message = "%s %s %s %s"
> 
> print message % SentenceGenerator()
> 
> (I ask because the above doesn't work)?

Use tuple(SentenceGenerator()).  A generator is just another object, so 
using it with the % operator tries to substitute it at one value.  (Even 
with this fix, though, your message didn't have enough formatters.)

-- 
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   Human salvation lies in the hands of the creatively maladjusted.
    -- Dr. Martin Luther King, Jr.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to