Re: Supply condition in function call

2015-03-29 Thread Manuel Graune
Cameron Simpson writes: > > In xterm and I think several other X11 terminals, Shift-Insert > pastes. I found that _way_ more convenient than middle click. The > mouse is not your friend. > This information might prove as useful as your answer to my original question. ;-) Thanks for both! -- A

Re: Supply condition in function call

2015-03-29 Thread Cameron Simpson
On 28Mar2015 20:57, Steven D'Aprano wrote: On Sat, 28 Mar 2015 08:19 pm, Ian Kelly wrote: I've never been a fan of the primary selection style anyway. Copying text is conceptually an action. Selecting text is how one indicates the target of an action; conceptually it is not an action itself an

Re: Supply condition in function call

2015-03-28 Thread Steven D'Aprano
On Sat, 28 Mar 2015 08:19 pm, Ian Kelly wrote: > I've never been a fan of the primary selection style anyway. Copying > text is conceptually an action. Selecting text is how one indicates > the target of an action; conceptually it is not an action itself and > shouldn't cause an action to be perfo

Re: Supply condition in function call

2015-03-28 Thread Steven D'Aprano
On Sat, 28 Mar 2015 06:50 pm, Marko Rauhamaa wrote: > Larry Hudson : > >> Highlight the selection you want copied, move the mouse cursor to the >> location you want it copied to and middle-click with the mouse. Works >> between programs as well as within a single program. And it copies >> directl

Re: Supply condition in function call

2015-03-28 Thread Ian Kelly
On Sat, Mar 28, 2015 at 1:50 AM, Marko Rauhamaa wrote: > Larry Hudson : > >> Highlight the selection you want copied, move the mouse cursor to the >> location you want it copied to and middle-click with the mouse. Works >> between programs as well as within a single program. And it copies >> direc

Re: Supply condition in function call

2015-03-28 Thread Marko Rauhamaa
Larry Hudson : > Highlight the selection you want copied, move the mouse cursor to the > location you want it copied to and middle-click with the mouse. Works > between programs as well as within a single program. And it copies > directly without going through the clipboard. Unfortunately, Linux

Re: Supply condition in function call

2015-03-28 Thread Chris Angelico
On Sat, Mar 28, 2015 at 6:32 PM, Steven D'Aprano wrote: >> | Methods defined here: > > This is the usual guff that help() prints when you pass it a class or type. > Occasionally it is useful. Often it is not, especially the dunder methods. > > Unfortunately help's UI is rather primitive. It woul

Re: Supply condition in function call

2015-03-28 Thread Steven D'Aprano
By the way, you're not alone in recognising that Python 3 may be a little harder to teach to beginners than Python 2. Raymond Hettinger, one of the most respected Pythonistas around, has pointed out the same thing. More below. On Sat, 28 Mar 2015 12:48 am, Rustom Mody wrote: > On Friday, March

Re: Supply condition in function call

2015-03-27 Thread Rustom Mody
On Saturday, March 28, 2015 at 5:57:08 AM UTC+5:30, Larry Hudson wrote: > On 03/26/2015 06:56 PM, Chris Angelico wrote: > > On Fri, Mar 27, 2015 at 12:41 PM, Rustom Mody wrote: > [snip] > >> After selecting the line above [inside python inside help(filter) ]for > >> cut-pasting here, by mistake I p

Re: Supply condition in function call

2015-03-27 Thread Larry Hudson
On 03/26/2015 06:56 PM, Chris Angelico wrote: On Fri, Mar 27, 2015 at 12:41 PM, Rustom Mody wrote: [snip] After selecting the line above [inside python inside help(filter) ]for cut-pasting here, by mistake I pressed Ctrl-C rather than Ctrl-Shift-C An exception was thrown and the terminal remai

Re: Supply condition in function call

2015-03-27 Thread Cameron Simpson
On 27Mar2015 21:02, Manuel Graune wrote: Cameron Simpson writes: This passes the local variables inside test1() to "condition" as a single parameter. Now, I grant that vars['i'] is a miracle of tediousness. So consider this elaboration: from collections import namedtuple condition_test =

Re: Supply condition in function call

2015-03-27 Thread Peter Otten
Manuel Graune wrote: > Peter Otten <__pete...@web.de> writes: > >> Cameron Simpson wrote: >> >>> test1([0,1,2,3], [1,2,3,4], condition_test) >>> >>> This passes the local variables inside test1() to "condition" as a >>> single parameter. Now, I grant that vars['i'] is a miracle of >>> tediousn

