removing text string

Ahmed, Shakir shahmed at
Thu Sep 11 14:33:01 CEST 2008


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. 


-----Original Message-----
From: at
[ at] On Behalf Of
Dennis Lee Bieber
Sent: Wednesday, September 10, 2008 3:45 PM
To: python-list at
Subject: Re: removing text string

On Wed, 10 Sep 2008 11:22:16 -0400, "Ahmed, Shakir" <shahmed at>
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,
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		wulfraed at
	(Bestiaria Support Staff:		web-asst at

More information about the Python-list mailing list