[Tutor] a quick Q: what does the "collapse" mean?
lina
lina.lastname at gmail.com
Thu Sep 8 16:16:53 CEST 2011
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.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
--
Best Regards,
lina
More information about the Tutor
mailing list