Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.python > #5536

Re: [Python-de] Argumente in Python-C-Extension parsen

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Stefan Behnel <python-de@behnel.de>
Newsgroups de.comp.lang.python
Subject Re: [Python-de] Argumente in Python-C-Extension parsen
Date Tue, 27 Aug 2019 19:18:22 +0200
Lines 40
Message-ID <mailman.48.1566926494.30344.python-de@python.org> (permalink)
References <bbae8f87-a8cb-442d-ac71-7b8cddf41f8f@googlegroups.com> <57c6c604-95be-484f-6236-353d82d17682@behnel.de>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de y0Uq6qtzBezWDrO7wavItAqLniQq+GJ3gbuWC0rFkuSg==
Return-Path <python-de@behnel.de>
X-Original-To python-de@python.org
Delivered-To python-de@mail.python.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; t=1566926487; s=strato-dkim-0002; d=behnel.de; h=In-Reply-To:Date:Message-ID:From:References:To:Subject: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=C+opZAUk8E8BspqniWA1TTKs309k5WDMeugKPDtrQH8=; b=bkUta3pWObpTF5H2DUbbP/BigtHC857czlixXUXoFRsazERxC0f3N2X0Ic89Hlgz/h 0mVJrdFnH+gqh3iLwTrKPEc2PbDRYP9yUVPvCs9jSrT1ONobSBjs4KgjupIF/1urL9Px 2tyCMiNjBLo7FcqhfeqEJVHyYHeYeYnOnkzOVK3K8EeXfRfhFybtOf0aNXc+cP6Codpb hwcSqsM5+qMGqVP9HZIQvFX4TPfFXE3wYGlCcPPDZKpcmwsj7cDXJWS60w4eA/LZXXSW 2uqeiRALwIiFAEobCuO9QsbymxOSzMbLPzrLHv1iWbPbrG/zsRRc3NMYfo9ej+VLUhme UXZQ==
X-RZG-AUTH ":E1MMdFW4b++AXZOTwA41DOYM0Dv9LNWvavC/fJZ6Wfgmp/Lh1ANWCRaaq2R1hCooD/t2Vl9QaFHh38sJGCJu0nqS0iI1gBy4Wj8LVlpcjbXQEUY="
X-RZG-CLASS-ID mo00
Openpgp preference=signencrypt
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0
In-Reply-To <bbae8f87-a8cb-442d-ac71-7b8cddf41f8f@googlegroups.com>
Content-Language de-DE
X-BeenThere python-de@python.org
X-Mailman-Version 2.1.29
Precedence list
List-Id Die Deutsche Python Mailingliste <python-de.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-de>, <mailto:python-de-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-de/>
List-Post <mailto:python-de@python.org>
List-Help <mailto:python-de-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-de>, <mailto:python-de-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <57c6c604-95be-484f-6236-353d82d17682@behnel.de>
X-Mailman-Original-References <bbae8f87-a8cb-442d-ac71-7b8cddf41f8f@googlegroups.com>
Xref csiph.com de.comp.lang.python:5536

Show key headers only | View raw


Guenther Sohler schrieb am 27.08.19 um 09:56:
> Derzeit bin Ich dabei, in einer C-Extension Übergabeparameter zu extrahieren.
> Leider ist das Argument kein einfaches Int oder String, sondern eine Klasse,
> die von object abgeleitet ist und die passende Doku habe ich auch noch nicht erkannt/gefunden.
> 
> 
> class MyClass(object):
>     def __init__(self):
>        self.value1=1
>        self.value2=[2,3]
>        self.value3=Subclass()
> 
> 
> Angefangen habe ich mit 
> 
> if (!PyArg_ParseTuple(args, "OO",&arg1, &arg2)) {
>     return NULL;
> }
> 
> Aber wie kann ich nun aus arg1 die value1, value2, und  value3 extrahieren oder überhaupt herausfinden, welche keys es gibt ?

Ganz ehrlich: mach's nicht in C. Wenn du irgendwie noch Einfluss nehmen
kannst auf die Wahl der Mittel in deinem Projekt, schreib es statt dessen
in Cython. Das nimmt dir diesen ganzen Mist ab, generiert dafür auch noch
schnelleren Code, und hilft dir außerdem dabei, dass dein Modul in
zukünftigen Pythonversionen weiter funktioniert, ohne dass du am C-Code
herumfrickeln musst.

https://cython.org/

Da schreibst du dann einfach

    def mach_was_mit_myclass(arg1, arg2):
        print(dir(arg1))
        return arg1.value1 + arg2.value1

und Cython generiert fröhlich den C-Code, der deine MyClass Objekte
akzeptiert und verarbeitet.

Stefan

Back to de.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Argumente in Python-C-Extension parsen Guenther Sohler <guenther.sohler@gmail.com> - 2019-08-27 00:56 -0700
  Re: [Python-de] Argumente in Python-C-Extension parsen Stefan Behnel <python-de@behnel.de> - 2019-08-27 19:18 +0200
    Re: [Python-de] Argumente in Python-C-Extension parsen Guenther Sohler <guenther.sohler@gmail.com> - 2019-08-28 22:45 -0700
      Re: [Python-de] Argumente in Python-C-Extension parsen Hartmut Goebel <h.goebel@goebel-consult.de> - 2019-08-29 08:47 +0200

csiph-web