Allowing Arbitrary Indentation in Python

Jonathan Gardner jgardner.jonathangardner.net at gmail.com
Tue Dec 18 19:09:33 EST 2007


On Dec 18, 2:16 pm, Sam <L33tmin... at gmail.com> wrote:
> layouts = ['column', 'form', 'frame']
> cmds.window(t='gwfUI Builder')
> cmds.paneLayout(configuration='vertical3', ps=((1, 25, 100), (3, 20,
> 100)))
>     cmds.paneLayout(configuration='horizontal2')
>         cmds.frameLayout(l='Layouts')
>             cmds.scrollLayout(cr=True)
>                 cmds.columnLayout(adj=True, cat=('both', 2))
>                     for i in layouts:
>                         cmds.button(l=i)
>                 cmds.setParent('..')
>             cmds.setParent('..')
>         cmds.setParent('..')
>     cmds.setParent('..')
> cmds.setParent('..')
> cmds.showWindow()
>

While Grant is pulling his hair out and yelling obscenities at the
moon, let me try to explain why you'd never want to indent code that
way, let alone write code that way.

In cases where you have to run a sequence of code in a nested way,
like this, it's best to create functions and then nest the functions.
Of course, I'm thinking more of a lisp solution and less of a C one.

In this case, you're going to have to have objects (or data
structures) that know what to do to execute the commands necessary.
When you get them all assembled, you simply run them in a recursive
way.

For instance:

  cmd.build(('pane', dict(configuration='horizontal'), ('frame',
dict(l='Layouts'), (....))))

You can indent these arbitrarily. Plus, you don't have to worry too
much about matching setParent and the other commands.



More information about the Python-list mailing list