Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41236

Re: TypeError: 'float' object is not iterable

Newsgroups comp.lang.python
Date 2013-03-14 11:11 -0700
References <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com>
Message-ID <5b49a5b4-dfaa-44fe-a60a-8e9aafde9f60@googlegroups.com> (permalink)
Subject Re: TypeError: 'float' object is not iterable
From John Ladasky <john_ladasky@sbcglobal.net>

Show all headers | View raw


On Thursday, March 14, 2013 3:12:11 AM UTC-7, Ana Dionísio wrote:

> for b in range (len(t_amb)):
>     a=8
>     for d in t_amb[b]:
>         a=a+1
>         sheet.write(a,b+1,d)
> 
> The error appear in "for d in t_amb[b]:" and I don't understand why. Can you help me?

It looks to me like you know how to program in some other language, possibly C, and your other language's needs are affecting the way that you write Python.  

You are supplying an explicit variable, b to step through... something.  I THINK that you want to step through t_amb, and not through the Bth element of t_amb.  Python's "in" statement will do this for you automatically, without you having to keep track of an index variable.

You didn't show your import statements, but I assume you are using the xlwt module.  That's where I find the sheet.write() function.  Now, exactly HOW did you want to write the data back to the Excel file?  In a single column?  A single row?  Or in a diagonal?  You have two nested loops.  I'm confused by the fact that you are incrementing both the row and column indices for sheet.write().

Do you know about the enumerate() function?  It's very handy.  It yields a tuple, the first element of which is a number counting up from zero, and the second element of which is an element from the (iterable) variable that you provide.

Does this code accomplish your task?

for column, data in enumerate(t_amb):
    sheet.write(8, column+1, data)

Or this?

for row, data in enumerate(t_amb):
    sheet.write(row+8, 1, data)

If you have any questions, feel free to ask.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

TypeError: 'float' object is not iterable Ana Dionísio <anadionisio257@gmail.com> - 2013-03-14 03:12 -0700
  Re: TypeError: 'float' object is not iterable Joel Goldstick <joel.goldstick@gmail.com> - 2013-03-14 06:31 -0400
    Re: TypeError: 'float' object is not iterable Ana Dionísio <anadionisio257@gmail.com> - 2013-03-14 03:34 -0700
      Re: TypeError: 'float' object is not iterable Joel Goldstick <joel.goldstick@gmail.com> - 2013-03-14 06:44 -0400
      Re: TypeError: 'float' object is not iterable Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-03-14 18:09 -0400
    Re: TypeError: 'float' object is not iterable Ana Dionísio <anadionisio257@gmail.com> - 2013-03-14 03:34 -0700
  Re: TypeError: 'float' object is not iterable MRAB <python@mrabarnett.plus.com> - 2013-03-14 10:43 +0000
  Re: TypeError: 'float' object is not iterable Chris Rebert <clp2@rebertia.com> - 2013-03-14 03:50 -0700
  Re: TypeError: 'float' object is not iterable John Ladasky <john_ladasky@sbcglobal.net> - 2013-03-14 11:11 -0700

csiph-web