Solved

web service to iterate over la list returned

Posted on 2011-03-01
3
366 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program 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…

919 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

17 Experts available now in Live!

Get 1:1 Help Now