Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 3rd, 2013, 06:45 PM
MynE MynE is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 38 MynE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 18 m 33 sec
Reputation Power: 1
Save text data from JSON as a list

Hi, I'm struggling on how to save text which I loaded from JSON to a variable as a list.

I loaded data like this:

Code:
l =[]

for i in range (10):
     l = results[i]['message']


The problem is when I check "l" it will show me only the last data of i which is 10. That means it print results[10]['message'] for me which is only 1 value (I need 10 of them)

Can anybody help me solve this problem, thank you so much.

P.S. Sorry that my question is at beginner level, but I have no idea now to deal with this.

Reply With Quote
  #2  
Old February 4th, 2013, 01:28 AM
eliskan eliskan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 43 eliskan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 59 m 28 sec
Reputation Power: 1
Because your code loops through the check 10 times, by the time it's finished, the "l" variable is no longer a list, it's literally the value "results[10]['message']"

Try append:

Code:
l =[]
for i in range (10):
     l.append(results[i]['message'])

Reply With Quote
  #3  
Old February 4th, 2013, 01:42 PM
MynE MynE is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 38 MynE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 18 m 33 sec
Reputation Power: 1
Oh Thank you so much sir, it works

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Save text data from JSON as a list

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap