Re: Stupid Python tricks

2016-01-01 Thread Serhiy Storchaka
On 31.12.15 05:51, Steven D'Aprano wrote: Fifteen years later, and Tim Peters' Stupid Python Trick is still the undisputed champion! It may be platform depended, but on my computer the obvious way is 10% faster the Stupid Python Trick. -- https://mail.python.org/mailman/listinfo/python-list

Re: Stupid Python tricks

2016-01-01 Thread Serhiy Storchaka
On 01.01.16 21:00, paul.hermeneu...@gmail.com wrote: On Wed, Dec 30, 2015 at 11:09 PM, Steven D'Aprano wrote: On Thu, 31 Dec 2015 04:02 pm, Rick Johnson wrote: Fifteen years later, and Tim Peters' Stupid Python Trick is still the undisputed champion! And should we be

Re: Stupid Python tricks

2016-01-01 Thread paul . hermeneutic
On Wed, Dec 30, 2015 at 11:09 PM, Steven D'Aprano wrote: > On Thu, 31 Dec 2015 04:02 pm, Rick Johnson wrote: > > >> Fifteen years later, and Tim Peters' Stupid Python Trick is still the > >> undisputed champion! > > > > And should we be happy about that revelation, or sad? >

Stupid Python tricks

2015-12-30 Thread Steven D'Aprano
Stolen^W Inspired from a post by Tim Peters back in 2001: https://mail.python.org/pipermail/python-dev/2001-January/011911.html Suppose you have a huge string, and you want to quote it. Here's the obvious way: mystring = "spam"*10 result = '"' + mystring + '"' But that potentially

Re: Stupid Python tricks

2015-12-30 Thread Steven D'Aprano
On Thu, 31 Dec 2015 04:02 pm, Rick Johnson wrote: > On Wednesday, December 30, 2015 at 9:51:48 PM UTC-6, Steven D'Aprano > wrote: >> Fifteen years later, and Tim Peters' Stupid Python Trick is still the >> undisputed champion! > > And should we be happy about that revelation, or sad? Yes! --

Re: Stupid Python tricks

2015-12-30 Thread Rick Johnson
On Wednesday, December 30, 2015 at 9:51:48 PM UTC-6, Steven D'Aprano wrote: > Fifteen years later, and Tim Peters' Stupid Python Trick is still the > undisputed champion! And should we be happy about that revelation, or sad? -- https://mail.python.org/mailman/listinfo/python-list

Re: Python tricks with applescript in OS-X

2009-12-16 Thread Juanre
Thanks for the pointers to appscript, and for the comments on the page. I have changed the examples at http://juanreyero.com/article/python/os-x-python.html to reflect them. Cheers, Juan -- http://juanreyero.com -- http://mail.python.org/mailman/listinfo/python-list

Python tricks with applescript in OS-X

2009-12-11 Thread joa...@gmail.com
Greetings, I've written a short document with some working examples of how to interface python with other applications in OS-X via applescript (had to spend some time figuring it out, and thought I might as well write it down). The examples include asking Google Earth for the latitude and

Re: Python tricks with applescript in OS-X

2009-12-11 Thread Kevin Walzer
On 12/11/09 3:13 AM, joa...@gmail.com wrote: Greetings, I've written a short document with some working examples of how to interface python with other applications in OS-X via applescript (had to spend some time figuring it out, and thought I might as well write it down). The examples include

Re: Python tricks

2009-01-13 Thread Nick Craig-Wood
Scott David Daniels scott.dani...@acm.org wrote: RajNewbie wrote: On Jan 12, 6:51 pm, Tim Chase python.l...@tim.thechases.com wrote: [a perfectly fine reply which is how I'd solve it] RajNewbie wrote: ... The solution that I had in mind is: while True: ... if

Python tricks

2009-01-12 Thread RajNewbie
Hi, My code has a lot of while loops of the following format: while True: ... if condition: break The danger with such a code is that it might go to an infinite loop - if the condition never occurs. Is there a way - a python trick - to have a check such that if the loop goes

Re: Python tricks

2009-01-12 Thread Ben Finney
RajNewbie raj.indian...@gmail.com writes: Could someone chip in with other suggestions? Set up an iterable that will end under the right conditions. Then, iterate over that with ‘for foo in that_iterable’. This idiom is usually far more expressive than any tricks with ‘while’ loops and ‘break’

Re: Python tricks

2009-01-12 Thread Tim Chase
My code has a lot of while loops of the following format: while True: ... if condition: break The danger with such a code is that it might go to an infinite loop - if the condition never occurs. Is there a way - a python trick - to have a check such that if the loop goes

Re: Python tricks

2009-01-12 Thread RajNewbie
On Jan 12, 6:51 pm, Tim Chase python.l...@tim.thechases.com wrote:    My code has a lot of while loops of the following format:    while True:      ...      if condition: break    The danger with such a code is that it might go to an infinite loop - if the condition never occurs.    

Re: Python tricks

2009-01-12 Thread Paul Rubin
RajNewbie raj.indian...@gmail.com writes: I do understand that we can use the code like - i = 0 while True: i++ if i 200: raise infinite_Loop_Exception ... if condition: break But I am not very happy with this code for 3 reasons I prefer: from

Re: Python tricks

2009-01-12 Thread John Machin
On Jan 13, 12:51 am, Tim Chase python.l...@tim.thechases.com took a walk on the OT side: Could someone chip in with other suggestions? As an aside:  the phrase is chime in[1] (to volunteer suggestions) Chip in[2] usually involves contributing money to a common fund (care to chip in $10 for

Re: Python tricks

2009-01-12 Thread Scott David Daniels
RajNewbie wrote: On Jan 12, 6:51 pm, Tim Chase python.l...@tim.thechases.com wrote: [a perfectly fine reply which is how I'd solve it] RajNewbie wrote: ... The solution that I had in mind is: while True: ... if condition: break if inifinte_loop(): raise

Re: Python tricks

2009-01-12 Thread Robert Latest
RajNewbie wrote: Is there a way - a python trick - to have a check such that if the loop goes for more than x number of steps, it will cause an exception? I do understand that we can use the code like - i = 0 while True: i++ if i 200: raise infinite_Loop_Exception

Re: Python tricks

2009-01-12 Thread Robert Latest
RajNewbie wrote: But, I still feel it would be much more aesthetically pleasing if I can call a single procedure like if infinite_loop() - to do the same. You may find it aesthetically pleasing, and it may very well be, but it will obfuscate your code and make it less maintainable. robert --