list - Filter return results printed in text file python -
using code:
from pysnap import snapchat pprint import pprint s = snapchat() username = raw_input('enter username: ') password = raw_input('enter password: ') s.login(username, password) friends = s.get_friends() newfile = open("newfile.txt", "a") pprint(friends, newfile)
it prints return / results of get_friends() great, want.
but.
the results this:
{u'can_see_custom_stories': true, u'direction': u'outgoing', u'display': u'', u'name': u'a7twini', #a7twini being username here u'type': 0},
the thing want display is:
a7twini <nextusername> <nextusername> etc..
is there way "filter" these results? making sure name ends in text file?
i hope can me, thanks!
edit: asked get_friends() function
def get_friends(self): """get friends returns list of friends. """ return self.get_updates().get('friends', [])
you can print name
entry each friend. assuming friends
list:
for friend in friends: newfile.write(friend[u'name'] + "\n")
or use list comprehension:
newfile.writelines([friend[u'name'] + "\n" friend in friends])
Comments
Post a Comment