Solved

web service to iterate over la list returned

Posted on 2011-03-01
3
364 Views
Last Modified: 2012-05-11
I have built a web service using cherry.py and am having issues on what is most likley very simple.  I have a web service call that returns a list of strings and I simply need to print this back to the browser.

I have something like this:
for item in stat:
     return (item)

It will only return the first element and then stops. How to I iterate over all the list elements??
0
Comment
Question by:andrew_89
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 35014076
Return returns.  So the first time through the loop you return.

Not sure exactly how you want to represent your list to your client but one way might be:

   return ",".join(stat)


Another way (which returns the same as the above just in a much more roundabout way):

   retval = ""
   for item in stat:
      retval += stat + ","

   return retval[:-1]


Another way (which returns your list JSONified):

   import json
   return json.dumps(stat)

0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 35014082
Sorry (typo):

   retval = ""
   for item in stat:
      retval += item + ","

   return retval[:-1]
0
 
LVL 1

Author Comment

by:andrew_89
ID: 35014152
awesome thanks, I am new to web services so this was throwing me..
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now