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


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

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

X-Received by 2002:a37:6007:: with SMTP id u7mr7665050qkb.92.1567057512456; Wed, 28 Aug 2019 22:45:12 -0700 (PDT)
X-Received by 2002:a05:620a:10a1:: with SMTP id h1mr187853qkk.186.1567057512254; Wed, 28 Aug 2019 22:45:12 -0700 (PDT)
Path csiph.com!xmission!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!a13no4944439qtd.0!news-out.google.com!d29ni3369qtg.1!nntp.google.com!a13no4944428qtd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups de.comp.lang.python
Date Wed, 28 Aug 2019 22:45:11 -0700 (PDT)
In-Reply-To <mailman.48.1566926494.30344.python-de@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=90.152.173.98; posting-account=2398iQoAAADZ5r0xIf0FAeS1GxPIO-SX
NNTP-Posting-Host 90.152.173.98
References <bbae8f87-a8cb-442d-ac71-7b8cddf41f8f@googlegroups.com> <57c6c604-95be-484f-6236-353d82d17682@behnel.de> <mailman.48.1566926494.30344.python-de@python.org>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <8100ec58-6024-40a8-9567-6780a2b82cba@googlegroups.com> (permalink)
Subject Re: [Python-de] Argumente in Python-C-Extension parsen
From Guenther Sohler <guenther.sohler@gmail.com>
Injection-Date Thu, 29 Aug 2019 05:45:12 +0000
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding quoted-printable
Lines 59
Xref csiph.com de.comp.lang.python:5538

Show key headers only | View raw


Am Dienstag, 27. August 2019 19:21:36 UTC+2 schrieb Stefan Behnel:
> 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

Hallo Stefan,

Danke für die Hilfestellung.

ich habe jetzt ein kleines Testprogramm geschrieben, das meine Klasse einbindet und testhalber Etwas mit ihr macht.

Zwar hat cython fröhlich Code daraus gemacht, der auch kompiliert.
Allerdings ist der Code so kryptrisch, daß Ich es bis jetzt nicht geschafft habe, die relevanten Kommandos raus zu kopieren.

Gibts denn keine andere Lösung ?

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