Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

VMS version 2.0 ==>


devel / comp.lang.python / Re: Problem slicing a list with the C API

SubjectAuthor
o Re: Problem slicing a list with the C APIChris Angelico

1
Re: Problem slicing a list with the C API

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Problem slicing a list with the C API
Date: Sun, 13 Mar 2022 10:36:02 +1100
Lines: 51
Message-ID: <mailman.289.1647128175.2329.python-list@python.org>
References: <My-05ih--3-2@tutanota.com>
<CAPTjJmrXVvdm5D-AKT_sj+2Mf2CxPUzmcbWTnQv6v9xeCzy+qQ@mail.gmail.com>
<My-77V7--3-2@tutanota.com>
<CAPTjJmrpq5nTAKAmRG7yt7tiHxruS8KJ9a1U35VeWvKEyvZ+LQ@mail.gmail.com>
<My-T6up--3-2@tutanota.com>
<CAPTjJmqunWCuHY3sqVffW2AmhZZZrGZuM6tuLTv22S51DaaUoA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de A6hkM/JvOMJAgjnOTS2fYQaciVvPqfmQyAne4sqPzggg==
Return-Path: <rosuav@gmail.com>
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=gmail.com header.i=@gmail.com header.b=f6v3lQtI;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(which': 0.04; '2022':
0.05; 'mar': 0.07; 'subject:API': 0.07; 'sun,': 0.07; 'itself,':
0.09; 'skip:x 10': 0.09; 'subject:list': 0.11; '(1,': 0.16;
'api.': 0.16; 'append': 0.16; 'behaviour': 0.16; 'chrisa': 0.16;
'corresponds': 0.16; 'easiest': 0.16; 'extending': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'iterate': 0.16; 'received:209.85.128.42': 0.16; 'received:mail-
wm1-f42.google.com': 0.16; 'tuple': 0.16; 'tuples': 0.16;
'tuples.': 0.16; 'want,': 0.16; 'wrote:': 0.16; 'api': 0.17;
'probably': 0.17; 'to:addr:python-list': 0.20; 'list,': 0.24;
'python,': 0.25; 'tried': 0.26; 'object': 0.26; 'suspect': 0.26;
'done': 0.28; '>>>': 0.28; 'takes': 0.31; "doesn't": 0.32;
'elements': 0.32; 'said,': 0.32; 'message-id:@mail.gmail.com':
0.32; 'but': 0.32; 'there': 0.33; 'focus': 0.33; 'work.': 0.34;
'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'question.': 0.35; 'from:addr:gmail.com': 0.35; 'received:209.85':
0.37; 'way': 0.38; 'received:209': 0.39; 'quite': 0.39; 'added':
0.39; 'adding': 0.39; 'list': 0.39; 'something': 0.40; 'want':
0.40; 'should': 0.40; 'tell': 0.60; 'method': 0.61; 'extend':
0.64; 'your': 0.64; 'right': 0.68; 'adds': 0.69; 'sequence': 0.69;
"you'll": 0.73; '(that': 0.84; 'comments,': 0.84; 'itself.': 0.84;
'method,': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:content-transfer-encoding;
bh=1Ls7viCIbC4zMmzQsKjjJ1ysLgpUvYczJY4TnRkso7o=;
b=f6v3lQtIt8xSRccWrd2xaEuuJIwY18eo6kLLwGjMKXB3OV5fsQ7XY4DD0vSZFVNIO1
nJ/ut2vfjfXnttZSK1aA4SUOv/avmFOgZW6laMnxcuremip++T14Zuhd3cFP1XDzPnH3
JhlojQVoxSrNp73HL9IFEVw3JT4TisyahatBkS9dl6Gi+hwoBLRtlJu4NPWnxhAUp8fu
MswQaNkdqDvLGKThqpkDXAVbOXHG1ELzwAED+KXnDdAfH1kknI5ya01Alus4tMESvCbj
dToF6pjHRLlcjyIN4B7FynPqsuRIkeUBL8q+OPttVuhF0OVYRif+xbweE0RCfIsJgGHt
eUaw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:content-transfer-encoding;
bh=1Ls7viCIbC4zMmzQsKjjJ1ysLgpUvYczJY4TnRkso7o=;
b=TxFkZ1CxTl/NDNOCDWh+VKS8D80wPGjSIgGYLcq38Ap6zaf4oJYEEBNR4TBMSAwFbj
T/SENghZ5rEZR4AvpB3q/ZF77FkMop2PB+F1dFBccBUcPDOa6vhe5coMYPnYnwbx44ZD
TNjTIle1xtgmZMtJIXr5yVLwaMjLW+zIkkKw5cr4EmGqxikLnNh+Z7uOQNmslDa4E4Ro
J1FSmgMNfE8H3nBKXt8jr8G2s7SoDQLLRsCp4qkz8gtAj79HBei5W7QlwkRoTBHGNdXl
I/qe5PmVZAaSTFBdH5F/EuseH4JsBgGlpcWr4kKuYmA+JxKX2+VKa+u4ZyWNzaptH7xO
UtnQ==
X-Gm-Message-State: AOAM532MaSWbIPOrWwzVYfsl3s4bj6vuqpASy4xN6WHR0+xWb+gpvwoM
ozSb3WsdG3ydUkHywUOJ8oiYPF4hf3Y2gYIc5BeOFTG2OVU=
X-Google-Smtp-Source: ABdhPJws1CRrJp0H7i2utniciJXgIoEXLGJdHs9Gs+LqNdUKqfiZr+/EYnzgIxDChD4tVFwSxAaS10hk83dGDa6kPq8=
X-Received: by 2002:a05:600c:4f0e:b0:389:eb27:581f with SMTP id
l14-20020a05600c4f0e00b00389eb27581fmr7815831wmq.132.1647128173113; Sat, 12
Mar 2022 15:36:13 -0800 (PST)
In-Reply-To: <My-T6up--3-2@tutanota.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: <CAPTjJmqunWCuHY3sqVffW2AmhZZZrGZuM6tuLTv22S51DaaUoA@mail.gmail.com>
X-Mailman-Original-References: <My-05ih--3-2@tutanota.com>
<CAPTjJmrXVvdm5D-AKT_sj+2Mf2CxPUzmcbWTnQv6v9xeCzy+qQ@mail.gmail.com>
<My-77V7--3-2@tutanota.com>
<CAPTjJmrpq5nTAKAmRG7yt7tiHxruS8KJ9a1U35VeWvKEyvZ+LQ@mail.gmail.com>
<My-T6up--3-2@tutanota.com>
 by: Chris Angelico - Sat, 12 Mar 2022 23:36 UTC

On Sun, 13 Mar 2022 at 10:30, Jen Kris <jenkris@tutanota.com> wrote:
>
>
> Chris, you were right to focus on the list pDictData itself. As I said, that is a list of 2-tuples, but I added each of the 2-tuples with PyList_Append, but you can only append a tuple to a list with the extend method. However, there is no append method in the C API as far as I can tell -- hence pDictData is empty. I tried with PyList_SetItem but that doesn't work. Do you know of way to "extend" a list in the C API.
>

Hmm. Not entirely sure I understand the question.

In Python, a list has an append method, which takes any object (which
may be a tuple) and adds that object to the end of the list:

>>> x = ["spam", "ham"]
>>> x.append((1,2))
>>> x
['spam', 'ham', (1, 2)]

A list also has an extend method, which takes any sequence (that also
includes tuples), and adds *the elements from it* to the end of the
list:

>>> x = ["spam", "ham"]
>>> x.extend((1,2))
>>> x
['spam', 'ham', 1, 2]

The append method corresponds to PyList_Append, as you mentioned. It
should be quite happy to append a tuple, and will add the tuple
itself, not the contents of it. So when you iterate over the list,
you'll get tuples.

Extending a list can be done with the sequence API. In Python, you can
write extend() as +=, indicating that you're adding something onto the
end:

>>> x = ["spam", "ham"]
>>> x += (1, 2)
>>> x
['spam', 'ham', 1, 2]

This corresponds to PySequence_InPlaceConcat, so if that's the
behaviour you want, that would be the easiest way to do it.

Based on your other comments, I would suspect that appending the
tuples is probably what you want here?

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor