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


Groups > comp.lang.python > #37424

Re: Is PyArg_ParseTuple necessary to parse arguments?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'interpreter': 0.04; 'cpython': 0.05; 'arguments': 0.07; 'python': 0.09; '*args):': 0.09; 'arg': 0.09; 'commonly': 0.09; 'counting': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'runtime': 0.09; 'tuple': 0.09; 'def': 0.10; 'extensions': 0.13; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'python."': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'certainly': 0.17; 'else,': 0.17; 'pointer': 0.17; 'stefan': 0.17; 'appropriate': 0.20; 'putting': 0.20; 'written': 0.20; "i've": 0.23; 'external': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'common': 0.26; 'skip:m 30': 0.26; 'plain': 0.27; 'thoughts': 0.27; 'header:X-Complaints-To:1': 0.28; 'convert': 0.29; 'manual': 0.29; 'objects': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'saves': 0.30; 'code': 0.31; 'to:addr:python- list': 0.33; 'another': 0.33; 'subject:?': 0.35; 'similar': 0.35; 'something': 0.35; 'received:org': 0.36; 'should': 0.36; 'skip:p 20': 0.36; 'quite': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'object': 0.38; 'things': 0.38; 'nothing': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'email addr:gmail.com,': 0.65; 'received:87.139': 0.84; 'subject:necessary': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: Is PyArg_ParseTuple necessary to parse arguments?
Date Wed, 23 Jan 2013 08:50:23 +0100
References <a4d078cf-b670-46e2-9a52-dfb3d43a25a0@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host p578ba676.dip0.t-ipconnect.de
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2
In-Reply-To <a4d078cf-b670-46e2-9a52-dfb3d43a25a0@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.871.1358927435.2939.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1358927435 news.xs4all.nl 6985 [2001:888:2000:d::a6]:59207
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37424

Show key headers only | View raw


rahulgarg44@gmail.com, 22.01.2013 18:20:
> Or can I just loop through the argument tuple manually by using something like PyTuple_GET_ITEM(args,i), then putting manual code to convert the objects to appropriate C type?
> The use case is that I am interfacing Python with another interpreter and do not know the type and number of arguments till runtime :)

Just in case you're not aware of it, C extensions are quite commonly
written in Cython instead of C these days. I've used it for Lupa, for
example, which embeds the Lua(JIT) runtime in CPython. That should be quite
similar to what you're after. It certainly makes things a lot easier to write

  cdef class Wrapper:
      "Wraps an external object for usage in Python."

      cdef mylib.sometype* _wrapped_object  # pointer to external 'thing'

      def __call__(self, *args):
         mapped_args = malloc(len(args)*...)
         # ...
         for i, arg in enumerate(args):
             map_value_to_external(arg, mapped_args[i])
         # ...
         result = call_external(self._wrapped_object, mapped_args)
         return map_value_from_external(result)

than to do these things in plain C. If nothing else, it saves you from
having to put thoughts into reference counting and other common CPython
C-API pitfalls.

Stefan

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


Thread

Is PyArg_ParseTuple necessary to parse arguments? rahulgarg44@gmail.com - 2013-01-22 09:20 -0800
  Re: Is PyArg_ParseTuple necessary to parse arguments? dieter <dieter@handshake.de> - 2013-01-23 08:00 +0100
  Re: Is PyArg_ParseTuple necessary to parse arguments? Stefan Behnel <stefan_ml@behnel.de> - 2013-01-23 08:50 +0100

csiph-web