Prev: TypeError: _new_() takes exactly 3 arguments (2 given) - what doesit mean?
Next: Python and Tkinter Programming by John Grayson
From: Gabriel Genellina on 5 Jun 2010 06:11 On 31 mayo, 08:11, moerchendiser2k3 <googler. 1.webmas...(a)spamgourmet.com> wrote: > you are right, Python still holds the last > reference. I just set a dummy and thats it :) > > Can you tell me where did you get the information from? Do you mean the _ variable? It's in the tutorial: http://docs.python.org/tutorial/introduction.html#using-python-as-a-calculator -- Gabriel Genellina
From: moerchendiser2k3 on 6 Jun 2010 06:30 thx, thats it! :)
From: Mark Lawrence on 17 Jun 2010 17:32 On 05/06/2010 11:11, Gabriel Genellina wrote: > On 31 mayo, 08:11, moerchendiser2k3<googler. > 1.webmas...(a)spamgourmet.com> wrote: > >> you are right, Python still holds the last >> reference. I just set a dummy and thats it :) >> >> Can you tell me where did you get the information from? > > Do you mean the _ variable? > It's in the tutorial: > http://docs.python.org/tutorial/introduction.html#using-python-as-a-calculator > > -- > Gabriel Genellina I have always believed that the _ variable is only available interactively because of this comment in the tutorial:- "In interactive mode, the last printed expression is assigned to the variable _. This means that when you are using Python as a desk calculator, it is somewhat easier to continue calculations, for example: ...." However a thread from IIRC a couple of days back used _ to say "I'm not interested in you, I'm throwing you away" in a list comprehension or whatever. I've tried this in a script this evening and it works perfectly. print 'total', sum(amount for _, amount in outputs) Where is the use of _ in a script documented, I've searched all over and can't find it, guess I don't have the Midas touch with google? :) Kindest regards. Mark Lawrence.
From: Stephen Hansen on 17 Jun 2010 17:51 On 6/17/10 2:32 PM, Mark Lawrence wrote: > Where is the use of _ in a script documented, I've searched all over and > can't find it, guess I don't have the Midas touch with google? :) Its purely a convention, and one that crosses language-bounds, and isn't entirely universal even given that. It just means 'placeholder that I care naught for'; its not a feature, there's no code or any /ability/ to use it. Its the same as any other variable name. It just happens to be a name that conveys no meaning while being short and visually distinct: except to say you don't care about what value ends up there, consider it thrown away. That the interactive interpreter happens to store the last value in a variable of the same name doesn't really mean anything. -- Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/
From: Mark Lawrence on 17 Jun 2010 19:18
On 17/06/2010 22:51, Stephen Hansen wrote: > On 6/17/10 2:32 PM, Mark Lawrence wrote: >> Where is the use of _ in a script documented, I've searched all over and >> can't find it, guess I don't have the Midas touch with google? :) > > Its purely a convention, and one that crosses language-bounds, and isn't > entirely universal even given that. > > It just means 'placeholder that I care naught for'; its not a feature, > there's no code or any /ability/ to use it. Its the same as any other > variable name. > > It just happens to be a name that conveys no meaning while being short > and visually distinct: except to say you don't care about what value > ends up there, consider it thrown away. > > That the interactive interpreter happens to store the last value in a > variable of the same name doesn't really mean anything. > > Thanks Stephen, don't think I'll lose any sleep over it then. :) Cheers. Mark Lawrence. |