Source formatting for long expressions.

Christopher Armstrong radix at twistedmatrix.com
Sat Jun 8 17:11:42 EDT 2002


Background:
  I'm writing a source persistence mechanism for Twisted 
(http://twistedmatrix.com) as an alternative to the Pickle and XML persistence
that we currently have. Basically, I have code that turns Python objects into
something that looks like::

Ref(1, Instance('twisted.internet.app.Application', persistenceVersion=7,
services={}, udpPorts=[], gid=1000, connectors=[], uid=1000,
tcpPorts=[(9080, Instance('twisted.web.server.Site', sessions={}, 
resource=Instance('twisted.coil.web.ConfigRoot', children={}, 
modules=[], widgets={'config': 
Instance('twisted.coil.web.AppConfiguratorPage', variables={}, 
dispensers=Instance('twisted.coil.coil.DispenserStorage', dispensers={}}),
app= ...
<bazillion more lines>

  As you can see, this is one really long expression :-) I already have the
code that persists to/unpersists from this format (it was fairly easy with the
'jelly' serialization framework), but it's not very useful unless it's in a
pretty format that's easy for people to edit. Does anyone know of a tool that
will beak up a very, very long expression like this into multiple lines with
sane indentation? I'll probably end up writing the beast myself, but I don't
want to waste my time if there's something out there.

-- 
                                Chris Armstrong
                         << radix at twistedmatrix.com >>
                http://twistedmatrix.com/users/carmstro.twistd/






More information about the Python-list mailing list