Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41526 > unrolled thread
| Started by | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| First post | 2013-03-19 11:50 -0400 |
| Last post | 2013-03-19 11:50 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Replace "dash" values in a field with new line- VB equivalent of Python Joel Goldstick <joel.goldstick@gmail.com> - 2013-03-19 11:50 -0400
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2013-03-19 11:50 -0400 |
| Subject | Re: Replace "dash" values in a field with new line- VB equivalent of Python |
| Message-ID | <mailman.3522.1363708242.2939.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
On Tue, Mar 19, 2013 at 11:36 AM, Cathy James <nambo4jb@gmail.com> wrote:
> Dear All,
> I need some assistance with Python so that values in the "Name" field e.g.
> Murray - James - Leo can be labeled as:
>
> Murray
> James
> Leo
>
> with a new line replacing every dash.
>
> Basically I need the equivalent of this VB in Python:
> replace ( [Name] , "-", vbNewLine)
>
> I tried this but no luck:
>
> str.[Name].replace("-", "\n")
> str.[Name].replace("-", \n)
> [Name].replace("-", \n")
>
> Your help is appreciated
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
> Is this what you need:
>>> names = 'Tom - Dick - Harry'
>>> name_list = names.split('-')
>>> name_list
['Tom ', ' Dick ', ' Harry']
>>> name_list = names.split('-')
>>> for n in name_list:
... print n.strip()
...
Tom
Dick
Harry
>>>
--
Joel Goldstick
http://joelgoldstick.com
Back to top | Article view | comp.lang.python
csiph-web