Erich <[EMAIL PROTECTED]> writes:
> def iterable(item, count_str=False):
> if not count_str and isinstance(item, str):
> return False
> try:
> iter(item)
> except:
> return False
> return True
> This is just simple boolean test for whether or not an object
On Tue, 2008-04-15 at 13:48 -0700, Jeffrey Froman wrote:
> Tim Chase wrote:
> >def nsplit(s, delim=None, maxsplit=None):
> > if maxsplit:
> >results = s.split(delim, maxsplit)
> >result_len = len(results)
> >if result_len < maxsplit:
> > results.extend([''
On Tue, 2008-04-15 at 11:51 -0700, Erich wrote:
> Hello all,
>
> Today I found myself once again defining two functions that I use all
> the time: nsplit and iterable. These little helper functions of mine
> get used all the time when I work. Im sick of having to define them
> (but am very good
Erich wrote:
> def iterable(item, count_str=False):
> if not count_str and isinstance(item, str):
> return False
> try:
> iter(item)
> except:
> return False
> return True
Beware the "except" clause here, as it catches *all* errors. Thus, if you
happen to ha
Tim Chase wrote:
>def nsplit(s, delim=None, maxsplit=None):
> if maxsplit:
>results = s.split(delim, maxsplit)
>result_len = len(results)
>if result_len < maxsplit:
> results.extend([''] * (maxsplit - result_len)
>return results
> else:
>
On Apr 15, 3:15 pm, Tim Chase <[EMAIL PROTECTED]> wrote:
>
> My suggestion would just be to create your own utils.py module
> that holds your commonly used tools and re-uses them
>
> -tkc
Well, I almost said that, but I was trying to find some "battery"
included that he could use since the OP s
>> def nsplit(s,p,n):
>> n -= 1
>> l = s.split(p, n)
>> if len(l) < n:
>> l.extend([''] * (n - len(l)))
>> return l
>
> The split() method has a maxsplit parameter that I think does the same
> thing. For example:
>
temp = 'foo,bar,baz'
temp.split(',', 1)
> ['foo'
> Today I found myself once again defining two functions that I use all
> the time: nsplit and iterable. These little helper functions of mine
> get used all the time when I work. Im sick of having to define them
> (but am very good at it these days, less than 1 typo per function!).
> It lead
Erich schrieb:
> This is like split() but returns a list of exactly lenght n. This is
> very useful when using unpacking, e.g.:
> x, y = nsplit('foo,bar,baz', ',', 2)
You could use the second argument of split:
x, y = 'foo,bar,baz'.split(',', 1)
Note that the number has the meaning "only spli
On Apr 15, 1:51 pm, Erich <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> Today I found myself once again defining two functions that I use all
> the time: nsplit and iterable. These little helper functions of mine
> get used all the time when I work. Im sick of having to define them
> (but am very go
On Apr 15, 1:51 pm, Erich <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> Today I found myself once again defining two functions that I use all
> the time: nsplit and iterable. These little helper functions of mine
> get used all the time when I work. Im sick of having to define them
> (but am very go
Hello all,
Today I found myself once again defining two functions that I use all
the time: nsplit and iterable. These little helper functions of mine
get used all the time when I work. Im sick of having to define them
(but am very good at it these days, less than 1 typo per function!).
It leads m
12 matches
Mail list logo