I’m using sqlalchemy-flask for my projects as well as json module.
I have two classes I’m pulling data from.
The two data types are Ints and List (I made sure of this by using type). When I try to append the int to the list I get None. Whats wrong?
def update_retweet_count(TWEET, TWEET_has_retweet):
if type(json.loads(TWEET_has_retweet.js_rt)) != list:
list_of_retweets = list([0])
else:
list_of_retweets = list(json.loads(TWEET_has_retweet.js_rt))
new_rtc = int(TWEET.tmp_rt_count)
x = list_of_retweets.append(new_rtc)
print x
When I run above X is None.
4 Hours later I try this below and It works!
def update_retweet_count(TWEET, TWEET_has_retweet):
if type(json.loads(TWEET_has_retweet.js_rt)) != list:
list_of_retweets = list([0])
else:
list_of_retweets = list(json.loads(TWEET_has_retweet.js_rt))
lst =[]
new_rtc = int(TWEET.tmp_rt_count)
[lst.append(y) for y in list_of_retweets]
lst.append(new_rtc)
print lst
Why does the first code not work?
Thank you!
Fernando
list.appendalways returnsNone: it changes the list in place. You do:in the first example and:
in the second (correct) example.