On Thu, Sep 8, 2011 at 4:16 PM, lina <lina.lastn...@gmail.com> wrote:
> On Thu, Sep 8, 2011 at 9:59 PM, Alan Gauld <alan.ga...@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, andreeng...@gmail.com
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor