Re: [Tutor] How to extract numerator and denominator from fractions.Fraction(4, 32)?

2013-08-06 Thread Alan Gauld
On 06/08/13 08:16, Jim Mooney wrote: class IterableFraction(Fraction): def __iter__(self): yield self.numerator yield self.denominator Seriously, though, I thought yield was like return - one and you're done - how are you getting two yields in there? yield a

Re: [Tutor] How to extract numerator and denominator from fractions.Fraction(4, 32)?

2013-08-06 Thread Steven D'Aprano
On Tue, Aug 06, 2013 at 08:58:31AM +0100, Alan Gauld wrote: > On 06/08/13 08:16, Jim Mooney wrote: > > >>class IterableFraction(Fraction): > >> def __iter__(self): > >> yield self.numerator > >> yield self.denominator > > >Seriously, though, I thought yield was like

Re: [Tutor] How to extract numerator and denominator from fractions.Fraction(4, 32)?

2013-08-06 Thread Alan Gauld
On 06/08/13 09:26, Steven D'Aprano wrote: All this is correct, but yield is more powerful than that. Not only does yield get used to return values from a function, it also gets used to send values *into* a running function. Yikes. This is new to me too. When did that happen? Has yield always h

Re: [Tutor] How to extract numerator and denominator from fractions.Fraction(4, 32)?

2013-08-06 Thread Walter Prins
Hi Steven, Alan, On 6 August 2013 09:44, Alan Gauld wrote: > On 06/08/13 09:26, Steven D'Aprano wrote: > > All this is correct, but yield is more powerful than that. Not only does >> yield get used to return values from a function, it also gets used to >> send values *into* a running function.

Re: [Tutor] adding users to tweets on a list

2013-08-06 Thread Saad Javed
> It looks like you're using Python 2, but you didn't specify. > > I'd probably do something like this: > > #!/usr/bin/env python > > MAX_LENGTH = 140 > > users = [ > "saad", "asad", "sherry", "danny", "ali", "hasan", "adil", > "yousaf", > "maria", "bilal", "owais", >

Re: [Tutor] How to extract numerator and denominator from fractions.Fraction(4, 32)?

2013-08-06 Thread Alan Gauld
On 06/08/13 10:01, Walter Prins wrote: py> def cr(): # Co-Routine. ... x = yield() ... while True: ... x = yield(x + 1) ... "send" and yield as akin to threaded execution, where cr() is like a thread that blocks at the yield call af

Re: [Tutor] adding users to tweets on a list

2013-08-06 Thread Saad Javed
> Ah, I see. Sorry, I misread your requirements. Something like this should > work. > > #!/usr/bin/env python > > MAX_LENGTH = 140 > > > class TweetTooLongError(Exception): > """ > Raised when a user would be too long to add to the tweet, even > alone. > """ >

Re: [Tutor] adding users to tweets on a list

2013-08-06 Thread Saad Javed
> ...or, better, remove the if...break and just do: > > while users and len(new_message) + len(add) <= MAX_LENGTH: > 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

Re: [Tutor] adding users to tweets on a list

2013-08-06 Thread Saad Javed
> > And the earlier fix now adds two users to a tweet, then one user, then two > user, then one... :( > 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: These are my friends living in the same city as i am.

Re: [Tutor] adding users to tweets on a list

2013-08-06 Thread Saad Javed
> 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 lim

Re: [Tutor] adding users to tweets on a list

2013-08-06 Thread Saad Javed
I added *len(new_message) + len(add) <= MAX_LENGTH *to the outer while loop instead of inner which threw an error. Your code works as expected. Thanks a lot! Saad ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http

Re: [Tutor] adding users to tweets on a list

2013-08-06 Thread Dave Angel
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(m

Re: [Tutor] How to extract numerator and denominator from fractions.Fraction(4, 32)?

2013-08-06 Thread Alan Gauld
On 06/08/13 18:56, Oscar Benjamin wrote: py> def cr(): # Co-Routine. ... x = yield() ... while True: ... x = yield(x + 1) ... I'm not keen on the argument/parameter mechanism here either. Arguments are sent but not explicitly de