Favorite non-python language trick?

Claudio Grondi claudio.grondi at freenet.de
Fri Jun 24 10:59:06 EDT 2005


I supose it will be very, very hard to find a trick
which turns out useful in Python. The current
set of features is from my point of view very
well designed out of the experience with many
other languages, so maybe you can use Python
as reference telling you which tricks are really
useful in programming and which are just bad,
non-Pythonic style.

At least I am myself out of ideas, else I had
proposed a PEP already, to get it or have
provided a module for it.

So feel free to poke around with Python.

if(not \
"--[[" == "--[["):
  # block of code
# --]]
as (already suggested) will also do the
trick with the block comment.

By the way,   I personally find
--[[
 good style comment block
]]--
or
[[--
 good style comment block
--]]
much more intuitive than
--[[
 bad style comment block
--]]

Claudio


"Joseph Garvin" <k04jg02 at kzoo.edu> schrieb im Newsbeitrag
news:mailman.840.1119607153.10512.python-list at python.org...
> Claudio Grondi wrote:
>
> >>And you can do block comments with --[[ and ---]].
> >>
> >>
> >
> >I am very happy not to have such "tricks" in Python.
> >
> >Any other (useful) suggestions?
> >
> >Claudio
> >
> >
> I'm glad and all that not everyone shares my enthusiasm over Lua's
> trick, and I'm glad that C/C++ can do it, but the original issue was
> non-python language tricks in general. Lets keep the thread on track.
>
> So far we've got lisp macros and a thousand response's to the lua trick.
> Anyone else have any actual non-python language tricks they like?
>
> Yeesh.
>
>
> >"Joseph Garvin" <k04jg02 at kzoo.edu> schrieb im Newsbeitrag
> >news:mailman.837.1119596150.10512.python-list at python.org...
> >
> >
> >>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 ---]].
> >>
> >>--[[
> >>hey
> >>this
> >>is
> >>a
> >>big
> >>comment
> >>--]]
> >>
> >>This syntax lets you do a nifty trick, where you can add or subtract a
> >>third dash to change whether or not code runs:
> >>
> >>--This code won't run because it's in a comment block
> >>--[[
> >>print(10)
> >>--]]
> >>
> >>--This code will, because the first two dashes make the rest a comment,
> >>breaking the block
> >>---[[
> >>print(10)
> >>--]]
> >>
> >>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 :)
> >>
> >>
> >
> >
> >
> >
>





More information about the Python-list mailing list