Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41524 > unrolled thread
| Started by | Cathy James <nambo4jb@gmail.com> |
|---|---|
| First post | 2013-03-19 11:36 -0400 |
| Last post | 2013-03-19 08:59 -0700 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.python
Replace "dash" values in a field with new line- VB equivalent of Python Cathy James <nambo4jb@gmail.com> - 2013-03-19 11:36 -0400
Re: Replace "dash" values in a field with new line- VB equivalent of Python Neil Cerutti <neilc@norwich.edu> - 2013-03-19 15:52 +0000
Re: Replace "dash" values in a field with new line- VB equivalent of Python rusi <rustompmody@gmail.com> - 2013-03-19 08:59 -0700
| From | Cathy James <nambo4jb@gmail.com> |
|---|---|
| Date | 2013-03-19 11:36 -0400 |
| Subject | Replace "dash" values in a field with new line- VB equivalent of Python |
| Message-ID | <mailman.3521.1363707421.2939.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
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
[toc] | [next] | [standalone]
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Date | 2013-03-19 15:52 +0000 |
| Message-ID | <aqrfu9F1v84U2@mid.individual.net> |
| In reply to | #41524 |
On 2013-03-19, 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")
str methods return new strings in Python, so you need to bind
something to them.
I don't know what the VB syntax above means, but if I pretend
that your string is bound to 'Name':
Name = Name.replace(" - ", "\n")
--
Neil Cerutti
[toc] | [prev] | [next] | [standalone]
| From | rusi <rustompmody@gmail.com> |
|---|---|
| Date | 2013-03-19 08:59 -0700 |
| Message-ID | <3f141155-cb55-4361-b3fa-ac1e8fc56e01@j1g2000pbq.googlegroups.com> |
| In reply to | #41524 |
On Mar 19, 8:36 pm, Cathy James <nambo...@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
What do you mean by 'field'?
Is it a text file? html form? Some kind of gui?
As such 'field' has no meaning in python without further qualification
Anyways here is a small sample that may start you off
>>> line=" Murray - james - Leo "
>>> line.replace("-", "\n")
' Murray \n james \n Leo '
Which may be what you want.
I think you will prefer
>>> line.split("-")
[' Murray ', ' james ', ' Leo ']
Or still better
>>> [part.strip() for part in line.split("-")]
['Murray', 'james', 'Leo']
>>>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web