getting tut. example to work

alex23 wuwei23 at gmail.com
Tue Feb 24 05:07:53 CET 2009


On Feb 24, 1:31 pm, John Forse <johnfo... at talktalk.net> wrote:
> I'm trying some examples from the language ref sections on the site in  
> the process of learning some python in 3.0.1. I've tried to run both  
> of the samples below ,but the only printout is "generator object chain  
> at 0x11f4dc8" whether I use print() or not .

Yes, because you're creating a generator object but you're not
actually doing anything with it.

> How do I use the sample  
> to produce the expected printout a b c d e f.

Since you have a print inside 'chain', you should be able to get that
output by doing the following:

    list(chain('abc','def'))

Although I'd recommend removing the print from 'chain' and doing this
instead:

    for elem in chain('abc','def'):
        print elem



More information about the Python-list mailing list