On Thu, Sep 8, 2011 at 4:16 PM, lina <span dir="ltr"><<a href="mailto:lina.lastname@gmail.com">lina.lastname@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Thu, Sep 8, 2011 at 9:59 PM, Alan Gauld <<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>> wrote:<br>
> On 08/09/11 14:02, lina wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I failed to understand the "collpase" meaning in a string.<br>
>><br>
>> can someone give me a simple example?<br>
><br>
> Can you give us some context?<br>
> Its not a method of a string object so far as I can tell?<br>
> Where did you read about it?<br>
<br>
</div>>From "dive into python",<br>
<br>
<a href="http://diveintopython.org/" target="_blank">http://diveintopython.org/</a><br>
<br>
one example:<br>
<br>
def info(object, spacing=10, collapse=1):<br>
"""Print methods and docs strings.<br>
<br>
Take modules, class, list, dictionary, or strong."""<br>
methodList = [e for e in dir(object) if callable(getattr(object, e))]<br>
processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)<br>
print "\n".join(["%s %s" %<br>
(method.ljust(spacing),<br>
processFunc(str(getattr(object, method).__doc__)))<br>
for method in methodList])<br>
<br>
if __name__ == "__main__":<br>
print info.__doc__<br>
<br>
I felt so hard to understand the collapse,<br>
<br>
Please don't discourage me telling me it's an old book,<br>
To me I started reading till 42 pages. let me finish it.<br>
<br>
I used to study python on and off,<br>
sometimes give a whole week, but due to not using it,<br>
so<br>
it's frustrating that when I really needed it, I barely could complete one.<br></blockquote><div><br>Reading this, it seems that 'collapse' is a variable defined somewhere else in the code.<br> </div></div>-- <br>
André Engels, <a href="mailto:andreengels@gmail.com">andreengels@gmail.com</a><br><br>