Last value of yield statement

Shriphani shriphanip at gmail.com
Wed Oct 10 13:42:00 CEST 2007


On Oct 10, 4:05 pm, John Machin <sjmac... at lexicon.net> wrote:
> On 10/10/2007 8:19 PM, Shriphani wrote:
>
>
>
> > Hello all,
>
> > Let us say I have a function like this:
>
> > def efficientFiller(file):
> >         worthless_list = []
> >         pot_file = open(file,'r')
> >         pot_file_text = pot_file.readlines()
> >         for line in pot_file_text:
> >                 if line.find("msgid") != -1:
> >                         message_id = shlex.split(line)[1]
> >                         if message_id in dictionary:
> >                                 number = pot_file_text.index(line)
> >                                 corresponding_crap =
> > dictionary.get(message_id)
> >                                 final_string = 'msgstr' + " " + '"' +
> > corresponding_crap + '"' + '\n'
> >                                 pot_file_text[number+1] = final_string
> >                                 yield pot_file_text
>
> > efficient_filler =  efficientFiller("libexo-0.3.pot")
> > new_list = list(efficient_filler)
> > print new_list
>
> > I want to plainly get the last value the yield statement generates.
> > How can I go about doing this please?
>
> I don't think that 'efficient' and 'plainly' mean what you think they
> mean. However to answer your question:
>
>      new_list[-1] if new_list else None
>
> BTW I get the impression that the yield statement yields the whole
> pot_file_text list each time, so that new_list will be a list of lists;
> is that intentional?

Hello again,
I am sorry for having made that extra post and should have seen that
the solution I wanted was posted here. Anyway thanks a lot

Regards,
Shriphani Palakodety




More information about the Python-list mailing list