paul at prescod.net
Tue Jun 29 18:20:25 CEST 1999
Reuben Sumner wrote:
> How can I do the equivalent of a PySequence_Check in Python?
> GvR told me that the question was illdefined (if I explained it correctly)
> and to ask here.
> What am I missing? I have a nested structure of lists and tuple and I
> just want to know when I have bottomed out. I can check for tuple or
> list indivually but that is ugly and inflexible. I could just try
> indexing and see if there was an exception but that is not much better.
This latter is probably our best bet. Python in general has no way of
declaring that an object acts as a sequence or mapping. Therefore there
can be no way of querying whether an object acts as a sequence or
mapping. In general, Python has no way of declaring that an object "acts
as" anything at all (other examples would include a set, a widget, a web
browser). There is no concept of interface or protocol except in the C
API. I think that the goal is to define the concept in general before
applying it specifically to sequences, mappings, file objects and other
My discussion with Guido on this issue began here:
<Pine.SUN.3.91.980824165825.9662F-100000 at cito.uwaterloo.ca>
or you can do a deja search with "IsMappingType"
There are some tricky issues about what this interface stuff all means in
a dynamically typed language.
The constant re-occurence of discussions like this have lead to the
development of a special interest group:
Paul Prescod - ISOGEN Consulting Engineer speaking for only himself
"The new revolutionaries believe the time has come for an aggressive
move against our oppressors. We have established a solid beachhead
on Friday. We now intend to fight vigorously for 'casual Thursdays.'
-- who says America's revolutionary spirit is dead?
More information about the Python-list