visual indentation
Hans Nowak
hans at zephyrfalcon.org
Fri Aug 22 15:13:26 EDT 2003
Hilbert wrote:
> Hello,
>
> I'm using python to output RIB streams for Renderman.
> The RIB stream is a bunch of statements which describes
> a 3d image. The Rib standard allows for blocks which we
> usually indent for better visualization for example:
>
> WorldBegin
> Color [1 1 1]
> Surface "constant"
> Sphere(1.0, -1.0, 1.0, 360)
> WorldEnd
>
> I'm using CGKit in python which has a Renderman binding,
> so to output the same RIB I'd write:
>
> RiWorldBegin()
> RiColor(1.0,1.0,1.0)
> RiSurface('constant')
> RiSphere(1.0,-1.0,1.0,360)
> RiWorldEnd()
>
> But I get an error, because python interprets my indentation
> as a block in the python code. So the only way to write this
> is without the indentation:
>
> RiWorldBegin()
> RiColor(1.0,1.0,1.0)
> RiSurface('constant')
> RiSphere(1.0,-1.0,1.0,360)
> RiWorldEnd()
>
> But this is a lot harder to read.
>
> Is there any way to use such "visual" indentation in python?
I can think of various ugly solutions, none of them very satisfying...
First, you can fake an indented block, e.g. like this:
RiWorldBegin()
if 1:
RiColor(1.0, 1.0, 1.0)
# etc...
RiWorldEnd()
Or you can put the function calls in a dummy list/tuple:
RiWorldBegin()
[
RiColor(1.0, 1.0, 1.0),
RiSurface('constant'),
RiSphere(1.0,-1.0,1.0,360),
]
RiWorldEnd()
Or you can put some dummy statements in front...
RiWorldBegin()
(); RiColor(1.0, 1.0, 1.0)
(); RiSurface('constant')
(); RiSphere(1.0,-1.0,1.0,360)
RiWorldEnd()
I warned you they were ugly... :-)
Maybe the best solution would be judicious use of comments, e.g.
RiWorldBegin()
#
RiColor(1.0, 1.0, 1.0)
RiSurface('constant')
RiSphere(1.0,-1.0,1.0,360)
#
RiWorldEnd()
This doesn't give you indentation, but at least the statements in the "block"
stand out more.
But maybe somebody else has a better solution...?
--
Hans (hans at zephyrfalcon.org)
http://zephyrfalcon.org/
More information about the Python-list
mailing list