[CentralOH] Code to Refactor
Eric Floehr
eric at intellovations.com
Tue May 15 18:57:37 CEST 2012
The need to return variable lengths pretty much rules out a generator.
If s is a string, you could just use a memory file, i.e. StringIO:
import cStringIO # Use cStringIO over StringIO for speed
stringfile = cStringIO.StringIO(s)
next_n = stringfile.read(n)
-Eric
On Tue, May 15, 2012 at 11:41 AM, <jep200404 at columbus.rr.com> wrote:
> What's a better way of doing the following?
> Iterators come to mind, but the need to get a
> variable lengths seems to screw that up.
>
> class dribbler():
> def __init__(self, s):
> self.s = s
> self.i = 0
>
> def get_next_n(self, n):
> s = self.s[self.i:self.i + n]
> self.i += n
> return s
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh
More information about the CentralOH
mailing list