Simple Text Processing

AJAskey askeyaj at gmail.com
Thu Sep 10 17:36:39 CEST 2009


New to Python.  I can solve the problem in perl by using "split()" to
an array.  Can't figure it out in Python.

I'm reading variable lines of text.  I want to use the first number I
find.  The problem is the lines are variable.

Input example:
  this is a number: 1
  here are some numbers 1 2 3 4

In both lines I am only interested in the "1".  I can't figure out how
to use "split()" as it appears to make me know how many space
separated "words" are in the line.  I do not know this.

I use:  a,b,c,e = split() to get the first line in the example.  The
second line causes a runtime exception.  Can I use "split" for this?
Is there another simple way to break the "words" into an array that I
can loop over?

Thanks.
Andy



More information about the Python-list mailing list