[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Why does Rect and Surface have copy method when copy exist in std-lib?



In the C code, rect.copy and surface.copy are equivalent to
rect.__copy__ and surface.__copy__. You may use copy.copy(rect) and
copy.copy(surface) in your code, but copy.copy will simply call
rect.__copy__ or surface.__copy__. By using rect.copy and surface.copy
rather than the standard library's copy.copy, your code will run
≈0.0001% faster.

For aesthetic reasons, you would use rect.copy and surface.copy rather
than rect.__copy__ and surface.__copy__ in your code.

Jason

On Mon, May 29, 2017 at 3:38 PM, Victor Blomqvist <vb@xxxxxxxx> wrote:
> Hello,
>
> Something I have been thinking about:
> Rect and Surface classes have their own copy methods. Why do they have that
> when there is a module called copy in the standard lib that can handle copy
> (with help)? The rect copy method was added in pygame 1.9 so it is fairly
> recent.
>
> http://pygame.org/docs/ref/rect.html#pygame.Rect.copy
> https://docs.python.org/2/library/copy.html
>
> Thanks for any insights!
> /Victor