Do pythons like sugar?
Steve Holden
sholden at holdenweb.com
Thu Jan 9 09:22:44 EST 2003
"Afanasiy" <abelikov72 at hotmail.com> wrote in message
news:6u6q1vk7dgjps43t0uuk8eut1ghlgnoc71 at 4ax.com...
> I've written this method for a text formatting class...
> But it's ugly as sin. With all those self's I consider
> it much less readable than it could be...
>
> A few languages provide syntax sugar for dealing with
> this by allowing you to localize the class scope.
>
> Does Python? eg. `with self do:`
>
> def format( self, width=80 ):
> self.lines = ['']
> i = 0
> for word in self.text.split():
> if self.textwidth(self.lines[i]) + self.textwidth(word) <= width:
> if self.textwidth(self.lines[i]) > 0:
> self.lines[i] += ' '
> self.lines[i] += word
> else:
> i += 1
> self.lines.append(word)
>
http://www.python.org/cgi-bin/faqw.py?req=show&file=faq06.031.htp
regards
-----------------------------------------------------------------------
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
Bring your musical instrument to PyCon! http://www.python.org/pycon/
-----------------------------------------------------------------------
More information about the Python-list
mailing list