Favorite non-python language trick?
Roel Schroeven
rschroev_nospam_ml at fastmail.fm
Fri Jun 24 05:44:45 EDT 2005
Joseph Garvin wrote:
> As someone who learned C first, when I came to Python everytime I read
> about a new feature it was like, "Whoa! I can do that?!" Slicing, dir(),
> getattr/setattr, the % operator, all of this was very different from C.
>
> I'm curious -- what is everyone's favorite trick from a non-python
> language? And -- why isn't it in Python?
>
> Here's my current candidate:
>
> So the other day I was looking at the language Lua. In Lua, you make a
> line a comment with two dashes:
>
> -- hey, this is a comment.
>
> And you can do block comments with --[[ and ---]].
>
> This syntax lets you do a nifty trick, where you can add or subtract a
> third dash to change whether or not code runs:
>
> So you can change whether or not code is commented out just by adding a
> dash. This is much nicer than in C or Python having to get rid of """ or
> /* and */. Of course, the IDE can compensate. But it's still neat :)
Off topic, but in C or C++ it's easier to do it using
#ifdef 1
...
#endif
Then you just have to change the 1 into 0 or vice versa. It also
prevents problems with nested comments.
Back on topic, the lack of such a construct in Python is actually one of
the very few things that bother me in the language. There are
work-arounds, of course; idle, for example, has a feature that prepends
a # to every line in the selection, or removes the # again. But not all
editors have such a feature, and even if they have it I still need to
select the block of code every time. Not that big a deal though.
--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton
Roel Schroeven
More information about the Python-list
mailing list