473,395 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

introspecting builtin functions/methods

Hi,

Does anyone know if and how I can, from within Python, read the
signatures of builtin methods/functions?

The following fails:
import inspect
inspect.getargspec(list.append) Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\inspect.py", line 655, in getargspec
raise TypeError('arg is not a Python function')
TypeError: arg is not a Python function inspect.getargspec(list.append.__call__) Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\inspect.py", line 655, in getargspec
raise TypeError('arg is not a Python function')
TypeError: arg is not a Python function

Also:
for elem in dir(list.append):

.... print elem
....
__call__
__class__
__delattr__
__doc__
__get__
__getattribute__
__hash__
__init__
__name__
__new__
__objclass__
__reduce__
__reduce_ex__
__repr__
__setattr__
__str__

gives no clue.

TIA, with my best regards,
G. Rodrigues
Jul 18 '05 #1
3 2897
On Tue, Dec 16, 2003 at 03:56:45PM +0000, Gon?alo Rodrigues wrote:
Hi,

Does anyone know if and how I can, from within Python, read the
signatures of builtin methods/functions?


The signatures for builtins are not available via any of the normal
introspection routines. The way argument parsing works in C makes it so
that the expected arguments are not available anywhere (typically) except as
a string literal inside the function definition.

It would be pretty handy if this information was available, but I think
converting the existing code to make it available would be a herculean
effort.

Jp

Jul 18 '05 #2
Gonçalo Rodrigues wrote:
Does anyone know if and how I can, from within Python, read the
signatures of builtin methods/functions?


For methods/functions written in C, the signature is defined by a
string passed to an internal C function (ParseTuple). And functions
don't even have to use that function to process their arguments;
they can pull values right out of the argument tuple (or they can
use ParseTuple more than once, in order to support multiple calling
conventions).

I'd say your only hope is the doc string:
inspect.getdoc(list.append)

'L.append(object) -- append object to end'

</F>


Jul 18 '05 #3
On Tue, 2003-12-16 at 15:56, =?UNKNOWN?Q?Gon=E7alo?= Rodrigues wrote:
Hi,

Does anyone know if and how I can, from within Python, read the
signatures of builtin methods/functions?

The following fails:
import inspect
inspect.getargspec(list.append) Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\inspect.py", line 655, in getargspec
raise TypeError('arg is not a Python function')
TypeError: arg is not a Python function inspect.getargspec(list.append.__call__) Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\inspect.py", line 655, in getargspec
raise TypeError('arg is not a Python function')
TypeError: arg is not a Python function

Also:
for elem in dir(list.append): ... print elem
...
__call__
__class__
__delattr__
__doc__
__get__
__getattribute__
__hash__
__init__
__name__
__new__
__objclass__
__reduce__
__reduce_ex__
__repr__
__setattr__
__str__

gives no clue.

TIA, with my best regards,
G. Rodrigues

You mean something like:
list.append.__doc__ 'L.append(object) -- append object to end' list.count.__doc__

'L.count(value) -> integer -- return number of occurrences of value'

--
Martin Franklin <mf********@gatwick.westerngeco.slb.com>
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Blair Hall | last post by:
Can anyone please tell me how to correctly use a built in function when there is a function of the same name in local scope? Here is an example. Suppose the following is in myApply.py: def...
2
by: Jacek Generowicz | last post by:
Functions defined in Python have type types.FunctionType, and are descriptors whose __get__ method turns them into bound or unbound methods. Functions defined in extension modules have type...
10
by: Stefan Seefeld | last post by:
hi there, I'm trying to convert a tuple to a list, and get a 'TypeError: list objects are unhashable'. Can anybody enlighten me as to the possible causes for this ? Where does hashing come...
4
by: Mark Harrison | last post by:
What's a good document to read in order to understand some of python's introspective functions? I'm trying to recurse through a module and print information about its contents. dir() does...
0
by: Joachim Dahl | last post by:
I would like to inherit the builtin array class and write som extension methods in C. Other people have suggested that I use numarray for that, but all I want is a simple continuous C array of...
1
by: barnesc | last post by:
Hi again, Since my linear algebra library appears not to serve any practical need (I found cgkit, and that works better for me), I've gotten bored and went back to one of my other projects:...
0
by: nejucomo | last post by:
Hi folks, Quick Synopsis: A test script demonstrates a memory leak when I use pythonic extensions of my builtin types, but if I use the builtin types themselves there is no memory leak. ...
20
by: Ari Krupnik | last post by:
scripts can add methods to the prototypes of builtin objects in JaavScript. I can assign functions to String.prototype.*, for instance. I want to add a method to Node, but when I try to execute...
23
by: =?ISO-8859-1?Q?Sch=FCle_Daniel?= | last post by:
Hello, lst = list((1,2,3)) lst = t = tupel((1,2,3)) t = (1,2,3) s = set((1,2,3)) s = ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.