Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Help fight continental drift.


devel / comp.lang.python / Re: Using generator expressions

SubjectAuthor
o Re: Using generator expressionsThomas Passin

1
Re: Using generator expressions

<mailman.340.1695654903.23016.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=28455&group=comp.lang.python#28455

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: list1@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Using generator expressions
Date: Mon, 25 Sep 2023 11:08:26 -0400
Lines: 46
Message-ID: <mailman.340.1695654903.23016.python-list@python.org>
References: <CAApdmf1h9Brwre5CQGWKUEzbogdjsOettXp1BdOGHy+x6v7-wA@mail.gmail.com>
<b2ba8f1e-1934-14ff-bebb-a0703f0e5eb1@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 0AsgaStqZUU8nZh6AwIzrATxD2LhB8vvqsVEoxlArNxg==
Cancel-Lock: sha1:uGyA9zkhb3UEDfaABa01G+ojljA= sha256:S7RFZijlqcqo/ID8b9Iyuz5Jk2OI7fhH0fLXPURZLmI=
Return-Path: <list1@tompassin.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=tompassin.net header.i=@tompassin.net header.b=kGBs/LYO;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'generated': 0.03;
'argument': 0.04; 'def': 0.04; 'run.': 0.05; 'variable': 0.05;
'string': 0.07; 'expression': 0.09; 'itself,': 0.09; 'treated':
0.09; 'values.': 0.09; 'arguments': 0.16; 'expressions': 0.16;
'instance': 0.16; 'received:10.0.0': 0.16;
'received:23.83.209.151': 0.16; 'received:64.90': 0.16;
'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16;
'received:dreamhost.com': 0.16;
'received:quail.birch.relay.mailchannels.net': 0.16; 'self.name':
0.16; 'splitting': 0.16; 'verbose': 0.16; 'want,': 0.16; 'wrote:':
0.16; 'problem': 0.16; 'values': 0.17; 'instead': 0.17; 'figure':
0.19; 'to:addr:python-list': 0.20; 'input': 0.21; 'skip:_ 10':
0.22; 'list,': 0.24; 'tried': 0.26; 'object': 0.26; 'expect':
0.28; 'suggestions': 0.28; 'error': 0.29; 'header:User-Agent:1':
0.30; 'am,': 0.31; 'do.': 0.32; 'extract': 0.32; 'python-list':
0.32; 'received:10.0': 0.32; 'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'subject:Using': 0.32;
"wouldn't": 0.32; 'but': 0.32; 'there': 0.33; 'work.': 0.34;
'header:In-Reply-To:1': 0.34; 'following': 0.35; 'also,': 0.36;
'fix': 0.36; 'change': 0.36; 'using': 0.37; 'class': 0.37;
'could': 0.38; 'list': 0.39; 'use': 0.39; 'still': 0.40; 'both':
0.40; 'want': 0.40; 'should': 0.40; 'pass': 0.64; 'definition':
0.64; 'supply': 0.65; 'shows': 0.67; 'back': 0.67; 'accept': 0.67;
'header:Received:6': 0.67; 'received:64': 0.67; 'exactly': 0.68;
'generator': 0.69; 'sequence': 0.69; 'within': 0.69; 'names,':
0.81; 'capture': 0.84; 'passive': 0.84; 'strings': 0.84
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1695654507; a=rsa-sha256;
cv=none;
b=bcsGRbE8Cj5qXykVkMzoe+3R3yACIPXypYk3KxxKsdO12QbVhEsig92h9KXFz40//vnzLq
ZUPbU89mVLIHh9TsE4nY5EQIaoGt/BEW9JduBUXpEBoHNPq9BrCFstXBNUzb0ZQXK3hqFy
qw6sFrAV4j8mCIz1VY969qmESckN+1Tdm4T7mvUZV93WPxDMR9jNexA1fXXLGDXX5o4ypY
bZ5HQyQFSqmt0BW8/2CyWC3IA9YPmKtIXWkiFG76sMTUN/YTir8omMJYgBxTsL1S1oFaKZ
Mv6WdMZYgzmkA2BELF800WjYOgz1dPebzWYROdPEM3mfjjG2Z9/V4RpmUttOzg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1695654507;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=zZ6q/BvfVA5JM9LCBDvK5L2D3yxoYH9W/ylJnvmBRcQ=;
b=Jt5kz9r09eMJ8bzpanMM+1auZnfETpYjvYRNaFvz4w1Dw8h3915R4AQgWpqz5O9DA8sUL/
JuXrPkGSb0mQpc8G3wtkaUvaINVyLJZRJ669AZUDY9hV7yrTsEokviI2NIwEPh6exfi/rA
hCaLuyILzV6Hg8oFmTStkxYaDcuKDpNPVhuTsgpRDtyjzbXdEecbvcNNn2bBrTVy8l+WlX
fdbZgpYjlF/QlgXUgIQ8Yavd8JTnyM+ukkJXLvtW443Z3Yc5U8uwKBDTdx8i8IjwlVJn6q
uO/8DCjUpNvtDJu+pjO1C/ng/eM4BorJOHI47klARm6Y3ylIc53h0+3VyQJ87A==
ARC-Authentication-Results: i=1; rspamd-7c449d4847-pf2d9;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Eyes-Reaction: 2a060d8b085959d8_1695654507649_3526649787
X-MC-Loop-Signature: 1695654507649:902480755
X-MC-Ingress-Time: 1695654507649
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1695654507;
bh=zZ6q/BvfVA5JM9LCBDvK5L2D3yxoYH9W/ylJnvmBRcQ=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=kGBs/LYOVYc/uNL7X25XDrseFcZ34f3N/zdkn8PgT/a9YQTTmf16qrzqn9aNM4gzL
5NHtLRVNwFM6yVTPorYxgizIsSxsE1n22Sryek3e0NTCvJDtvJkISSydITbAkuI8T3
OaIlPnOb6LN4SC224fO2uSvN2nFKfPhridzZvRpB1SGT3dbQwnJRKwpKscwohV8ybe
JfomRz4rhvqCeT6TpWI8fi3wB8WEdCCZnRQ3V+duZZm8/OlRSxqsVXm8VW1O/omsyv
swmSma/cdojpW1sDf7vup2VGn+h5RZ+0EpAb5Elu82/IyFsf1824iJnuoxkzKoFu8x
ki++eZBHPezoA==
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Content-Language: en-US
In-Reply-To: <CAApdmf1h9Brwre5CQGWKUEzbogdjsOettXp1BdOGHy+x6v7-wA@mail.gmail.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <b2ba8f1e-1934-14ff-bebb-a0703f0e5eb1@tompassin.net>
X-Mailman-Original-References: <CAApdmf1h9Brwre5CQGWKUEzbogdjsOettXp1BdOGHy+x6v7-wA@mail.gmail.com>
 by: Thomas Passin - Mon, 25 Sep 2023 15:08 UTC

On 9/25/2023 10:15 AM, Jonathan Gossage via Python-list 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.
>

You should get an error at the y assignment. The argument of test1() is
a generator, which would get assigned to the "a" argument, and there
would be no "b" argument, which is an error.

In any event, even if this were to work as you want, it would only work
for strings that contain one comma. And you ask for values like y._a,
but y._a is never created, only y.a. If you did convert the generator
to a list, and if you fix the underscored variable names, it still
wouldn't work because the arguments don't expect a list.

Time to step back and figure out exactly what you actually want to do.


devel / comp.lang.python / Re: Using generator expressions

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor