Python to Perl Conversions

Robert Kern kernr at mail.ncifcrf.gov
Fri Aug 20 01:10:57 EDT 1999


On Fri, 20 Aug 1999 00:27:48 -0500, "Gordon McMillan"
<gmcm at hypernet.com> wrote:

>Couple comments -
>
>Tom Christiansen wrote:
>>                                 Yes, slices in python don't include
>>                                 the termination point.
>
>This might be a surprise if you're not used to it, but it turns out 
>to be very nice. Basically any way of expressing a range will result 
>in something that includes the left hand side, but excludes the right 
>hand. So when you're slicing, chopping up, inserting... you (almost) 
>never have to use "i-1".

It also means that len(seq[start:end]) == end - start.  It is also
convenient when using negative indices.

>> delattr(object,name)            n/a?  "delete named attribute from
>>                                 object".
>>                                 I suppose this might be
>>                                         delete $obj->{name}
>>                                 but that's pretty uncool to do it
>>                                 without asking the object.
>
>I'm not sure I've *ever* seen this used in Python. But it hints at a 
>very nice piece of syntactic sugaring you can do.

I've seen it used in wrapper classes where the classes' __delattr__
method needs to delete the data object's attribute.

[snip rest]

Robert Kern           |
----------------------|"In the fields of Hell where the grass grows high
This space            | Are the graves of dreams allowed to die."
intentionally         |           - Richard Harter
left blank.           |




More information about the Python-list mailing list