Re: [Tutor] lambda

2011-03-19 Thread Steven D'Aprano
Ajit Deshpande wrote: I am trying to figure out where lambda functions can be useful. Has anyone used them in real world? Of course. lambdas are especially useful for callback functions, which are especially common when doing GUI programming. From my reading so far, I hear people claim tha

Re: [Tutor] lambda

2011-03-19 Thread Alan Gauld
"Ajit Deshpande" wrote I am trying to figure out where lambda functions can be useful. Has anyone used them in real world? Yers lots of people, all over the place. They are very useful things. Why would anyone use a one liner anonymous function, To pass as an argument to another functio

Re: [Tutor] Waiting until a thread ends

2011-03-19 Thread lists
> > > >> In my continuing quest the find the best way of doing this I came across >> the following method: >> >> for thread in threading.enumerate(): >> if thread is not threading.currentThread(): >> thread.join() >> print 'FINISHED' >> >> In my newbie understanding, you

Re: [Tutor] lambda

2011-03-19 Thread Dave Angel
On 01/-10/-28163 02:59 PM, Ajit Deshpande wrote: I am trying to figure out where lambda functions can be useful. Has anyone used them in real world? From my reading so far, I hear people claim that lambda can be a useful replacement for small functions. Most examples didn't make much sense to

Re: [Tutor] Need some clarification on this

2011-03-19 Thread Dave Angel
On 01/-10/-28163 02:59 PM, Joel Goldstick wrote: 2011/3/19 Yaşar Arabacı a=5 b=5 a == b True a is b True My question is, why "a is b" is true. What I expected it to be is that, a and b are different things with same value. ___ Tutor maillist -

Re: [Tutor] Need some clarification on this

2011-03-19 Thread Ajit Deshpande
This is a special feature called interning in python. As of Python 2.6, values of -5 to 105 are never cleared from memory for performance reasons. This is applicable to integers only. "==" is a value comparator, whereas "is" is a reference compartor. Check this interesting extension to your code:

Re: [Tutor] Need some clarification on this

2011-03-19 Thread Hugo Arts
2011/3/19 Yaşar Arabacı : a=5 b=5 a == b > True a is b > True > > My question is, why "a is b" is true. What I expected it to be is that, a > and b are different things with same value. > It's an optimization thing. When you type "a=5," the python interpreter is obligated to give y

Re: [Tutor] Need some clarification on this

2011-03-19 Thread xDog Walker
On Saturday 2011 March 19 08:35, Emmanuel Ruellan wrote: > 2011/3/19 Yaşar Arabacı > > > >>>a=5 > > >>>b=5 > > >>>a == b > > > > True > > > > >>>a is b > > > > True > > > > My question is, why "a is b" is true. What I expected it to be is that, a > > and b are different things with same value. > >

Re: [Tutor] Need some clarification on this

2011-03-19 Thread Emmanuel Ruellan
2011/3/19 Yaşar Arabacı > > > >>>a=5 > >>>b=5 > >>>a == b > True > >>>a is b > True > > My question is, why "a is b" is true. What I expected it to be is that, a > and b are different things with same value. > Even stranger: >>> a = 10**10 >>> b = 10**10 >>> a == b True >>> a is b False >>> a =

Re: [Tutor] lambda

2011-03-19 Thread bob gailer
In my Python Pipelines program I have the following opts = { 'characters' : (lambda rec, tot: tot + len(rec), 0), 'words' : (lambda rec, tot: tot + len(rec.split()), 0), 'lines' : (lambda rec, tot: tot + 1, 0), 'minline' :(lambda rec, tot: min(len(rec), tot), 9

Re: [Tutor] lambda

2011-03-19 Thread bob gailer
On 3/19/2011 9:44 AM, Ajit Deshpande wrote: I am trying to figure out where lambda functions can be useful. Has anyone used them in real world? From my reading so far, I hear people claim that lambda can be a useful replacement for small functions. Most examples didn't make much sense to me.

Re: [Tutor] lambda

2011-03-19 Thread Adam Bark
On 19/03/11 14:44, Ajit Deshpande wrote: I am trying to figure out where lambda functions can be useful. Has anyone used them in real world? From my reading so far, I hear people claim that lambda can be a useful replacement for small functions. Most examples didn't make much sense to me. Wh

Re: [Tutor] Need some clarification on this

2011-03-19 Thread Joel Goldstick
2011/3/19 Yaşar Arabacı > >>>a=5 > >>>b=5 > >>>a == b > True > >>>a is b > True > > My question is, why "a is b" is true. What I expected it to be is that, a > and b are different things with same value. > > ___ > Tutor maillist - Tutor@python.org > T

Re: [Tutor] Need some clarification on this

2011-03-19 Thread Joel Goldstick
2011/3/19 Yaşar Arabacı > >>>a=5 > >>>b=5 > >>>a == b > True > >>>a is b > True > > My question is, why "a is b" is true. What I expected it to be is that, a > and b are different things with same value. > > ___ > Tutor maillist - Tutor@python.org > T

[Tutor] Need some clarification on this

2011-03-19 Thread Yaşar Arabacı
>>>a=5 >>>b=5 >>>a == b True >>>a is b True My question is, why "a is b" is true. What I expected it to be is that, a and b are different things with same value. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: h

[Tutor] lambda

2011-03-19 Thread Ajit Deshpande
I am trying to figure out where lambda functions can be useful. Has anyone used them in real world? >From my reading so far, I hear people claim that lambda can be a useful replacement for small functions. Most examples didn't make much sense to me. Why would anyone use a one liner anonymous func

Re: [Tutor] Waiting until a thread ends

2011-03-19 Thread lists
> > >> Only really glanced at this, but you seem to be checking only the last >>> thread *after* the loop? Surely you should be storing all the threads in a >>> list (or someplace) as you create them, and then check them all for liveness >>> and if so join them each in turn, to ensure you only pri

Re: [Tutor] binary, ascii, steganography

2011-03-19 Thread Alan Gauld
"Steven D'Aprano" wrote with how to get binary to text, so your suggestions are greatly appreciated. I'll get to it! (0001 = a, 0010 = b, ...) >>> int('01101110', 2) 110 >>> chr(110) 'n' And if you really want to use non standard character values you could look at the string maket