Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16134
| From | Phil Rist <Phil_member@newsguy.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: String splitting by spaces question |
| Date | 2011-11-23 16:20 -0800 |
| Organization | NewsGuy - Unlimited Usenet $19.95 |
| Message-ID | <jak2kr09dh@drn.newsguy.com> (permalink) |
| References | <3f19e4c0-e010-4cb2-9f71-dd09e0d3cb1f@r9g2000vbw.googlegroups.com> |
In article <3f19e4c0-e010-4cb2-9f71-dd09e0d3cb1f@r9g2000vbw.googlegroups.com>, Massi says... > >Hi everyone, > >I have to parse a string and splitting it by spaces. The problem is >that the string can include substrings comprises by quotations which >must mantain the spaces. What I need is to pass from a string like: > >This is an 'example string' > >to the following vector: > >["This", "is", "an", "example string"] > >Which is the best way to achieve this? >Thanks in advance! Is this what you want? import shlex lText = "This is a 'short string' for you to read." lWords = shlex.split(lText) print lWords produces, ['This', 'is', 'a', 'short string', 'for', 'you', 'to', 'read.'] Shlex can be found under 'Program Frameworks' under 'The Python Standard Library' of ActivePython 2.7 documentation. C:\Source\Python\New>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
String splitting by spaces question Massi <massi_srb@msn.com> - 2011-11-23 09:10 -0800
RE: String splitting by spaces question "Alemu Tadesse" <atadesse@sunedison.com> - 2011-11-23 11:31 -0600
Re: String splitting by spaces question Arnaud Delobelle <arnodel@gmail.com> - 2011-11-23 17:40 +0000
Re: String splitting by spaces question Nick Dokos <nicholas.dokos@hp.com> - 2011-11-23 12:51 -0500
Re: String splitting by spaces question Miki Tebeka <miki.tebeka@gmail.com> - 2011-11-23 12:40 -0800
Re: String splitting by spaces question Phil Rist <Phil_member@newsguy.com> - 2011-11-23 16:20 -0800
Re: String splitting by spaces question DevPlayer <devplayer@gmail.com> - 2011-11-23 19:53 -0800
csiph-web