[Tutor] Tutor Digest, Vol 50, Issue 9
pylinuxian at gmail.com
Wed Apr 9 15:32:17 CEST 2008
On Wed, Apr 9, 2008 at 12:59 PM, rui <ruivaldo at gmail.com> wrote:
> 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-> always integer
> > mystring-> 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
> Tutor maillist - Tutor at python.org
my guess would be something like this :
for line in a:
for i in tmp_list_1:
if type(i) == int:
if you explain more you case maybe i can get more ideas - hope this helps
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor