FAQ
Hi Everyone,

I am writing a C extension and encountered two problems.

1) How can I include a description of the arguments? I can include a
description string. No problem. But whenever I say help(my_func) it
shows the arguments are "... ". However, if a function is defined in
python, I will definitely be able to see the parameters when I type
help(my_func).

2) How can I make the arguments less picky without writing a lot of
type conversion code? My function really needs a tuple as its
argument. For example, f( (1,2,3) ) would work. However, in order to
make it easy to use, I am thinking that it should be able to take a
list too. In other words, I want f( [1,2,3] ) to work also. I can
certainly check for the types in the code and deal with each
situation. But remember this is tedious to do in C. Is there any
better way to handle this?

Thanks,
cg

Search Discussions

  • Marc 'BlackJack' Rintsch at Jul 27, 2007 at 6:23 am

    On Fri, 27 Jul 2007 00:34:22 +0000, beginner wrote:

    2) How can I make the arguments less picky without writing a lot of
    type conversion code? My function really needs a tuple as its
    argument. For example, f( (1,2,3) ) would work. However, in order to
    make it easy to use, I am thinking that it should be able to take a
    list too. In other words, I want f( [1,2,3] ) to work also. I can
    certainly check for the types in the code and deal with each
    situation. But remember this is tedious to do in C. Is there any
    better way to handle this?
    The same way as you would do in Python: convert the argument into a tuple
    if you *really* need a tuple, or just use it as sequence or via iterator.
    And pay attention to errors of course.

    Ciao,
    Marc 'BlackJack' Rintsch

    From http Fri Jul 27 08:35:44 2007
    From: http (Paul Rubin)
    Date: 26 Jul 2007 23:35:44 -0700
    Subject: zip() function troubles
    References: <[email protected]>
    <f8bvik$vvp$03$[email protected]>
    Message-ID: <[email protected]>

    Peter Otten <__peter__ at web.de> writes:
    When you are allocating a lot of objects without releasing them the garbage
    collector kicks in to look for cycles. Try switching it off:
    I think that is the answer. The zip took almost 2 minutes without
    turning gc off, but takes 1.25 seconds with gc off. It turned a
    linear-time algorithm into a quadratic one. I think something is
    broken about a design where that can happen. Maybe Pypy will have
    a generational GC someday.
  • Beginner at Jul 27, 2007 at 9:19 pm

    On Jul 27, 1:23 am, Marc 'BlackJack' Rintsch wrote:
    On Fri, 27 Jul 2007 00:34:22 +0000, beginner wrote:
    2) How can I make the arguments less picky without writing a lot of
    type conversion code? My function really needs a tuple as its
    argument. For example, f( (1,2,3) ) would work. However, in order to
    make it easy to use, I am thinking that it should be able to take a
    list too. In other words, I want f( [1,2,3] ) to work also. I can
    certainly check for the types in the code and deal with each
    situation. But remember this is tedious to do in C. Is there any
    better way to handle this?
    The same way as you would do in Python: convert the argument into a tuple
    if you *really* need a tuple, or just use it as sequence or via iterator.
    And pay attention to errors of course.

    Ciao,
    Marc 'BlackJack' Rintsch
    That makes sense. Thanks.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJul 27, '07 at 12:34a
activeJul 27, '07 at 9:19p
posts3
users2
websitepython.org

People

Translate

site design / logo © 2023 Grokbase