Solved

web service to iterate over la list returned

Posted on 2011-03-01
3
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a…
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

726 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