Nп/п : 4 из 100
 От   : Dom Grigonis                        2:5075/128        25 сен 23 17:23:52
 К    : All                                                   25 сен 23 17:27:02
 Тема : Re: Using generator expressions
----------------------------------------------------------------------------------
                                                                                 
@MSGID:
<mailman.339.1695651836.23016.python-list@python.org> cc615bf8
@REPLY: <19E81B1D-A7FE-4B54-93A9-2F1DB6CEBBA1@gmail.com>
82c2a3d9
@REPLYADDR Dom Grigonis <dom.grigonis@gmail.com>
@REPLYTO 2:5075/128 Dom Grigonis
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID:
<mailman.339.1695651836.23016.python-list@python.org>
@RFC-References:
<CAApdmf1h9Brwre5CQGWKUEzbogdjsOettXp1BdOGHy+x6v7-wA@mail.gmail.com> <19E81B1D-A7FE-4B54-93A9-2F1DB6CEBBA1@gmail.com>
@TZUTC: 0300
@TID: FIDOGATE-5.12-ge4e8b94
y = test1(*[a for a in st])
y = test1(*st)
Maybe any of these would be ok for you?

Regards,
DG


 > On 25 Sep 2023, at 17:15, Jonathan Gossage via Python-list
<python-list@python.org> wrote:

> I am having a problem using generator expressions to supply the arguments
> for a class instance initialization. The following example shows the
> problem:

> class test1(object):
>    def   init  (self, a, b):

>>        self.name = a

>        self.value = b
> st = `Programming Renaissance, Any`.split(`, `)
> y = test1(a for a in st)
> print(f`Object values are: {y. a}, {y. b}`)

> I would expect to get the values from the list generated by splitting the
> string passed in as arguments to the new instance of test1, but instead
> I get the generator expression by itself as a generator object. The
> generator
> expression is treated like a passive object instead of being run. If I had
> wanted to pass the generator expression itself, I would have expected to
> have
> to use parentheses around the generator expression. Any suggestions on how
> to
> get the generator expression to run?
> If I change the definition of the input arguments to *args I can capture the
> arguments within   init   but it is verbose and ugly. Also, I could accept
> the
> arguments from a Sequence and extract the Sequence members into the class
> values. I would prefer my solution if I could get it to work.
> Note that I tried generator expressions both inside parentheses and not,
> without success.

> -- 
> Jonathan Gossage
> -- 
https://mail.python.org/mailman/listinfo/python-list

--- Apple Mail (2.3654.120.0.1.15)
 * Origin: usenet.network (2:5075/128)
SEEN-BY: 50/109 301/1 467/888 4500/1 5000/111
5001/100 5005/49 5020/715 830
SEEN-BY: 5020/848 1042 4441 12000 5030/49 1081
5054/8 5061/133 5075/128
SEEN-BY: 5080/102 5083/1 444
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх