[Tutor] adding users to tweets on a list

Chris Down chris at chrisdown.name
Tue Aug 6 19:57:02 CEST 2013


On 2013-08-06 22:49, Saad Javed wrote:
> That causes:
>
> Enter 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:
> Traceback (most recent call last):
>   File "chris_tweet_len.py", line 44, in <module>
>     print("\n".join(generate_tweets(message, users)))
>   File "chris_tweet_len.py", line 31, in generate_tweets
>     while users and len(new_message) + len(add) <= MAX_LENGTH:
> UnboundLocalError: local variable 'new_message' referenced before assignment

Cannot reproduce. I'm not sure how you edited the script, but somehow you moved
new_message to where it is unbound. See attached.

> And the earlier fix now adds two users to a tweet, then one user, then two
> user, then one... :(

I don't see how that differs from your expected output...?

> I want all users added to the tweet. E.g. if 4 users can be added to the
> tweet before reaching the limit, return three tweets...first two with 4 users
> attached and the last one with three.

You hit the 140 character limit if another user is added, so it resets to the
base message and adds the next user(s) as possible.

What is your expected output for that sample input?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tweet.py
Type: text/x-python
Size: 1151 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20130806/788b1b2c/attachment-0001.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20130806/788b1b2c/attachment-0001.pgp>


More information about the Tutor mailing list