Download Current Version: xlist.py (2005-06-11)

This is an odd little utility that is meant to kinda sorta extend Python's syntax for defining lists. Basically, I wanted to be able to define lists using the Pythonic idea of indentation rather than begin/end markers. This, in turn, was to simplify the usage of my PyTag module.

Basically, I want to be able to do this:

a=[
stuff
more_stuff
even[
more
stuff
and[
more
stuff

And have that be interpretted the same as

a=[
stuff,
more_stuff,
even[
more,
stuff,
and[
more,
],
stuff,
]

And that's what this function does. At the moment it's pretty dumb and would be confused by a lot of things, so I really wouldn't recommend using it for anything too complicated.

Standard usage would be something like:

from xlist import xlist

exec(xlist("""
a=[
stuff
more_stuff
even[
more
stuff
and[
more
stuff
"""

I think it would be possible to do it right, but I'd have to sit down and think about it a bit more. For now, this code works for the simple cases.

History