Re: Initializing an attribute that needs the object
On Fri, Jun 02, 2006 at 06:15:28PM -0300, David Pratt wrote: >Hi. I want to have different handlers to do perform logic. The problem >is the Handler requires an instance of the factory since it will use its >own methods in conjunction with methods of the factory. > >Once I have got a Factory instance I can give it a new handler (see >below). It would be more flexible if I could provide a handle in >constructor - but how to do this when it requires the object itself. >Would I use a super for this sort of thing? Many thanks when __init__ is called the object already exists. >class Factory: > > def __init__(self): > self.some_handler = Handler(self) > >f = Factory() >f.some_handler = AnotherHandler(f) try this, should works: class Factory: def __init__(self): self._some_handler = AnotherHandler(self) maybe a class hierarchy is good for you ciao m. signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find all the same words in a text?
On Sat, Feb 10, 2007 at 05:29:23AM -0800, Johny wrote: >I need to find all the same words in a text . >What would be the best idea to do that? >I used string.find but it does not work properly for the words. >Let suppose I want to find a number 324 in the text > >'45 324 45324' > >there is only one occurrence of 324 word but string.find() finds 2 >occurrences ( in 45324 too) >>> '45 324 45324'.split().count('324') 1 >>> ciao marco -- reply to `python -c "print '[EMAIL PROTECTED]'[::-1]"` signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find all the same words in a text?
On Sat, Feb 10, 2007 at 06:00:05AM -0800, Johny wrote: >On Feb 10, 2:42 pm, Marco Giusti <[EMAIL PROTECTED]> wrote: >> On Sat, Feb 10, 2007 at 05:29:23AM -0800, Johny wrote: >> >I need to find all the same words in a text . >> >What would be the best idea to do that? >> >I used string.find but it does not work properly for the words. >> >Let suppose I want to find a number 324 in the text >> >> >'45 324 45324' >> >> >there is only one occurrence of 324 word but string.find() finds 2 >> >occurrences ( in 45324 too) >> >> >>> '45 324 45324'.split().count('324') >> 1 >> >>> >> >> ciao >Marco, >Thank you for your help. >It works perfectly but I forgot to say that I also need to find the >possition of each word's occurrence.Is it possible that >>> li = '45 324 45324'.split() >>> li.index('324') 1 >>> play with count and index and take a look at the help of both ciao marco -- reply to `python -c "print '[EMAIL PROTECTED]'[::-1]"` signature.asc Description: Digital signature -- http://mail.python.org/mailman/listinfo/python-list