Re: Supply condition in function call

2015-03-27 Thread Manuel Graune
Cameron Simpson writes: > This passes the local variables inside test1() to "condition" as a > single parameter. Now, I grant that vars['i'] is a miracle of > tediousness. So consider this elaboration: > > from collections import namedtuple > > condition_test = lambda vars: vars.i + vars.j > 4

Re: Supply condition in function call

2015-03-27 Thread Manuel Graune
Peter Otten <__pete...@web.de> writes: > Cameron Simpson wrote: > >> test1([0,1,2,3], [1,2,3,4], condition_test) >> >> This passes the local variables inside test1() to "condition" as a single >> parameter. Now, I grant that vars['i'] is a miracle of tediousness. So >> consider this elaboration

Re: Supply condition in function call

2015-03-27 Thread Mark Lawrence
On 27/03/2015 13:48, Rustom Mody wrote: On Friday, March 27, 2015 at 10:05:21 AM UTC+5:30, Steven D'Aprano wrote: On Fri, 27 Mar 2015 01:21 pm, Rustom Mody wrote: Anyway my point is that in python (after 2.2??) saying something is an object is a bit of a tautology -- ie verbiage without inform

Re: Supply condition in function call

2015-03-27 Thread Chris Angelico
On Sat, Mar 28, 2015 at 12:48 AM, Rustom Mody wrote: > Knows some C, not much else. > Starts studying python. > Good until a point. > Then suddenly hit... map, filter, and the worst of all lambda. > More he reads less he understands. > Tries help... Gets the above. > > So which do you think helps

Re: Supply condition in function call

2015-03-27 Thread Rustom Mody
On Friday, March 27, 2015 at 10:05:21 AM UTC+5:30, Steven D'Aprano wrote: > On Fri, 27 Mar 2015 01:21 pm, Rustom Mody wrote: > > > Anyway my point is that in python (after 2.2??) saying something is an > > object is a bit of a tautology -- ie verbiage without information. > > > Er, it's *always*

Re: Supply condition in function call

2015-03-27 Thread Dave Angel
On 03/26/2015 09:41 PM, Rustom Mody wrote: On Thursday, March 26, 2015 at 11:30:57 AM UTC+5:30, Chris Angelico wrote: Python 3.5.0a0 (default:4709290253e3, Jan 20 2015, 21:48:07) [GCC 4.7.2] on linux class filter(object) | filter(function or None, iterable) --> filter object | | Retur

Re: Supply condition in function call

2015-03-26 Thread Steven D'Aprano
On Fri, 27 Mar 2015 01:21 pm, Rustom Mody wrote: > Anyway my point is that in python (after 2.2??) saying something is an > object is a bit of a tautology -- ie verbiage without information. Er, it's *always* been a tautology. Every value in Python is an object, including classes, and that has b

Re: Supply condition in function call

2015-03-26 Thread Rustom Mody
On Friday, March 27, 2015 at 7:56:16 AM UTC+5:30, Ian wrote: > On Thu, Mar 26, 2015 at 7:56 PM, Chris Angelico wrote: > >> On a more specific note, its the 1st line: > >> > >> class filter(object) > >> > >> which knocks me off. > >> If a more restricted type from the ABC was shown which exactly ca

Re: Supply condition in function call

2015-03-26 Thread Rustom Mody
On Friday, March 27, 2015 at 7:26:54 AM UTC+5:30, Chris Angelico wrote: > On Fri, Mar 27, 2015 at 12:41 PM, Rustom Mody wrote: > > On a more specific note, its the 1st line: > > > > class filter(object) > > > > which knocks me off. > > If a more restricted type from the ABC was shown which exactly

Re: Supply condition in function call

2015-03-26 Thread Ian Kelly
On Thu, Mar 26, 2015 at 7:56 PM, Chris Angelico wrote: >> On a more specific note, its the 1st line: >> >> class filter(object) >> >> which knocks me off. >> If a more restricted type from the ABC was shown which exactly captures all >> the iterator-specific stuff like __iter__, __next__ it would

Re: Supply condition in function call

