[Tutor] a quick Q: what does the "collapse" mean?
joel.goldstick at gmail.com
Thu Sep 8 16:48:07 CEST 2011
On Thu, Sep 8, 2011 at 10:36 AM, Andre Engels <andreengels at gmail.com> wrote:
> 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>
>> > 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",
>> 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" %
>> 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,
>> it's frustrating that when I really needed it, I barely could complete
> Reading this, it seems that 'collapse' is a variable defined somewhere else
> in the code.
> André Engels, andreengels at gmail.com
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> collapse is a function that Mark must have described earlier in the chapter
you are working on. Are you using the online version? which chapter
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor