On Thursday 18 May 2006 03:00, Heiko Wundram wrote:

> Am Donnerstag 18 Mai 2006 06:06 schrieb Dave Cinege:

> > This is useful, but possibly better put into practice as a separate

> > method??

>

> I personally don't think it's particularily useful, at least not in the

> special case that your patch tries to address.

Well I'm thinking along the lines of a method to extract only quoted substr's:

' this is "something" and"nothing else"but junk'.splitout('"')

['something ', 'nothing else']

Useful? I dunno....

> splitters), but if you have more complicated quoting operators (such as

> """), are you sure it's sensible to implement the logic in split()?

Probably not. See below...

> 2) What should the result of "this is a \"test string".split(None,-1,'"')

> be? An exception (ParseError)?

I'd probably vote for that. However my current patch will simply play dumb and stop split'ing the rest of the line, dropping the first quote.

'this is a "test string'.split(None,-1,'"')

['this', 'is', 'a', 'test string']

> Silently ignoring the missing delimiter, and

> returning ['this','is','a','test string']? Ignoring the delimiter

> altogether, returning ['this','is','a','"test','string']? I don't think

> there's one case to satisfy all here...

Well the point to the patch is a KISS approach to extending the split() method just slightly to exclude a range of substr from split'ing by delimiter, not to engage in further text processing.

I'm dealing with this ALL the time, while processing output from other programs. (Windope) fIlenames, (poorly considered) wifi network names, etc. For me it's always some element with whitespace in it and double quotes surrounding it, that otherwise I could just use a slice to dump the quotes for the needed element

'filename: "/root/tmp.txt"'.split()[1] [1:-1]

'/root/tmp.txt'

OK

'filename: "/root/is a bit slow.txt"'.split()[1] [1:-1]

'/root/i'

NOT OK

This exact bug just zapped me in a product I have, that I didn't forsee whitespace turning up in that element.....

Thus my patch:

'filename: "/root/is a bit slow.txt"'.split(None,-1,'"')[1]

'/root/is a bit slow.txt'

LIFE IS GOOD

> 3) What about escapes of the delimiter? Your current patch doesn't address

> them at all (AFAICT) at the moment,

And it wouldn't, just like the current split doesn't.

'this is a \ test string'.split()

['this', 'is', 'a', '\\', 'test', 'string']

> Don't get me wrong, I personally find this functionality very, very

> interesting (I'm +0.5 on adding it in some way or another), especially as a

> part of the standard library (not necessarily as an extension to .split()).

I'd be happy to have this in as .splitquoted(), but once you use it, it seems more to me like a natural 'ought to be there' extension to split itself.

>

> Why not write up a PEP?

Because I have no idea of the procedure. : ) URL?

Dave

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to