2015-03-26 Thread Chris Angelico
On Fri, Mar 27, 2015 at 12:41 PM, Rustom Mody wrote: > On Thursday, March 26, 2015 at 11:30:57 AM UTC+5:30, Chris Angelico wrote: >> On Thu, Mar 26, 2015 at 3:02 PM, Rustom Mody wrote: >> > [And BTW >> > help(filter) in python2 is much better documention than in python3 >> > ] >> >> Python 2.7.3

Re: Supply condition in function call

2015-03-26 Thread Rustom Mody
On Thursday, March 26, 2015 at 11:30:57 AM UTC+5:30, Chris Angelico wrote: > On Thu, Mar 26, 2015 at 3:02 PM, Rustom Mody wrote: > > [And BTW > > help(filter) in python2 is much better documention than in python3 > > ] > > Python 2.7.3 (default, Mar 13 2014, 11:03:55) > [GCC 4.7.2] on linux2 > >

Re: Supply condition in function call

2015-03-26 Thread Cameron Simpson
On 26Mar2015 11:37, Peter Otten <__pete...@web.de> wrote: You are right. [...] By the way, in this case you don't need the list at all: def vartuple(vars): return namedtuple("locals", vars)._make(vars.values()) Hmm. Neat. I had not realised that was available. You'd need "vars.keys()", no

Re: Supply condition in function call

2015-03-26 Thread Grant Edwards
On 2015-03-25, Ian Kelly wrote: > On Wed, Mar 25, 2015 at 1:53 PM, Grant Edwards > wrote: >> On 2015-03-25, Ian Kelly wrote: >>> On Wed, Mar 25, 2015 at 11:29 AM, Manuel Graune >>> wrote: >>> I'm looking for a way to supply a condition to an if-statement inside a function body when

Re: Supply condition in function call

2015-03-26 Thread Peter Otten
Cameron Simpson wrote: > On 26Mar2015 10:03, Peter Otten <__pete...@web.de> wrote: >>Cameron Simpson wrote: >>> vars = locals() >>> varnames = list(vars.keys()) >> >>That leaves varnames in undefined order. Consider >> >>varnames = sorted(vars) > > Actually, not necessary. > > I star

Re: Supply condition in function call

2015-03-26 Thread Cameron Simpson
On 26Mar2015 10:03, Peter Otten <__pete...@web.de> wrote: Cameron Simpson wrote: vars = locals() varnames = list(vars.keys()) That leaves varnames in undefined order. Consider varnames = sorted(vars) Actually, not necessary. I started with sorted, but it is irrelevant, so I bac

Re: Supply condition in function call

2015-03-26 Thread Peter Otten
Cameron Simpson wrote: > On 26Mar2015 07:27, Manuel Graune wrote: >>Gary Herron writes: >>> On 03/25/2015 10:29 AM, Manuel Graune wrote: def test1(a, b, condition="True"): for i,j in zip(a,b): c=i+j if eval(condition): print("Foo")

Re: Supply condition in function call

