Problem slicing a list with the C API

Chris Angelico rosuav at gmail.com
Sat Mar 12 18:50:26 EST 2022


On Sun, 13 Mar 2022 at 10:41, Jen Kris <jenkris at tutanota.com> wrote:
>
>
> 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.
>

Ah. I guess that's one of the fundamental vulnerabilities of Stack
Overflow: people answer the question in front of them, which isn't
necessarily the question that YOU are trying to answer. Sometimes, the
solutions can be misleading, because your goal is actually different.

Fortunately, tuples in Python are objects, like every other value.
It's extremely convenient - to word that another way, it's extremely
INconvenient to work with a language where that isn't the case, and
you need to work differently depending on whether you're using
integers or strings. This is how you work with a trie (actually an
artifact name now, as it's implemented with a hashtable) in SourceMod
- this is the equivalent of dictionary subscript assignment:

https://sm.alliedmods.net/new-api/adt_trie/SetTrieValue
- works for integers, floats, and handles (which are integers)

https://sm.alliedmods.net/new-api/adt_trie/SetTrieString
- works for strings

Yup, it's annoying :)

ChrisA


More information about the Python-list mailing list