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


Groups > comp.lang.python > #38968 > unrolled thread

Howto parse a string using a char in python

Started by"Steve Goodwin" <sgoodwin@cfl.rr.com>
First post2013-02-15 18:04 -0500
Last post2013-02-15 18:13 -0500
Articles 6 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  Howto parse a string using a char in python "Steve Goodwin" <sgoodwin@cfl.rr.com> - 2013-02-15 18:04 -0500
    Re: Howto parse a string using a char in python John Gordon <gordon@panix.com> - 2013-02-15 23:11 +0000
    Re: Howto parse a string using a char in python Tim Chase <python.list@tim.thechases.com> - 2013-02-15 17:16 -0600
    Re: Howto parse a string using a char in python David Robinow <drobinow@gmail.com> - 2013-02-15 18:19 -0500
    Re: Howto parse a string using a char in python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-15 23:20 +0000
    Re: Howto parse a string using a char in python Gary Chambers <gwchamb@gwcmail.com> - 2013-02-15 18:13 -0500

#38968 — Howto parse a string using a char in python

From"Steve Goodwin" <sgoodwin@cfl.rr.com>
Date2013-02-15 18:04 -0500
SubjectHowto parse a string using a char in python
Message-ID<511ebf0c$0$21334$9a6e19ea@unlimited.newshosting.com>
Hi,

I am looking for the python2.7 function(s) to parse a string from a colon 
character ":"

Sounds simple enough.

For example, a string like "123456:789".  I just need the "123456" 
substring.(left of the :)

I have looked at regular expressions and string functions, so far no luck. 
Custom function required?

Thank you.

- Spoog98 

[toc] | [next] | [standalone]


#38971

FromJohn Gordon <gordon@panix.com>
Date2013-02-15 23:11 +0000
Message-ID<kfmfbo$ff0$1@reader1.panix.com>
In reply to#38968
In <511ebf0c$0$21334$9a6e19ea@unlimited.newshosting.com> "Steve Goodwin" <sgoodwin@cfl.rr.com> writes:

> I am looking for the python2.7 function(s) to parse a string from a colon 
> character ":"

> Sounds simple enough.

> For example, a string like "123456:789".  I just need the "123456" 
> substring.(left of the :)

> I have looked at regular expressions and string functions, so far no luck. 
> Custom function required?

Use the split() string function.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#38974

FromTim Chase <python.list@tim.thechases.com>
Date2013-02-15 17:16 -0600
Message-ID<mailman.1857.1360970107.2939.python-list@python.org>
In reply to#38968
On 2013-02-15 18:04, Steve Goodwin wrote:
> Hi,
> 
> I am looking for the python2.7 function(s) to parse a string from a
> colon character ":"
> 
> Sounds simple enough.
> 
> For example, a string like "123456:789".  I just need the "123456" 
> substring.(left of the :)
> 
> I have looked at regular expressions and string functions, so far
> no luck. Custom function required?

With just a single character, it sounds like you want something like

  whole = "123456:789"
  parts = whole.split(':') # or .split(':', 1)
  interesting = parts[0]

No custom function needed.

-tkc


[toc] | [prev] | [next] | [standalone]


#38975

FromDavid Robinow <drobinow@gmail.com>
Date2013-02-15 18:19 -0500
Message-ID<mailman.1858.1360970352.2939.python-list@python.org>
In reply to#38968
On Fri, Feb 15, 2013 at 6:04 PM, Steve Goodwin <sgoodwin@cfl.rr.com> wrote:
> Hi,
>
> I am looking for the python2.7 function(s) to parse a string from a colon
> character ":"
>
> Sounds simple enough.
>
> For example, a string like "123456:789".  I just need the "123456"
> substring.(left of the :)
"123456:789".split(":")[0]

[toc] | [prev] | [next] | [standalone]


#38976

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-02-15 23:20 +0000
Message-ID<mailman.1859.1360970360.2939.python-list@python.org>
In reply to#38968
On 15/02/2013 23:04, Steve Goodwin wrote:
> Hi,
>
> I am looking for the python2.7 function(s) to parse a string from a colon
> character ":"
>
> Sounds simple enough.
>
> For example, a string like "123456:789".  I just need the "123456"
> substring.(left of the :)
>
> I have looked at regular expressions and string functions, so far no luck.
> Custom function required?
>
> Thank you.
>
> - Spoog98
>
>

More likely a visit to the opticians :)  See 
http://docs.python.org/2/library/stdtypes.html#string-methods for the 
find and index methods.

-- 
Cheers.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#38977

FromGary Chambers <gwchamb@gwcmail.com>
Date2013-02-15 18:13 -0500
Message-ID<mailman.1860.1360970443.2939.python-list@python.org>
In reply to#38968

[Multipart message — attachments visible in raw view] — view raw

Steve,

> I am looking for the python2.7 function(s) to parse a string from a colon 
> character ":"
> 
> Sounds simple enough.
> 
> For example, a string like "123456:789".  I just need the "123456" 
> substring.(left of the :)

How about:

newstr = str[:str.find(':')]

--
GC

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web