removing text string
Ahmed, Shakir
shahmed at sfwmd.gov
Thu Sep 11 08:33:01 EDT 2008
Thanks
Actually the number I am getting it is from slicing from a long text
line. I need to slice 10 characters from that line but no string only
numeric numbers. When I am slicing 10 characters those A, c, O is coming
at the end.
Thanks
-----Original Message-----
From: python-list-bounces+shahmed=sfwmd.gov at python.org
[mailto:python-list-bounces+shahmed=sfwmd.gov at python.org] On Behalf Of
Dennis Lee Bieber
Sent: Wednesday, September 10, 2008 3:45 PM
To: python-list at python.org
Subject: Re: removing text string
On Wed, 10 Sep 2008 11:22:16 -0400, "Ahmed, Shakir" <shahmed at sfwmd.gov>
declaimed the following in comp.lang.python:
> I need to remove text string from the list of the numbers mentioned
> below:
>
> 080829-7_A
> 070529-5_c
> 080824-7_O
> 070405_6_p
>
? Is that last one an error that is supposed to be
...5-6_, not
...5_6_ ?
1) If the required data is fixed width, just slice it
out = inp[:8]
2) If the data is variable width but has a fixed delimiter,
find
the delimiter position and then slice (this is the reason for my
question above -- this method) OR just split on the delimiter and take
the part you need.
out = inp.split("_")[0]
3) If the data is more complex (again if that last line
with two _
is supposed to be trimmed after the second, and the first turned into a
-) you will need to fully define the parsing rules of the data.
--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed at ix.netcom.com wulfraed at bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-asst at bestiaria.com)
HTTP://www.bestiaria.com/
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list