[Tutor] a quick Q: what does the "collapse" mean?
Andre Engels
andreengels at gmail.com
Thu Sep 8 16:36:13 CEST 2011
On Thu, Sep 8, 2011 at 4:16 PM, lina <lina.lastname at gmail.com> wrote:
> On Thu, Sep 8, 2011 at 9:59 PM, Alan Gauld <alan.gauld at btinternet.com>
> wrote:
> > On 08/09/11 14:02, lina wrote:
> >>
> >> Hi,
> >>
> >> I failed to understand the "collpase" meaning in a string.
> >>
> >> can someone give me a simple example?
> >
> > Can you give us some context?
> > Its not a method of a string object so far as I can tell?
> > Where did you read about it?
>
> >From "dive into python",
>
> http://diveintopython.org/
>
> one example:
>
> def info(object, spacing=10, collapse=1):
> """Print methods and docs strings.
>
> Take modules, class, list, dictionary, or strong."""
> methodList = [e for e in dir(object) if callable(getattr(object, e))]
> processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s:
> s)
> print "\n".join(["%s %s" %
> (method.ljust(spacing),
> processFunc(str(getattr(object, method).__doc__)))
> for method in methodList])
>
> if __name__ == "__main__":
> print info.__doc__
>
> I felt so hard to understand the collapse,
>
> Please don't discourage me telling me it's an old book,
> To me I started reading till 42 pages. let me finish it.
>
> I used to study python on and off,
> sometimes give a whole week, but due to not using it,
> so
> it's frustrating that when I really needed it, I barely could complete one.
>
Reading this, it seems that 'collapse' is a variable defined somewhere else
in the code.
--
André Engels, andreengels at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110908/3e09f203/attachment.html>
More information about the Tutor
mailing list