Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

To invent, you need a good imagination and a pile of junk. -- Thomas Edison


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

SubjectAuthor
o Re: Problem slicing a list with the C APIJen Kris

1
Re: Problem slicing a list with the C API

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: jenk...@tutanota.com (Jen Kris)
Newsgroups: comp.lang.python
Subject: Re: Problem slicing a list with the C API
Date: Sun, 13 Mar 2022 00:41:31 +0100 (CET)
Lines: 71
Message-ID: <mailman.290.1647128494.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>
<My-VYHx--3-2@tutanota.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de j1yh28F3+txxleOJnyi4UgGb9celTdoPkG3h6KqDsnSg==
Return-Path: <jenkris@tutanota.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=tutanota.com header.i=@tutanota.com header.b=aafJgWsn;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
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; 'cc:addr
:python-list': 0.09; 'itself,': 0.09; 'list.\xc2\xa0': 0.09;
'skip:x 10': 0.09; 'subject:list': 0.11; 'url:mailman': 0.15;
'(1,': 0.16; '2022,': 0.16; '>>>>': 0.16; 'api.': 0.16; 'append':
0.16; 'behaviour': 0.16; 'cc:name:python list': 0.16; 'chrisa':
0.16; 'corresponds': 0.16; 'easiest': 0.16; 'extending': 0.16;
'iterate': 0.16; 'now.\xc2\xa0': 0.16; 'tuple': 0.16; 'tuples':
0.16; 'tuples.': 0.16; 'want,': 0.16; 'wrote:': 0.16; 'python':
0.16; 'api': 0.17; 'probably': 0.17; 'uses': 0.19;
'cc:addr:python.org': 0.20; 'code': 0.23; 'received:de': 0.23;
'list,': 0.24; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'python,': 0.25; 'url:listinfo': 0.25;
'cc:2**0': 0.25; 'url-ip:188.166/16': 0.25; 'tried': 0.26;
'object': 0.26; 'suspect': 0.26; 'done': 0.28; 'wrong': 0.28;
'takes': 0.31; 'url-ip:188/8': 0.31; "doesn't": 0.32; 'elements':
0.32; 'said,': 0.32; 'received:192.168.1': 0.32; 'but': 0.32;
"i'm": 0.33; "i'll": 0.33; 'there': 0.33; 'focus': 0.33; 'work.':
0.34; 'header:In-Reply-To:1': 0.34; 'question.': 0.35; 'posts':
0.36; 'received:192.168': 0.37; 'way': 0.38; 'thanks': 0.38;
'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; 'email': 0.63; '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; 'incorrect': 0.84; 'itself.':
0.84; 'method,': 0.84
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1647128491;
s=s1; d=tutanota.com;
h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:In-Reply-To:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender;
bh=Wz9lv/R/L6uMI9LHNmZcKIJnGSFXx2Q6QA3c7G+rS5I=;
b=aafJgWsnxovCW6qcxZ6PgD4xPWKkXD9PDwIkVKge9eQNkq0RiWaRaxRMBayieJUp
pfHZv6vWkladPPWm5F468mG7R9Wd7QcUhZ1723L5EddRhpMiE3zSVLklq4EHnrWJTZY
Rk6mx2tFaHNG18Dxl1i8EYeEbTg/YnFRW1F51B3rRBv+Cvh3nNfBbIO5WvU+zNow0kk
5B/Y1fKDaNF4ixVZQH48zBkxHvLGbHQkH6Uw976DxLOZ19J3o/s7QUGT+cHDi+VoOTG
z6Lou9tQY9jk0W/bQON6cq3pq1Fbx8ZOAmz5vol+iYVQXePyf23m05gSUE7kCrfGd+K
SoO68LJhHg==
In-Reply-To: <CAPTjJmqunWCuHY3sqVffW2AmhZZZrGZuM6tuLTv22S51DaaUoA@mail.gmail.com>
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
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: <My-VYHx--3-2@tutanota.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>
<CAPTjJmqunWCuHY3sqVffW2AmhZZZrGZuM6tuLTv22S51DaaUoA@mail.gmail.com>
 by: Jen Kris - Sat, 12 Mar 2022 23:41 UTC

Thanks for PySequence_InPlaceConcat, so when I need to extend I'll know what to use.  But my previous email was based on incorrect information from several SO posts that claimed only the extend method will work to add tuples to a list.  I found that's wrong -- even my own Python code uses the append method.  But my PyList_Append is not doing the job so that's where I'm looking now. 

Thanks very much for your reply.

Mar 12, 2022, 15:36 by rosuav@gmail.com:

> 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
> --
> https://mail.python.org/mailman/listinfo/python-list
>

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor