Inelegant

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Apr 19 02:03:16 EDT 2005


Bengt Richter wrote:

> I never liked any of the solutions that demand bracketing the string with expression brackets,
> but I just had an idea ;-)

Or for an even more twisted idea:


   from textwrap import dedent

   class _Dedent(type):

     def __new__(cls, name, bases, dict):
       if name  == "*": # for bootstrapping
         return type.__new__(cls, name, bases, dict)
       return dedent(dict['__doc__'])

   DedentedString = _Dedent("*", (), {})

   #
   #   Usage example
   #

   class foo(DedentedString):
     """
     This is a dedented (or perhaps demented?) string.
     It spans multiple lines.
     """

   print type(foo)
   print foo

The output is:

   <type 'str'>

   This is a dedented (or perhaps demented?) string.
   It spans multiple lines.


-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list