[Tutor] adding users to tweets on a list

Dave Angel davea at davea.name
Tue Aug 6 20:36:09 CEST 2013


Saad Javed wrote:

> I want to add users to the tweet from the list, the no. of users added
> based on the length of the tweet.
>
This version should be a bit cleaner than what I've seen on this thread.

#!/usr/bin/env python

LIMIT = 140
#(I use uppercase there to show it's a constant)

def send(message, users):
    output = message
    while users:
        while users and 1+len(output+users[0]) < LIMIT:
            output += " " + users.pop(0)
        if output == message:
            print "message too long for user", user[0]
            raise userError
        print output
        output = message

lst = ['@saad', '@asad', '@sherry', '@danny', '@ali', '@hasan',
'@adil', '@yousaf', '@maria', '@bilal', '@owais']


#string = raw_input('enter string: ')
#example string
string = ("These are my friends living in the same city as i am."
" I have known them for years. They are "
"good people in general. They are:")

send(string, lst)

BTW, you have a bunch of other messages on the thread which are replying
to the invisible man, posts that aren't (yet?) visible.  Since you quote
him without attribution, we have no clue who you're commenting about.

-- 
DaveA




More information about the Tutor mailing list