how to deepcopy a slice object?

Simon Forman rogue_pedro at yahoo.com
Tue Aug 15 05:11:27 EDT 2006


Alexandre Guimond wrote:
> Hi all,
>
> i'm trying to deepcopy a slice object but i get the following error.
> Does anyone know a workaround?
>
> ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
> Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)]
> on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import copy
> >>> copy.deepcopy( slice( 1, 10, 2 ) )
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "C:\Program Files\Python\lib\copy.py", line 204, in deepcopy
>     y = _reconstruct(x, rv, 1, memo)
>   File "C:\Program Files\Python\lib\copy.py", line 336, in _reconstruct
>     y = callable(*args)
>   File "C:\Program Files\Python\lib\copy_reg.py", line 92, in
> __newobj__
>     return cls.__new__(cls, *args)
> TypeError: slice expected at least 1 arguments, got 0
>
> thx for any help.

Why would you want to [deep]copy a slice object?

Anyway,  I don't know much about them, other than that they are
slightly unusual objects that play a very restricted role in python,
rather like the Ellipsis.

Workarounds are possible, I think, but really you almost certainly
don't need to do this.

Peace,
~Simon




More information about the Python-list mailing list