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

Iggeres Bet iggeres at yahoo.es
Sun Dec 8 17:52:07 EST 2002


Michael Hudson <mwh at python.net> wrote in message news:<7h3d6odkfnj.fsf at pc150.maths.bris.ac.uk>...
> > 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.

I can check it deeper, and I will change to the new function. 

> 
> > -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?

So, I need to import copy and call copy to do it.
Nobody needed a faster shallow copy using the C API?


Cheers
Iggeres



More information about the Python-list mailing list