473,395 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to fix "Object not iterable" error?

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 29268
bvdet
2,851 Expert Mod 2GB
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
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
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
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
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....
5
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...
4
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...
70
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...
7
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...
5
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
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
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.