2015-03-26 Thread Cameron Simpson
On 26Mar2015 07:27, Manuel Graune wrote: Gary Herron writes: On 03/25/2015 10:29 AM, Manuel Graune wrote: def test1(a, b, condition="True"): for i,j in zip(a,b): c=i+j if eval(condition): print("Foo") test1([0,1,2,3],[1,2,3,4],"i+j >4") print("Bar") test1([

Re: Supply condition in function call

2015-03-25 Thread Manuel Graune
Gary Herron writes: > On 03/25/2015 10:29 AM, Manuel Graune wrote: >> >> def test1(a, b, condition="True"): >> for i,j in zip(a,b): >> c=i+j >> if eval(condition): >> print("Foo") >> >> test1([0,1,2,3],[1,2,3,4],"i+j >4") >> print("Bar") >> test1([0,1,2,3],[1,2,

Re: Supply condition in function call

2015-03-25 Thread Chris Angelico
On Thu, Mar 26, 2015 at 3:02 PM, Rustom Mody wrote: > [And BTW > help(filter) in python2 is much better documention than in python3 > ] Python 2.7.3 (default, Mar 13 2014, 11:03:55) [GCC 4.7.2] on linux2 filter(...) filter(function or None, sequence) -> list, tuple, or string Return tho

Re: Supply condition in function call

2015-03-25 Thread Rustom Mody
On Thursday, March 26, 2015 at 12:44:03 AM UTC+5:30, Gary Herron wrote: > On 03/25/2015 10:29 AM, Manuel Graune wrote: > > Hi, > > > > I'm looking for a way to supply a condition to an if-statement inside a > > function body when calling the function. I can sort of get what I want > > with using ev

Re: Supply condition in function call

2015-03-25 Thread Ian Kelly
On Wed, Mar 25, 2015 at 1:53 PM, Grant Edwards wrote: > On 2015-03-25, Ian Kelly wrote: >> On Wed, Mar 25, 2015 at 11:29 AM, Manuel Graune >> wrote: >> >>> I'm looking for a way to supply a condition to an if-statement inside a >>> function body when calling the function. I can sort of get what

Re: Supply condition in function call

2015-03-25 Thread Grant Edwards
On 2015-03-25, Ian Kelly wrote: > On Wed, Mar 25, 2015 at 11:29 AM, Manuel Graune > wrote: > >> I'm looking for a way to supply a condition to an if-statement inside a >> function body when calling the function. I can sort of get what I want >> with using eval [...] > > Pass the condition as a f

Re: Supply condition in function call

2015-03-25 Thread Gary Herron
On 03/25/2015 10:29 AM, Manuel Graune wrote: Hi, I'm looking for a way to supply a condition to an if-statement inside a function body when calling the function. I can sort of get what I want with using eval (see code below) but I would like to achieve this in a safer way. If there is a solution

Re: Supply condition in function call

2015-03-25 Thread Terry Reedy
On 3/25/2015 1:29 PM, Manuel Graune wrote: Hi, I'm looking for a way to supply a condition to an if-statement inside a function body when calling the function. I can sort of get what I want with using eval (see code below) but I would like to achieve this in a safer way. If there is a solution w

Re: Supply condition in function call

2015-03-25 Thread Joel Goldstick
On Wed, Mar 25, 2015 at 2:22 PM, Ian Kelly wrote: > On Wed, Mar 25, 2015 at 12:17 PM, Joel Goldstick > wrote: >> Oh, now I see. Do you know about this: >> https://docs.python.org/2/library/ast.html#ast.literal_eval > > As the name suggests, that only evals literals. It won't work for > complex e

Re: Supply condition in function call

2015-03-25 Thread Ian Kelly
On Wed, Mar 25, 2015 at 12:17 PM, Joel Goldstick wrote: > Oh, now I see. Do you know about this: > https://docs.python.org/2/library/ast.html#ast.literal_eval As the name suggests, that only evals literals. It won't work for complex expressions like "i + j > 4" -- https://mail.python.org/mailma

Re: Supply condition in function call

2015-03-25 Thread Joel Goldstick
On Wed, Mar 25, 2015 at 1:51 PM, Manuel Graune wrote: > Joel Goldstick writes: > >> On Wed, Mar 25, 2015 at 1:29 PM, Manuel Graune >> wrote: >>> >>> def test1(a, b, condition="True"): >>> for i,j in zip(a,b): >>> c=i+j >>> if eval(condition): >>>print("Foo") >>>

Re: Supply condition in function call

2015-03-25 Thread Manuel Graune
Joel Goldstick writes: > On Wed, Mar 25, 2015 at 1:29 PM, Manuel Graune wrote: >> >> def test1(a, b, condition="True"): >> for i,j in zip(a,b): >> c=i+j >> if eval(condition): >>print("Foo") >> > I'm not sure I understand your question, but condition will evaluate

Re: Supply condition in function call

2015-03-25 Thread Ian Kelly
On Wed, Mar 25, 2015 at 11:29 AM, Manuel Graune wrote: > Hi, > > I'm looking for a way to supply a condition to an if-statement inside a > function body when calling the function. I can sort of get what I want > with using eval (see code below) but I would like to achieve this in a > safer way. If

Re: Supply condition in function call

2015-03-25 Thread Joel Goldstick
On Wed, Mar 25, 2015 at 1:29 PM, Manuel Graune wrote: > Hi, > > I'm looking for a way to supply a condition to an if-statement inside a > function body when calling the function. I can sort of get what I want > with using eval (see code below) but I would like to achieve this in a > safer way. If

Supply condition in function call

2015-03-25 Thread Manuel Graune
Hi, I'm looking for a way to supply a condition to an if-statement inside a function body when calling the function. I can sort of get what I want with using eval (see code below) but I would like to achieve this in a safer way. If there is a solution which is safer while being less flexible, that