More random python observations from a perl programmer

Jan Decaluwe jand at easics.be
Thu Aug 19 12:13:28 EDT 1999


Tom Christiansen wrote:
> 
> DISSIMILARITY:
>     Because there are no variable markers in Python, there are no
>     variable interpolation in strings.  That makes something like
>         print "this $x is $y here\n"
>     become in python
>         print "this %d is %d here\n" % (x, y)

However, if you "supply" a scope, e.g. using the vars() function,
you can say:

  print "this %(x)d is %(y)d here" % vars()

which lets you combine interpolation with formatting directives.

> GOTCHA: (medium)
>     All ranges are up to but *not including* that point.  So range(3)
>     is the list [0,1,2].  This is also true in slices, which is the
>     real gotcha part.  A slide t[2:5] does not include t[5] in it.

I always found this very strange. However, in practical use it turns
out to be often quite natural, for example:
   a[:5] returns 5 elements.

Exactly the same approach is used by the containers in C++'s STL
library, so I guess there must be some good theoretical arguments also.

-- 
Jan Decaluwe	       Easics              
Design Manager         System-on-Chip design services  
+32-16-395 600	       Interleuvenlaan 86, B-3001 Leuven, Belgium
mailto:jand at easics.be  http://www.easics.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2730 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-list/attachments/19990819/d97eae5e/attachment.bin>


More information about the Python-list mailing list