[Tutor] Tutor Digest, Vol 50, Issue 9

rui ruivaldo at gmail.com
Wed Apr 9 14:59:01 CEST 2008

Hi Gloom,

You should give a look at the method "split" (of the string objects) and

The first is used do break a string into smaller pieces and the other to
convert a string to an int object, raising an exception when it is not

On Wed, Apr 9, 2008 at 9:29 AM, Gloom Demon <gloomdemon at gmail.com> wrote:

> Hello :-)
> Can someone please explain to me ho can I find out how many elements are
> there in one record of a list?
> The problem is as follows:
> I have a txt file from which I read data into Python.
> The file looks something like this:
> 01 bla bla bla 23,15 2345,67
> 02 alb alb 2,4 890,1
> 03 bal bla alb lab 567,12345 87,45
> ....
> I need to be able to discriminate the string parts from the numeric ones.
> Since the number of words in the file can vary, I have to be able to find out when they are finished
> and when the floats come in
> mystring[0]-> always integer
> mystring[1]-> string (word)
> mystring[1-X]-> last string (word)
> mystring[X+1]-> always float
> mystring[X+2]-> always float
> it would have been nice if I could find out the total number of the fields
> in one list record so that I could then adress them via a variable.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

Ruivaldo Neto
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080409/d630cfd5/attachment.htm 

More information about the Tutor mailing list