[Python-Dev] New string method - splitquoted
Guido van Rossum
guido at python.org
Sat May 20 16:57:08 CEST 2006
"I'm sorry Dave, I'm afraid I can't do that."
We hear you, Dave, but this is not a suitable function to add to the
standard library. Many respondents are trying to tell you that in many
different ways. If you keep arguing for it, we'll just ignore you.
PS. Give up TDMA. Try Spambayes instead. It works much better and is
less annoying for your correspondents.
On 5/18/06, Dave Cinege
<dcinegemlists2-dated-1148418122.b868e0 at psychosis.com> wrote:
> On Thursday 18 May 2006 16:13, you wrote:
> > Dave Cinege wrote:
> > > For example:
> > >
> > > s = ' Chan: 11 SNR: 22 ESSID: "Spaced Out Wifi" Enc: On'
> > My complaint with this example is that you are just using the wrong tool
> > to do this job. If I was going to do this, I would've immediately jumped
> > on the regex-press train.
> > wifi_info = re.match('^\s+'
> > 'Chan:\s+(?P<channel>[0-9]+)\s+'
> > 'SNR:\s+(?P<snr>[0-9]+)\s+'
> > 'ESSID:\s+"(?P<essid>[^"]*)"\s+'
> > 'Enc:\s+(?P<encryption>[a-zA-Z]+)'
> > , s)
> For the 5 years of been pythoning, I've used re probably twice.
> I find regex to be a tool of last resort, and quite a bit of effort to get
> right, as regex (for me) is quite prone it giving unintended results without
> a good deal of thought. I don't want to have to think. That's why I use
> python. : )
> .split() and slicing has always been python's holy grail for me, and I find it
> a lot easier to .replace() 'stray' chars with spaces or a delimiter and then
> split() that. It's easier to read and (should be) a lot quicker to process
> then regex. (Which I care about, as I'm also often on embedded CPU's of a few
> hundred MHz)
> So .split works just super duper.....but I keep running in to situations where
> I'd like a substr to be excluded from the split'ing.
> The clearest one is excluding a 'quoted' string that has whitespace.
> Here's another, be it, a very poor example:
> s = '\t\tFrequency:2.462 GHz (Channel 11)' # This is real output from iwlist:
> s.replace(':',')').replace(' (','))').split(None,-1,')')
> ['Frequency', '2.462 GHz', 'Channel 11']
> I wanted to preserve the '2.462 GHz' substr. Let's assume, that could come out
> as '900 MHz' or '11.3409 GHz'. The above code gets what I want in 1 shot,
> either way. Show me an easier way, that doesn't need multiple splits, and
> string re-assembly, ....and I'll use it.
> Python-Dev mailing list
> Python-Dev at python.org
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev