On Mar 19, 8:36 pm, Cathy James <[email protected]> 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']
>>>
--
http://mail.python.org/mailman/listinfo/python-list