Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread Thomas Passin
On 3/10/2023 11:15 PM, aapost wrote: On 3/10/23 22:16, Thomas Passin wrote: [...] The additional note in the above is, when taking the def route above, the thing you would have to consider is what scope is the dictionary pids? Do you need to submit it to the lambda and subsequently the functi

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread aapost
On 3/10/23 22:16, Thomas Passin wrote: On 3/10/2023 7:07 PM, aapost wrote: which does start to break down readability due to line length, as there isn't really an indention rule set for something uncommonly used. but some renaming makes the pattern clearer pids.update({"messages" :subprocess.

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread Thomas Passin
On 3/10/2023 10:37 PM, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2023-03-10 at 22:16:05 -0500, Thomas Passin wrote: I'd make the pattern in this example even more understandable and less error-prone: def update_pids(target): cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] p

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread 2QdxY4RzWzUUiLuE
On 2023-03-10 at 22:16:05 -0500, Thomas Passin wrote: > I'd make the pattern in this example even more understandable and less > error-prone: > > def update_pids(target): > cmd = ["tail", "-n", "1", "-f", f"/var/log/{target}"] > pids.update({target: subprocess.Popen(cmd)}) if not \ >

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread Thomas Passin
On 3/10/2023 7:07 PM, aapost wrote: which does start to break down readability due to line length, as there isn't really an indention rule set for something uncommonly used. but some renaming makes the pattern clearer pids.update({"messages" :subprocess.Popen(["cmd1"])}) if not pids["messages

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread aapost
On 3/9/23 15:25, Thomas Passin wrote: >>> # this is a code snippet from a Tkinter gui app >>> # in this case lambda is quite convenient >>> self.btn_cancel = Button(self.progress_container, text='Cancel', >>> command=lambda: subprocess.call('taskkill /f /im uberzip.exe', >>> shell=Tr

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread aapost
On 3/10/23 18:46, aapost wrote:     main.pids.update({"messages" :subprocess.Popen(["tail", "-n", "1", "-f", "/var/log/messages"])}),     main.pids.update({"syslog" :subprocess.Popen(["tail", "-n", "1", "-f", "/var/log/syslog"])}),     main.pids.update({"kern" :subprocess.Popen([

Re: Lambda returning tuple question, multi-expression

2023-03-10 Thread Cameron Simpson
On 09Mar2023 17:55, aapost wrote: On 3/9/23 16:37, Cameron Simpson wrote: Just a note that some code formatters use a trailing comma on the last element to make the commas fold points. Both yapf (my preference) and black let you write a line like (and, indeed, flatten if short enough):    

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread aapost
On 3/9/23 16:37, Cameron Simpson wrote: On 09Mar2023 09:06, Alan Gauld wrote: Just a note that some code formatters use a trailing comma on the last element to make the commas fold points. Both yapf (my preference) and black let you write a line like (and, indeed, flatten if short enough):

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread aapost
On 3/9/23 04:06, Alan Gauld wrote: Thank you for the feedback, I appreciate the comments. To add a little extra, there is actually a reason I lean toward overuse of .config() for a lot of things even though they could be sent to the constructor (other than that w["attribute"]= doesn't work

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Chris Angelico
On Fri, 10 Mar 2023 at 07:43, Thomas Passin wrote: > > On 3/9/2023 3:29 AM, aapost wrote: > > The 'what I am trying to do' is ask a question regarding opinions and > > practices on issuing a sequence of actions within a lambda via a tuple > > (since the common practice approaches against it - main

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Cameron Simpson
On 09Mar2023 09:06, Alan Gauld wrote: Also layout is all important here. It could get very messy to read if indentation isn't clear. You only have to look at some Javascript code with function definitions as arguments to functions to see how clunky that can be. Just a note that some code forma

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Cameron Simpson
On 09Mar2023 09:06, Alan Gauld wrote: On 08/03/2023 21:56, aapost wrote: When making a UI there are a lot of binding/trace operations that need to occur that lead to a lot of annoying 1 use function definitions. I don't really see lambda use like below. Lambdas are very common in GUI callback

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Thomas Passin
On 3/9/2023 3:29 AM, aapost wrote: The 'what I am trying to do' is ask a question regarding opinions and practices on issuing a sequence of actions within a lambda via a tuple (since the common practice approaches against it - mainly with tkinter - feel more convoluted), and in doing so leaving

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread aapost
On 3/9/23 00:13, Thomas Passin wrote: lol.. 'us'.. So.. to give an example from your own code: but_play = Tk.Button(_frame, text='Play', width = BUTTONWIDTH + 1, pady = PADY, command=lambda x=plotmgr:play_macro(x), bg = BUTTON_BG, font = NEWFONT) Can be written as: b = Tk.Button(master=

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Weatherby,Gerard
t;,command=e) or b = tk.Button(master=main, text="Enable",command=lambda: [e.config(state="normal") for e in (e1, e2, e3)]) From: Python-list on behalf of aapost Date: Wednesday, March 8, 2023 at 5:15 PM To: python-list@python.org Subject: Lambda returning tuple question,

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Alan Gauld
On 08/03/2023 21:56, aapost wrote: > When making a UI there are a lot of binding/trace operations that need > to occur that lead to a lot of annoying 1 use function definitions. I > don't really see lambda use like below. Lambdas are very common in GUI callbacks but I admit I've never seen tuple

Re: Lambda returning tuple question, multi-expression

2023-03-08 Thread Thomas Passin
On 3/8/2023 11:19 PM, aapost wrote: > In both cases (as per my intent) Well, that's the trouble. You haven't stated your intent, so we're forced to try to reverse engineer it. Below I state what my reverse-engineering effort thinks is your intent. It would be better if you actually said clea

Re: Lambda returning tuple question, multi-expression

2023-03-08 Thread aapost
On 3/8/23 16:56, aapost wrote: Thomas > Cameron def set_entries_enabled_state(enabled = True): state = 'normal' if enabled else 'disabled' for e in (e1, e2, e3): e.config(state=state) def config_b_and_entries(enabled = True): state = 'normal' if enabled else 'disabled'

Re: Lambda returning tuple question, multi-expression

2023-03-08 Thread Cameron Simpson
On 08Mar2023 16:56, aapost wrote: When making a UI there are a lot of binding/trace operations that need to occur that lead to a lot of annoying 1 use function definitions. I don't really see lambda use like below. Giving 2 working lambda examples using a returned tuple to accomplish multipl

Re: Lambda returning tuple question, multi-expression

2023-03-08 Thread Thomas Passin
On 3/8/2023 4:56 PM, aapost wrote: b = tk.Button(master=main, text="Enable") b.config(     command=lambda: (     e1.config(state="normal"),     e2.config(state="normal"),     e3.config(state="normal")     ) ) It's hard to understand what you are trying to do here. I don't rem

Lambda returning tuple question, multi-expression

2023-03-08 Thread aapost
When making a UI there are a lot of binding/trace operations that need to occur that lead to a lot of annoying 1 use function definitions. I don't really see lambda use like below. Giving 2 working lambda examples using a returned tuple to accomplish multiple expressions - what sort of gotchas

Re: elementary tuple question. (sorry)

2007-04-06 Thread mik3l3374
On Apr 6, 5:31 am, "7stud" <[EMAIL PROTECTED]> wrote: > On Apr 5, 3:08 pm, "Steven W. Orr" <[EMAIL PROTECTED]> wrote: > > > I have a tuple that I got from struct.unpack. Now I want to pass the data > > from the returned tuple to struct.pack > > > >>> fmt > > > 'l 10l 11i h 4h c 47c 0l'>>>struct.pac

Re: elementary tuple question. (sorry)

2007-04-05 Thread 7stud
On Apr 5, 3:08 pm, "Steven W. Orr" <[EMAIL PROTECTED]> wrote: > I have a tuple that I got from struct.unpack. Now I want to pass the data > from the returned tuple to struct.pack > > >>> fmt > > 'l 10l 11i h 4h c 47c 0l'>>>struct.pack(fmt, tup) > > Traceback (most recent call last): >File "", l

Re: elementary tuple question. (sorry)

2007-04-05 Thread Gabriel Genellina
En Thu, 05 Apr 2007 18:08:14 -0300, Steven W. Orr <[EMAIL PROTECTED]> escribió: > I have a tuple that I got from struct.unpack. Now I want to pass the data > from the returned tuple to struct.pack > fmt > 'l 10l 11i h 4h c 47c 0l' struct.pack(fmt, tup) > Traceback (most recent call las

Re: elementary tuple question. (sorry)

2007-04-05 Thread attn . steven . kuo
On Apr 5, 2:08 pm, "Steven W. Orr" <[EMAIL PROTECTED]> wrote: > I have a tuple that I got from struct.unpack. Now I want to pass the data > from the returned tuple to struct.pack > > >>> fmt > > 'l 10l 11i h 4h c 47c 0l'>>>struct.pack(fmt, tup) > > Traceback (most recent call last): >File "", l

elementary tuple question. (sorry)

2007-04-05 Thread Steven W. Orr
I have a tuple that I got from struct.unpack. Now I want to pass the data from the returned tuple to struct.pack >>> fmt 'l 10l 11i h 4h c 47c 0l' >>>struct.pack(fmt, tup) Traceback (most recent call last): File "", line 1, in ? struct.error: required argument is not an integer What's the idi

Re: Tuple Question

2004-12-21 Thread Lonnie Princehouse
> Why is this? It should work.Are you using an old version of Python? -- http://mail.python.org/mailman/listinfo/python-list

Re: Tuple Question

2004-12-21 Thread Steven Bethard
VanL wrote: Why is this? >>> class MyTuple(tuple): ... def __getitem__(self, name): ... return tuple.__getitem__(self, name) ... >>> data = (1,2,3,4,5) >>> t = MyTuple(data) >>> t[0] Traceback (most recent call last): File "", line 1, in ? File "", line 3, in __getitem__ TypeErr

Re: Tuple Question

2004-12-21 Thread James Stroud
I forgot to mention: >>> mytup=("fred","barney") >>> tuple.__getitem__(mytup,0) 'fred' On Tuesday 21 December 2004 09:41 am, VanL wrote: > Hello, > > Why is this? > > >>> class MyTuple(tuple): > > ... def __getitem__(self, name): > ... return tuple.__getitem__(self, name) > ... > >

Re: Tuple Question

2004-12-21 Thread James Stroud
I don't think the tuple name is working as you expect. I don't know of any reason to redefine "__getitem__()" the way you have done: >>> class MyTuple(tuple): ... pass ... >>> data = (1,2,3,4,5) >>> t = MyTuple(data) >>> t[0] 1 >>> tuple >>> tuple.__getitem__ >>> tuple.__getitem__(0) Tracebac

Tuple Question

2004-12-21 Thread VanL
Hello, Why is this? >>> class MyTuple(tuple): ... def __getitem__(self, name): ... return tuple.__getitem__(self, name) ... >>> data = (1,2,3,4,5) >>> t = MyTuple(data) >>> t[0] Traceback (most recent call last): File "", line 1, in ? File "", line 3, in __getitem__ TypeError: descr