Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16134

Re: String splitting by spaces question

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.glorb.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!spln!extra.newsguy.com!newsp.newsguy.com!drn
From Phil Rist <Phil_member@newsguy.com>
Newsgroups comp.lang.python
Subject Re: String splitting by spaces question
Date 23 Nov 2011 16:20:43 -0800
Organization NewsGuy - Unlimited Usenet $19.95
Lines 37
Message-ID <jak2kr09dh@drn.newsguy.com> (permalink)
References <3f19e4c0-e010-4cb2-9f71-dd09e0d3cb1f@r9g2000vbw.googlegroups.com>
NNTP-Posting-Host p21be65762de3bafd7ceb2d37de6a66d665d3091116fb9d91.newsdawg.com
User-Agent Direct Read News 5.60
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:16134

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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