473,671 Members | 2,341 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to fix "Object not iterable" error?

3 New Member
Hey everyone,
I am fairly new to python, and I was working on a google app engine project for a class, and this error came up. I wasn't sure why, because right above it I have the same object type right above it, and when I take the filter off the other, it works fine, I just can't do that or it screws everything up
Expand|Select|Wrap|Line Numbers
  1. def LoginBar():
  2.     user = users.get_current_user()
  3.     greet = Greeting.all()
  4.     info = greet
  5.     greet.filter("username =", user)
  6.     info = Greeting.all()
  7.     url_account_linktext = "Account"
  8.     check = 0
  9.     if user:
  10.         for info in greet:
  11.             if info.username == user:
  12.                 check = 1
  13.                 break
  14.         if check == 0:
  15.             greeting = Greeting()
  16.             greeting.username = users.get_current_user()
  17.             greeting.email = user.email()
  18.             greeting.name = greeting.username.nickname()
  19.             greeting.put()
  20.  
  21.         url = users.create_logout_url('/')
  22.         url_linktext = 'Logout'
  23.     else:
  24.         url = users.create_login_url('/')
  25.         url_linktext = 'Login'
  26.     template_values = {
  27.             'info': info,
  28.             'greetings': greet,
  29.             'url': url,
  30.             'url_linktext': url_linktext,
  31.             'url_account_linktext': url_account_linktext, 
  32.         }
  33.  
If I use the info variable in this code

Expand|Select|Wrap|Line Numbers
  1. {% for greeting in info %}
  2.     <br /><b>{{ greeting.name }}</b><br />
  3. {% endfor %}
  4.  
it throws this exception, but if I put greet in there, whether it is filtered or not, it works. Any ideas why? I really wish I could use greet, but that doesn't work, sadly, because I use it else where for other stuff. Thanks in advance

Edit, here is the traceback
Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 515, in __call__
  3.     handler.get(*groups)
  4.   File "C:\Users\William\Documents\workspace\242Homework2\src\homework\main.py", line 109, in get
  5.     self.response.out.write(template.render(path, values))
  6.   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\template.py", line 143, in render
  7.     return t.render(Context(template_dict))
  8.   File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\template.py", line 183, in wrap_render
  9.     return orig_render(context)
  10.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\__init__.py", line 168, in render
  11.     return self.nodelist.render(context)
  12.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\__init__.py", line 705, in render
  13.     bits.append(self.render_node(node, context))
  14.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\__init__.py", line 718, in render_node
  15.     return(node.render(context))
  16.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\defaulttags.py", line 175, in render
  17.     return self.nodelist_true.render(context)
  18.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\__init__.py", line 705, in render
  19.     bits.append(self.render_node(node, context))
  20.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\__init__.py", line 718, in render_node
  21.     return(node.render(context))
  22.   File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\defaulttags.py", line 99, in render
  23.     values = list(values)
  24. TypeError: 'Greeting' object is not iterable
  25.  
Feb 7 '11 #1
3 29292
bvdet
2,851 Recognized Expert Moderator Specialist
It would help if you posted the error message including the traceback.

The assignments you make in LoginBar() don't seem right. You make an assignment to info twice before the if statement, and then again if user evaluates True.

The second block of code posted is not valid Python and would raise a SyntaxError.
Feb 7 '11 #2
william hoskins
3 New Member
I added the tracebook, sorry, meant to add that. The last block of code is integrating the python into html, I was half asleep when I asked this, sorry
Feb 7 '11 #3
william hoskins
3 New Member
Never mind, it works now...it turns out I needed to put .all onto the iterating object in the for loop. Thanks for your help!
Feb 7 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2052
by: Nick Jacobson | last post by:
Casting an 'enumerate' object destroys it?? Is that supposed to happen, or is it a bug? For example: a = e = enumerate(a) print dict(e) print dict(e)
8
2871
by: Chris Lasher | last post by:
Hello, I really like the finditer() method of the re module. I'm having difficulty at the moment, however, because finditer() still creates a callable-iterator oject, even when no match is found. This is undesirable in cases where I would like to circumvent execution of code meant to parse out data from my finditer() object. I know that if I place a finditer() object in an iterative for loop, the loop will not execute, but is there some...
5
2078
by: Leif K-Brooks | last post by:
Is there a word for an iterable object which isn't also an iterator, and therefor can be iterated over multiple times without being exhausted? "Sequence" is close, but a non-iterator iterable could technically provide an __iter__ method without implementing the sequence protocol, so it's not quite right.
4
1641
by: Michele Simionato | last post by:
According to the standand library (http://docs.python.org/lib/typeiter.html) an *iterable* is something with an __iter__ method. This means that strings are *not* iterable. However I can loop over a string without problem and I would say that an iterable is anything I can iterate over. Of course I am *not* proposing we add __iter__ to strings (it is convenient for me to be able to distinguish
70
4030
by: py | last post by:
I have function which takes an argument. My code needs that argument to be an iterable (something i can loop over)...so I dont care if its a list, tuple, etc. So I need a way to make sure that the argument is an iterable before using it. I know I could do... def foo(inputVal): if isinstance(inputVal, (list, tuple)): for val in inputVal: # do stuff
7
53012
by: Tim N. van der Leeuw | last post by:
Hi, I'd like to know if there's a way to check if an object is a sequence, or an iterable. Something like issequence() or isiterable(). Does something like that exist? (Something which, in case of iterable, doesn't consume the first element of the iterable) Regards,
5
15591
by: tom | last post by:
Hi! My code is And it gives following error: How can sortedList variable turn into NoneType? I just don't get it...
19
23841
by: python101 | last post by:
I try to calculate the sum of an infinite series S = Sum (from n=0 to 100) 1/k! I got message 'float' / 'int' object is not iterable. How can I fix this?
11
1398
by: Erich | last post by:
Hello all, Today I found myself once again defining two functions that I use all the time: nsplit and iterable. These little helper functions of mine get used all the time when I work. Im sick of having to define them (but am very good at it these days, less than 1 typo per function!). It leads me to the following questions 1. Is this functionality already built in and im just missing it 2. Is there some well known, good technique...
2
10993
by: mmiikkee13 | last post by:
>>a_list = range(37) .... print k, v .... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'int' object is not iterable What 'int' object is this referring to? I'm iterating over a dict, not an int.
0
8478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8919
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8821
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8599
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6230
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4409
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.