FAQ
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?

Thanks,
Hilbert

hilbert at panka.com

Search Discussions

  • Achrist at Aug 22, 2003 at 6:28 pm

    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?
    If the code is purely sequential, how about something like this:

    import string
    def RunTheseStatements(s):
    stmts = map(string.strip, s.split("\n"))
    for stmt in stmts:
    eval(stmt)

    RunTheseStatements("""


    RiWorldBegin()
    RiColor(1.0,1.0,1.0)
    RiSurface('constant')
    RiSphere(1.0,-1.0,1.0,360)
    RiWorldEnd()


    """)


    Al
  • Gary Herron at Aug 22, 2003 at 7:44 pm

    On Friday 22 August 2003 11:28 am, achrist at easystreet.com wrote:
    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?
    If the code is purely sequential, how about something like this:

    import string
    def RunTheseStatements(s):
    stmts = map(string.strip, s.split("\n"))
    for stmt in stmts:
    eval(stmt)

    RunTheseStatements("""


    RiWorldBegin()
    RiColor(1.0,1.0,1.0)
    RiSurface('constant')
    RiSphere(1.0,-1.0,1.0,360)
    RiWorldEnd()


    """)
    Here's another way -- inside a [..] or (...) construct

    [
    RiWorldBegin(),
    RiColor(1.0,1.0,1.0),
    RiSurface('constant'),
    RiSphere(1.0,-1.0,1.0,360),
    RiWorldEnd(),
    ]


    Or try this (this might be too ugly)

    RiWorldBegin()
    if 1:
    RiColor(1.0,1.0,1.0)
    RiSurface('constant')
    RiSphere(1.0,-1.0,1.0,360)
    RiWorldEnd()

    or make these all member functions of a class and try

    c. RiWorldBegin(),
    c. RiColor(1.0,1.0,1.0),
    c. RiSurface('constant'),
    c. RiSphere(1.0,-1.0,1.0,360),
    c. RiWorldEnd(),

    or

    Hmmmm -- I'll bet there's more possibilities.

    Gary Herron
  • Gary Herron at Aug 22, 2003 at 8:06 pm

    On Friday 22 August 2003 11:28 am, achrist at easystreet.com wrote:
    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?
    If the code is purely sequential, how about something like this:

    import string
    def RunTheseStatements(s):
    stmts = map(string.strip, s.split("\n"))
    for stmt in stmts:
    eval(stmt)

    RunTheseStatements("""


    RiWorldBegin()
    RiColor(1.0,1.0,1.0)
    RiSurface('constant')
    RiSphere(1.0,-1.0,1.0,360)
    RiWorldEnd()


    """)
    Here's another way -- inside a [..] or (...) construct

    [
    RiWorldBegin(),
    RiColor(1.0,1.0,1.0),
    RiSurface('constant'),
    RiSphere(1.0,-1.0,1.0,360),
    RiWorldEnd(),
    ]


    Or try this (this might be too ugly)

    RiWorldBegin()
    if 1:
    RiColor(1.0,1.0,1.0)
    RiSurface('constant')
    RiSphere(1.0,-1.0,1.0,360)
    RiWorldEnd()

    or make these all member functions of a class and try

    c. RiWorldBegin(),
    c. RiColor(1.0,1.0,1.0),
    c. RiSurface('constant'),
    c. RiSphere(1.0,-1.0,1.0,360),
    c. RiWorldEnd(),

    or

    Hmmmm -- I'll bet there's more possibilities.

    Gary Herron
  • Jeremy Dillworth at Aug 22, 2003 at 8:51 pm
    Here's another idea:

    def world1():
    RiColor(1.0,1.0,1.0)
    RiSurface('constant')
    RiSphere(1.0,-1.0,1.0,360)

    def world2():
    RiColor(1.0,1.0,1.0)
    RiSurface('constant')
    RiSphere(1.0,-1.0,1.0,360)

    worlds_to_build = [world1, world2]
    for world in worlds_to_build:
    RiWorldBegin()
    world()
    RiWorldEnd()

    --- achrist at easystreet.com wrote:
    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?
    If the code is purely sequential, how about something like this:

    import string
    def RunTheseStatements(s):
    stmts = map(string.strip, s.split("\n"))
    for stmt in stmts:
    eval(stmt)

    RunTheseStatements("""


    RiWorldBegin()
    RiColor(1.0,1.0,1.0)
    RiSurface('constant')
    RiSphere(1.0,-1.0,1.0,360)
    RiWorldEnd()


    """)


    Al
    --
    http://mail.python.org/mailman/listinfo/python-list
  • Ben Finney at Aug 22, 2003 at 10:43 pm

    On Fri, 22 Aug 2003 13:06:46 -0700, Gary Herron wrote:
    Hmmmm -- I'll bet there's more possibilities.
    All of which, like all possibilities for forcing different indentation
    on Python, presented so far, *reduce* readability instead of enhancing
    it.

    --
    \ "One time a cop pulled me over for running a stop sign. He |
    `\ said, 'Didn't you see the stop sign?' I said, 'Yeah, but I |
    _o__) don't believe everything I read.'" -- Steven Wright |
    Ben Finney <http://bignose.squidly.org/>
  • Hilbert at Aug 24, 2003 at 6:10 pm
    You're right, this reduces readability in python,
    but reflects the RIB stream better which is
    what I want to do.

    In article <slrnbkd8aj.sd.bignose-hates-spam at rose.localdomain.fake>, Ben Finney wrote:
    On Fri, 22 Aug 2003 13:06:46 -0700, Gary Herron wrote:
    Hmmmm -- I'll bet there's more possibilities.
    All of which, like all possibilities for forcing different indentation
    on Python, presented so far, *reduce* readability instead of enhancing
    it.
  • Skip Montanaro at Aug 22, 2003 at 6:47 pm
    Hilbert> I'm using CGKit in python which has a Renderman binding, so to
    Hilbert> output the same RIB I'd write:

    Hilbert> RiWorldBegin()
    Hilbert> RiColor(1.0,1.0,1.0)
    Hilbert> RiSurface('constant')
    Hilbert> RiSphere(1.0,-1.0,1.0,360)
    Hilbert> RiWorldEnd()

    Hilbert> But I get an error, because python interprets my indentation as
    Hilbert> a block in the python code.

    As it should, because whitespace is significant in Python.

    Hilbert> So the only way to write this is without the indentation:

    Hilbert> RiWorldBegin()
    Hilbert> RiColor(1.0,1.0,1.0)
    Hilbert> RiSurface('constant')
    Hilbert> RiSphere(1.0,-1.0,1.0,360)
    Hilbert> RiWorldEnd()

    Hilbert> But this is a lot harder to read.

    Hilbert> Is there any way to use such "visual" indentation in python?

    In this case, just use "if 1:"

    RiWorldBegin()
    if 1:
    RiColor(1.0,1.0,1.0)
    RiSurface('constant')
    RiSphere(1.0,-1.0,1.0,360)
    RiWorldEnd()

    Skip
  • Hans Nowak at Aug 22, 2003 at 7:13 pm

    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/
  • Chad Netzer at Aug 25, 2003 at 5:39 am

    On Fri, 2003-08-22 at 12:13, Hans Nowak wrote:
    Hilbert wrote:
    But maybe somebody else has a better solution...?

    Another kinda ugly one:


    RiWorldBegin() ;\
    RiColor(1.0,1.0,1.0) ;\
    RiSurface('constant') ;\
    RiSphere(1.0,-1.0,1.0,360) ;\
    RiWorldEnd()


    --

    Chad Netzer
  • Cliff Wells at Aug 22, 2003 at 7:26 pm

    On Fri, 2003-08-22 at 11:10, 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?
    How about this? It creates a bit of unnecessary overhead (a single
    tuple creation), but looks okay visually (and Emacs correctly indents
    it):

    RiWorldBegin()
    (
    RiColor(1.0,1.0,1.0),
    RiSurface('constant'),
    RiSphere(1.0,-1.0,1.0,360),
    )
    RiWorldEnd()


    Regards,

    --
    Cliff Wells, Software Engineer
    Logiplex Corporation (www.logiplex.net)
    (503) 978-6726 (800) 735-0555
  • Evan Simpson at Aug 22, 2003 at 9:07 pm

    Hilbert wrote:
    RiWorldBegin()
    RiColor(1.0,1.0,1.0)
    RiSurface('constant')
    RiSphere(1.0,-1.0,1.0,360)
    RiWorldEnd()

    Is there any way to use such "visual" indentation in python?
    If all of the lines that you want to indent in this fashion are
    expressions, not statments, then you could do this:

    RiWorldBegin()
    ( RiColor(1.0,1.0,1.0) )
    ( RiSurface('constant') )
    ( RiSphere(1.0,-1.0,1.0,360) )
    RiWorldEnd()

    If there are statements involved, you could do this:

    RiWorldBegin()
    1; RiColor(1.0,1.0,1.0)
    1; RiSurface('constant')
    1; RiSphere(1.0,-1.0,1.0,360)
    RiWorldEnd()

    Both are ugly, of course.

    Cheers,

    Evan @ 4-am
  • Peter Otten at Aug 22, 2003 at 10:05 pm

    Hilbert wrote:

    Is there any way to use such "visual" indentation in python?
    Whitespace *is* significant in Python, and you should not try to circumvent
    this using dirty tricks. Why not structuring your world definitions in the
    standard way, putting the things that belong together in separate functions
    or classes?

    #disclaimer: no knowledge of CGKit involved in the following code
    WHITE = (1.0,1.0,1.0)

    def whitesurface():
    RiColor(*WHITE)
    RiSurface('constant')

    def firstworld():
    whitesurface()
    RiSphere(1.0,-1.0,1.0,360)

    def secondworld():
    whitesurface()
    RiSphere(1.0,-1.0,1.0,360)

    for world in [firstworld, secondworld]:
    RiWorldBegin()
    world()
    RiWorldEnd()

    I think the above is pretty readable, and you can always factor out
    repeating chunks of code

    Peter
  • Greg Krohn at Aug 22, 2003 at 10:52 pm
    "Hilbert" <Hilbert at panka.com> wrote in message
    news:slrnbkcja7.s51.Hilbert at server.panka.com...
    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?

    Thanks,
    Hilbert

    hilbert at panka.com
    What about an if statement:

    RiWorldBegin()
    if True:
    RiColor(1.0,1.0,1.0)
    RiSurface('constant')
    RiSphere(1.0,-1.0,1.0,360)
    RiWorldEnd()

    I realize it's ugly, but it's easy.
  • Dan Bishop at Aug 23, 2003 at 12:40 am
    Hilbert <Hilbert at panka.com> wrote in message news:<slrnbkcja7.s51.Hilbert at server.panka.com>...
    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 ...
    Is there any way to use such "visual" indentation in python?
    If the code consists of nothing but expressions (which yours does), you can write:

    (RiWorldBegin())
    ( RiColor(1.0,1.0,1.0))
    ( RiSurface('constant'))
    ( RiSphere(1.0,-1.0,1.0,360))
    (RiWorldEnd())

    or

    (
    RiWorldBegin(),
    RiColor(1.0,1.0,1.0),
    RiSurface('constant'),
    RiSphere(1.0,-1.0,1.0,360),
    RiWorldEnd()
    )
  • Cliff Wells at Aug 23, 2003 at 1:58 am

    On Fri, 2003-08-22 at 11:10, 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'm sending this again as the message I sent earlier apparently never
    made it.

    RiWorldBegin()
    (
    RiColor(1.0,1.0,1.0),
    RiSurface('constant'),
    RiSphere(1.0,-1.0,1.0,360),
    )
    RiWorldEnd()

    There's a bit of added overhead (superfluous tuple creation) but it does
    what you ask.

    Regards,
    Cliff

    --
    Should I stand midst the breakers, Should I lie with Death my bride?
    -This Mortal Coil
  • Hilbert at Aug 24, 2003 at 6:10 pm
    Thanks for all the suggestions!

    I like both the tuple and the if 1: approach.

    I don't want to define blocks in functions because that
    would actually differ from how the RIB stream works.
    I'd like to have my code reflect a real RIB stream.

    Thanks again,
    Hilbert

    hilbert at panka.com



    In article <slrnbkcja7.s51.Hilbert at server.panka.com>, 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?

    Thanks,
    Hilbert

    hilbert at panka.com

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 22, '03 at 6:10p
activeAug 25, '03 at 5:39a
posts17
users14
websitepython.org

People

Translate

site design / logo © 2022 Grokbase