Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16120
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <nick@dokosmarshall.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.036 |
| X-Spam-Evidence | '*H*': 0.93; '*S*': 0.00; 'comprises': 0.07; 'advance!': 0.09; 'csv': 0.09; 'delimiters': 0.16; 'nick': 0.16; 'row': 0.16; 'subject:String': 0.16; 'cc:addr:python-list': 0.16; 'subject:question': 0.17; 'wrote:': 0.18; 'this?': 0.19; 'cc:no real name:2**0': 0.20; 'maybe': 0.21; 'header:In-Reply-To:1': 0.22; 'string': 0.24; 'module': 0.26; 'function': 0.27; 'skip:[ 10': 0.27; 'import': 0.27; 'pass': 0.29; 'problem': 0.29; 'print': 0.29; 'cc:addr:python.org': 0.29; 'array': 0.30; 'splitting': 0.30; 'thanks': 0.31; 'list': 0.32; 'match': 0.34; 'question,': 0.34; 'parse': 0.34; '...': 0.36; 'cc:2**1': 0.36; 'but': 0.37; 'received:org': 0.38; 'more': 0.61; 'achieve': 0.61; 'your': 0.61; 'reply-to:no real name:2**0': 0.72; 'header:Reply-to:1': 0.84; 'cc:addr:msn.com': 0.84; 'quotations': 0.84; 'spaces.': 0.84; 'substrings': 0.84 |
| To | "Alemu Tadesse" <atadesse@sunedison.com> |
| From | Nick Dokos <nicholas.dokos@hp.com> |
| Subject | Re: String splitting by spaces question |
| In-Reply-To | Message from "Alemu Tadesse" <atadesse@sunedison.com> of "Wed, 23 Nov 2011 11:31:21 CST." <6FA6EB75E3CA4744ADF9EF97D8DAC18B01967924@mail.sunedison.com> |
| References | <3f19e4c0-e010-4cb2-9f71-dd09e0d3cb1f@r9g2000vbw.googlegroups.com> <6FA6EB75E3CA4744ADF9EF97D8DAC18B01967924@mail.sunedison.com> |
| Organization | HPCS |
| X-Mailer | MH-E 8.3; nmh 1.3; GNU Emacs 24.0.90 |
| Date | Wed, 23 Nov 2011 12:51:12 -0500 |
| Sender | nick@dokosmarshall.org |
| Cc | python-list@python.org, Massi <massi_srb@msn.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| Reply-To | nicholas.dokos@hp.com |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2977.1322071012.27778.python-list@python.org> (permalink) |
| Lines | 34 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1322071012 news.xs4all.nl 6892 [2001:888:2000:d::a6]:38416 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:16120 |
Show key headers only | View raw
Alemu Tadesse <atadesse@sunedison.com> wrote:
> Can we use rsplit function on an array or vector of strings ? it works
> for one not for vector
> ...
>
> 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!
You can use a list comprehension:
l2 = [x.rsplit(...) for x in l]
But for the original question, maybe the csv module would be
more useful: you can change delimiters and quotechars to match
your input:
import csv
reader = csv.reader(open("foo.txt", "rb"), delimiter=' ', quotechar="'")
for row in reader:
print row
Nick
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