Posted by bob on 2009/05/04 – 17:07
Filed under dev
Tagged as python
This is hardly interesting pressing news, but it’s left an impression on me, so I choose to share: In my tinkering with python, I’ve found the python console to be a priceless tool when helping to discover syntax. In this afternoon’s example, I was wondering about different cute ways to loop through lists, so I drop to a prompt, type python, hit enter, and:
>>> a = [1, 2, 3]
>>> a.append(4)
>>> print a
[1, 2, 3, 4]
>>> while 7 not in a:
... a.append(int(raw_input('append?')))
...
append?4
append?3
append?5
append?6
append?7
>>> print a
[1, 2, 3, 4, 4, 3, 5, 6, 7]
>>>
OK, that skips the step where I googled, saw an example, and then wanted to try it out in a simple cases to make sure I got it. But this still demonstrates the value, right?
Posted by bob on 2009/05/04 – 16:59
Filed under dev
Tagged as cute_design, python
I’ve been using python for some sysadmin tools lately, and thoroughly enjoyed python’s ability to invoke the future standards. Python’s PEP system (Python Enhancement Proposals) promotes a public forum for changes. I’m not familiar with the political process, but that’s soon on my to-investigate list.
While reading about a proposed enhancement to while loops (PEP 315 — Enhanced While Loop - enhancing to allow a do/while struct), I found a usage description.
Because of the new keyword "do", the statement
from __future__ import do_while
will initially be required to use the do-while form.
This allows you to beckon the Gods for a new version and use it, because it’s even been thought of! Amazing. No, really, it allows them to add a new feature gracefully. Announce a change and allow the use of it through a special format that will be forwards compatible.