Linebreaks and Indention
Bernhard Herzog
bh at intevation.de
Thu Mar 25 16:33:11 CET 2004
Martin Schulze <joey at infodrom.org> writes:
> How would you like to have the following construct splitted?
>
> foo = getElementsByName(
> getElementByName(getElementByName(getElementByName(
> root, 'Capability'), 'Request'), 'GetMap'), 'Format')
Well, that's a bit of a pathological case in general. In this
particular case I'd probably write a function or method to combine those
nested getElementByName calls, e.g.
def getNestedElementsByName(element, *names):
for name in names:
element = getElementByName(element, name):
return element
And then you can do
foo = getNestedElementsByName(root, 'Capability', 'Request', 'GetMap',
'Format')
Or you could extend getElementByName to accept more than one name.
> It could be done with a *long* root.foo.bar[0].baz[1].gnarz... chain as well.
>
> I don't want to assign four local variables just to keep all
> constructs short.
Well, sometimes it's easier to read if you introduce a new variable,
sometimes not. I don't want to create rules that handle all of the
possible situations. Not least because I wouldn't always abide by them
:)
Bernhard
--
Intevation GmbH http://intevation.de/
Skencil http://sketch.sourceforge.net/
Thuban http://thuban.intevation.org/
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)