Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41226
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <chris@rebertia.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'float': 0.05; 'skip:` 10': 0.05; 'debugging.': 0.07; 'ok.': 0.07; 'rewrite': 0.07; "subject:' ": 0.07; 'python': 0.09; 'explanation': 0.09; 'imports': 0.09; 'iterate': 0.09; 'likewise': 0.09; 'loop.': 0.09; 'subject:iterable': 0.09; 'typeerror:': 0.09; 'cc:addr:python-list': 0.10; 'subject:not': 0.11; 'already,': 0.16; 'bounds': 0.16; 'clear.': 0.16; 'iteration': 0.16; 'list;': 0.16; 'merely': 0.16; 'nowadays': 0.16; 'repeatedly.': 0.16; 'subject:object': 0.16; 'why:': 0.16; 'wrote:': 0.17; 'duplicate': 0.17; 'thu,': 0.17; 'variables': 0.17; 'why.': 0.17; 'code,': 0.18; 'putting': 0.20; 'earlier': 0.21; 'assignment': 0.22; 'assuming': 0.22; 'cc:2**0': 0.23; 'this:': 0.23; "haven't": 0.23; 'cc:no real name:2**0': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'appear': 0.26; 'wrote': 0.26; 'values': 0.26; 'am,': 0.27; '(we': 0.27; 'list:': 0.27; 'message- id:@mail.gmail.com': 0.27; 'chris': 0.28; 'run': 0.28; 'contrast,': 0.29; 'loop,': 0.29; 'once,': 0.29; 'piece': 0.29; 'case,': 0.29; 'saves': 0.30; 'error': 0.30; 'helpful': 0.30; 'url:python': 0.32; 'print': 0.32; 'message.': 0.33; 'excel': 0.33; 'me?': 0.33; 'tutorial': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'along': 0.35; 'replaced': 0.35; 'list.': 0.35; 'but': 0.36; 'url:org': 0.36; '(i.e.': 0.36; 'url:library': 0.36; 'item': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'url:docs': 0.38; 'list,': 0.39; 'help': 0.40; 'your': 0.60; 'range': 0.60; 'real': 0.61; 'url:index': 0.61; 'different': 0.63; 'details': 0.63; 'within': 0.64; 'here': 0.65; 'our': 0.65; 'therefore': 0.65; 'wish': 0.70; 'future,': 0.72; 'step-by-step': 0.75; '2013': 0.84; 'sender:addr:chris': 0.84; 'url:functions': 0.84; 'ana': 0.91; 'lone': 0.91; 'url:tutorial': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=0apoL8em0HI6tT8XAKK518jC0TomEjj7v2tf/aPu8Fw=; b=IkpYhePzbzAG2vPf2Y+O789cBBFmH3i3pj5KzqDBc/BIoC6pRnjszEsfqskXAyscpB P7CJFe5u2Q7c9mL/I6CqgSUvEF32WaKUQXpaCSoRvbaTRAv41zd7A1Wss+ADo8OLe/4h XeH6BBmz32d5iYRDflFs0/VE/qJxKFyZUEEUM= |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding:x-gm-message-state; bh=0apoL8em0HI6tT8XAKK518jC0TomEjj7v2tf/aPu8Fw=; b=Wws8yLvZDoaSTRbpTV6XnHYanlnPnawS6PiLjYjBr9jApsMewGDa++0aGpu9TZhN3f Ef7clZ1obBhgBUEw1Hhz6m61b0ewlB8AAI5AuqqhBLxSD+/OkyWW+MQMmNqB8AmtFK6t X43lYv/Cqjy1bwP9YmpHhp/nD6v0KXIc5jXBgiGDMmmIr0mPggA3ck+4B9qtwVejzwzO ZCBgQVcuAXnw/E1lgzap9KWLpPOW4AeNlOpkrL7B5uM2cPw23ov9E0GWlAZuRhKHmyv1 9sqiqdvwCkO7Ps4mjq/oIeFVYgEQFJ/1s4lC55bVEENfDEfPsj4VVlcAk0U5LvMTNiGq oC1Q== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.88.165 with SMTP id bh5mr19644909igb.71.1363258239633; Thu, 14 Mar 2013 03:50:39 -0700 (PDT) |
| Sender | chris@rebertia.com |
| In-Reply-To | <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> |
| References | <3984882c-0144-47ba-af4f-b29877bc4698@googlegroups.com> |
| Date | Thu, 14 Mar 2013 03:50:39 -0700 |
| X-Google-Sender-Auth | RbJlnXiHfg-LwplWrLOYikKcSh8 |
| Subject | Re: TypeError: 'float' object is not iterable |
| From | Chris Rebert <clp2@rebertia.com> |
| To | Ana Dionísio <anadionisio257@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-Gm-Message-State | ALoCoQl1eONZR9ah8RXHzRjVP+et2RNCEo0vVU1pr8e4drjcCh1Fo+tQAr2Jdv4EoUuTHn8jU76d |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3296.1363258242.2939.python-list@python.org> (permalink) |
| Lines | 75 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1363258242 news.xs4all.nl 6972 [2001:888:2000:d::a6]:55758 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:41226 |
Show key headers only | View raw
On Thu, Mar 14, 2013 at 3:12 AM, Ana Dionísio <anadionisio257@gmail.com> wrote: > Hi!! > > I keep having this error and I don't know why: TypeError: 'float' object is not iterable. In general, in the future, always include the full exception Traceback, not just the final error message. The extra details this provides can greatly aid debugging. > I have this piece of code, that imports to python some data from Excel and saves it in a list: > > " > t_amb = [] > > for i in range(sh2.nrows): > t_amb.append(sh2.cell(i,2).value) `t_amb` is a list, and you are apparently putting floats (i.e. real numbers) into it. `t_amb` is a list of floats. Therefore every item of `t_amb` (i.e. `t_amb[x]`, for any `x` that's within the bounds of the list's indices) will be a float. (Also, you may want to rewrite this as a list comprehension; http://docs.python.org/2/tutorial/datastructures.html#list-comprehensions ) > print t_amb > > " > Here is everything ok. > > But then, I need to pass the data again to exel, so I wrote this: > > " > a=8 This duplicate assignment is pointless. > for b in range (len(t_amb)): > a=8 > for d in t_amb[b]: Given our earlier conclusion, we likewise know that `t_amb[b]` will be a float (we merely replaced the arbitrary `x` with `b`). A single float is a scalar, not a collection, so it's nonsensical to try and iterate over it like you are in "for d in t_amb[b]:"; a number is not a list. `t_amb[b]` is a lone number, and numbers contain no items/elements over which to iterate. Perhaps you want just "d = t_amb[b]" ? Remember that in a `for` loop, the expression after the `in` (i.e. `t_amb[b]`) is evaluated only once, at the beginning of the loop, and not repeatedly. In contrast, assuming this were a valid `for` loop, `d` would take on different values at each iteration of the loop. In any case, it's rarely necessary nowadays to manually iterate over the range of the length of a list; use `enumerate()` instead; http://docs.python.org/2/library/functions.html#enumerate > 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? I hope this explanation has been sufficiently clear. If you haven't already, you may wish to review the official Python tutorial at http://docs.python.org/2/tutorial/index.html . You may also find it helpful to run your program step-by-step in the interactive interpreter/shell, printing out the values of your variables along the way so as to understand what your program is doing. Regards, Chris
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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