[Python C API] Two Different Questions :: PySlice_GetIndices(), copying an object.

Michael Hudson mwh at python.net
Sat Dec 7 10:33:20 EST 2002


iggeres at yahoo.es (Iggeres Bet) writes:

> Hi, 
> 
> I have two different questions about the C API on Python 2.2:
> 
> -1- Pyslice_GetIndices()

This function is useless.  Don't use it.  You might want to crib the
code I wrote from CVS; the function is called PySlice_GetIndicesEx and
has a slightly different signature.

> The definition of this function is:
> 
>    int PySlice GetIndices(PySliceObject *slice, int length, int
> *start, int
>    *stop, int *step)
> 
> I used it and passed the length of my "list", but the program gave me
> an exception because I didn't define the __len__ method in the class.
> It's correct? Why PySlice_GetIndices() calls the __len__ method when
> we need to pass the length explicitly?

I don't know what's happening here, but your analysis must be somewhat
wrong: PySlice_GetIndices never sees your "list", so can't be affected
by whether it implements __len__ or not.

> -2- Doing a shallow copy using the C API.
> 
> Is it possible to do a shallow copy of my object using the C API
> without using the copy module?

I don't think so.

> The object's class is defined on Python, not in C.

How would you do a shallow copy of it in Python?

Cheers,
M.

-- 
93. When someone says "I want a programming language in which I
    need only say what I wish done," give him a lollipop.
  -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html



More information about the Python-list mailing list