Re: in Python? -- Chunk -- (ChunkC '(a a b b b)), ==> ((a 2) (b 3))

2024-06-11 Thread Rob Cliffe via Python-list
import itertools def chunk1(seq):     return [ ch * len(list(grp)) for (ch, grp) in itertools.groupby(s) ] def chunk2(seq):     return [ (ch, len(list(grp))) for (ch, grp) in itertools.groupby(s) ] s='aaabbaa' print(chunk1(s)) print(chunk2(s)) ### Program

Re: IDLE: clearing the screen

2024-06-08 Thread Rob Cliffe via Python-list
OK, here is the advanced version: import os class _cls(object):     def __repr__(self):         os.system('cls')         return '' cls = _cls() Now when you type cls it clears the screen.  The only flaw is that there is a blank line at the very top of the screen, and the ">>>" prompt appears on

Re: Fwd: IDLE: clearing the screen

2024-06-05 Thread Rob Cliffe via Python-list
On 05/06/2024 04:09, Cameron Simpson wrote: On 04Jun2024 22:43, Rob Cliffe wrote: import os def cls(): x=os.system("cls") Now whenever you type cls() it will clear the screen and show the prompt at the top of the screen. (The reason for the "x=" is: os.system returns a result, in this case

Fwd: IDLE: clearing the screen

2024-06-04 Thread Rob Cliffe via Python-list
Welcome to Python!  A great language for program development. Answers might be platform-dependent (are you using WIndows, Linux, etc.). However, the following works for me on WIndows.  You can put it in the startup.py file so you don't have to type it every time you start up the IDLE. import

Beep on WIndows 11

2023-11-11 Thread Rob Cliffe via Python-list
 Apologies if this is not a Python question. I  recently moved from a WIndows 10 laptop to a Windows 11 one. Although there is nothing wrong with the sound on the new machine (I can listen to podcasts and watch videos), I find that outputting "\a" to the console (aka stdout) no longer beeps (or

Writing to clipboard in Python 3.11

2023-11-07 Thread Rob Cliffe via Python-list
Recently I switched from Python 3.8.3 to Python 3.11.4.  A strange problem appeared which was not there before: I am using the win32clipboard backage (part of pywin32), and when I use SetClipboardData() to write text which consists ENTIRELY OF DIGITS to the clipboard, I either get an error (not

Re: []=[]

2023-09-26 Thread Rob Cliffe via Python-list
It's not a bug, it's an empty unpacking. Just as you can write     [A,B] = [1,2] # Sets A to 1, B to 2 Best wishes Rob Cliffe On 23/09/2023 04:41, Greg Ewing via Python-list wrote: On 23/09/23 4:51 am, Stefan Ram wrote: []=[]    (Executes with no error.) # []=[] ( 1 ) #\_/# (Executes

Re: Tkinter ttk Treeview binding responds to past events!

2023-09-12 Thread Rob Cliffe via Python-list
On 12/09/2023 19:51, Mirko via Python-list wrote: I have also found that after() is a cure for some ills, though I avoid using it more than I have to because it feels ... a bit fragile, perhaps. Yeah. Though for me it was the delay which made it seem fragile. With a 0 delay, this looks

Re: Tkinter ttk Treeview binding responds to past events!

2023-09-11 Thread Rob Cliffe via Python-list
On 11/09/2023 21:25, Mirko via Python-list wrote: Am 11.09.23 um 14:30 schrieb John O'Hagan via Python-list: I was surprised that the code below prints 'called' three times. from tkinter import * from tkinter.ttk import * root=Tk() def callback(*e):      print('called') tree =

f-string error message

2023-08-30 Thread Rob Cliffe via Python-list
I am currently using Python 3.11.4. First I want to say: f-strings are great!  I use them all the time, mostly but by no means exclusively for debug messages.  And in 3.12 they will get even better. And the improved error messages in Python (since 3.9) are great too!  Keep up the good work.

divmod with negative Decimal values

2023-08-22 Thread Rob Cliffe via Python-list
I am using Python 3.11.4. Can anyone explain why Decimal values behave differently from ints when negative values are used in divmod as follows: >>> divmod(-1, 60) (-1, 59)  # as expected >>> divmod(Decimal("-1"), 60) (Decimal('-0'),

Re: Tkinter docs?

2023-05-30 Thread Rob Cliffe via Python-list
Thanks to everyone who replied.  All replies were constructive, none were telling me to stop belly-aching. I forgot/omitted to state that it was I who wrote the original project (in a completely different language), making the task of re-writing it much less formidable.  And meaning that I am

Tkinter docs?

2023-05-23 Thread Rob Cliffe via Python-list
I have recently started converting a large project to tkinter, starting with zero knowledge of tkinter.  (You are free to think: BAD IDEA. ) I am well aware that adopting a new tool always involves a learning curve, and that one is prone to think that things are more difficult than they

Re: Addition of a .= operator

2023-05-23 Thread Rob Cliffe via Python-list
On 23/05/2023 22:03, Peter J. Holzer wrote: On 2023-05-21 20:30:45 +0100, Rob Cliffe via Python-list wrote: On 20/05/2023 18:54, Alex Jando wrote: So what I'm suggesting is something like this: hash = hashlib.sha256(b'word') hash

Re: Addition of a .= operator

2023-05-23 Thread Rob Cliffe via Python-list
This sort of code might be better as a single expression. For example: user = ( request.GET["user"] .decode("utf-8") .strip() .lower() ) user = orm.user.get(name=user) LOL.  And I thought I was the one with a (self-confessed) tendency to write too slick, dense,

Re: Addition of a .= operator

2023-05-23 Thread Rob Cliffe via Python-list
On 20/05/2023 18:54, Alex Jando wrote: I have many times had situations where I had a variable of a certain type, all I cared about it was one of it's methods. For example: import hashlib hash = hashlib.sha256(b'word') hash =

Learning tkinter

2023-05-18 Thread Rob Cliffe via Python-list
I am trying to learn tkinter. Several examples on the internet refer to a messagebox class (tkinter.messagebox). But: Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>

Re: Question regarding unexpected behavior in using __enter__ method

2023-04-25 Thread Rob Cliffe via Python-list
This puzzled me at first, but I think others have nailed it.  It is not to do with the 'with' statement, but with the way functions are defined. When a class is instantiated, as in x=X():     the instance object gets (at least in effect), as attributes, copies of functions defined *in the

Re: Packing Problem

2023-03-18 Thread Rob Cliffe via Python-list
ffe via Python-list Date: Thursday, March 2, 2023 at 2:12 PM To: python-list@python.org Subject: Re: Packing Problem *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Slightly improved version (deals with multiple characters toget

Re: =- and -= snag

2023-03-14 Thread Rob Cliffe via Python-list
On 14/03/2023 21:28, avi.e.gr...@gmail.com wrote: TThere are people now trying to in some ways ruin the usability by putting in type hints that are ignored and although potentially helpful as in a linter evaluating it, instead often make it harder to read and write code if required to use

Re: Cutting slices

2023-03-05 Thread Rob Cliffe via Python-list
On 05/03/2023 22:59, aapost wrote: On 3/5/23 17:43, Stefan Ram wrote:    The following behaviour of Python strikes me as being a bit    "irregular". A user tries to chop of sections from a string,    but does not use "split" because the separator might become    more complicated so that a

Re: Cryptic software announcements (was: ANN: DIPY 1.6.0)

2023-03-05 Thread Rob Cliffe via Python-list
On 01/03/2023 00:13, Peter J. Holzer wrote: [This isn't specifically about DIPY, I've noticed the same thing in other announcements] On 2023-02-28 13:48:56 -0500, Eleftherios Garyfallidis wrote: Hello all, We are excited to announce a new release of DIPY: DIPY 1.6.0 is out from the oven!

Re: Packing Problem

2023-03-02 Thread Rob Cliffe via Python-list
Slightly improved version (deals with multiple characters together instead of one at a time): # Pack.py def Pack(Words):     if not Words:     return ''     # The method is to build up the result by adding letters at the beginning     # and working forward, and by adding letters at the

Packing Problem

2023-03-02 Thread Rob Cliffe via Python-list
I found Hen Hanna's "packing" problem to be an intriguing one: Given a list of words:     ['APPLE', 'PIE', 'APRICOT', 'BANANA', 'CANDY'] find a string (in general non-unique) as short as possible which contains the letters of each of these words, in order, as a subsequence. It struck me as

Re: How to fix this issue

2023-03-01 Thread Rob Cliffe via Python-list
On 01/03/2023 18:46, Thomas Passin wrote: If this is what actually happened, this particular behavior occurs because Python on Windows in a console terminates with a instead of the usual . I think you mean . -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 3.10 Fizzbuzz

2023-02-27 Thread Rob Cliffe via Python-list
On 27/02/2023 21:04, Ethan Furman wrote: On 2/27/23 12:20, rbowman wrote: > "By using Black, you agree to cede control over minutiae of hand- > formatting. In return, Black gives you speed, determinism, and freedom > from pycodestyle nagging about formatting. You will save time and mental >

Re: Line continuation and comments

2023-02-23 Thread Rob Cliffe via Python-list
On 22/02/2023 15:23, Paul Bryan wrote: Adding to this, there should be no reason now in recent versions of Python to ever use line continuation. Black goes so far as to state "backslashes are bad and should never be used":

Re: semi colonic

2023-02-23 Thread Rob Cliffe via Python-list
On 23/02/2023 02:25, Hen Hanna wrote: i sometimes put extra commas... as: [ 1, 2, 3, 4, ] That is a good idea. Even more so when the items are on separate lines:     [         "spam",         "eggs",         "cheese",     ] and you may want to

Re: semi colonic

2023-02-23 Thread Rob Cliffe via Python-list
On 23/02/2023 00:58, avi.e.gr...@gmail.com wrote: So can anyone point to places in Python where a semicolon is part of a best or even good way to do anything? Yes.  Take this bit of toy code which I just dreamed up.  (Of course it is toy code; don't bother telling me how it could be written

Re: Why doesn't Python (error msg) tell me WHAT the actual (arg) values are ?

2023-02-23 Thread Rob Cliffe via Python-list
On 22/02/2023 20:05, Hen Hanna wrote: Python makes programming (debugging) so easy I agree with that! Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: LRU cache

2023-02-22 Thread Rob Cliffe via Python-list
On 18/02/2023 17:19, Albert-Jan Roskam wrote: On Feb 18, 2023 17:28, Rob Cliffe via Python-list wrote: On 18/02/2023 15:29, Thomas Passin wrote: > On 2/18/2023 5:38 AM, Albert-Jan Roskam wrote: >>     I sometimes use this trick, which I learnt from a book by

Re: semi colonic

2023-02-22 Thread Rob Cliffe via Python-list
On 23/02/2023 02:04, Thomas Passin wrote: On 2/22/2023 7:58 PM, avi.e.gr...@gmail.com wrote: So can anyone point to places in Python where a semicolon is part of a best or even good way to do anything?  I use the semicolon (once in a while) is for quick debugging.  I might add as line

Re: LRU cache

2023-02-18 Thread Rob Cliffe via Python-list
On 18/02/2023 15:29, Thomas Passin wrote: On 2/18/2023 5:38 AM, Albert-Jan Roskam wrote:     I sometimes use this trick, which I learnt from a book by Martelli.     Instead of try/except, membership testing with "in" (__contains__) might     be faster. Probably "depends". Matter of

Re: Comparing caching strategies

2023-02-16 Thread Rob Cliffe via Python-list
On 11/02/2023 00:39, Dino wrote: First off, a big shout out to Peter J. Holzer, who mentioned roaring bitmaps a few days ago and led me to quite a discovery. I was intrigued to hear about roaring bitmaps and discover they really were a thing (not a typo as I suspected at first). What next, I

Re: evaluation question

2023-02-07 Thread Rob Cliffe via Python-list
On 07/02/2023 08:15, Chris Angelico wrote: On Tue, 7 Feb 2023 at 18:49, Rob Cliffe via Python-list wrote: On 02/02/2023 09:31, mutt...@dastardlyhq.com wrote: On Wed, 1 Feb 2023 18:28:04 +0100 "Peter J. Holzer" wrote: --b2nljkb3mdefsdhx Content-Type: text/plain; charset=us-asc

Re: Evaluation of variable as f-string

2023-02-07 Thread Rob Cliffe via Python-list
[re-sending this to both the list and to Chris, as a prior send to the list only was bounced back] On 31/01/2023 22:33, Chris Angelico wrote: Thanks for clarifying. Hm. So 'x' is neither in locals() nor in globals(). Which starts me wondering (to go off on a tangent): Should there be a

Re: evaluation question

2023-02-06 Thread Rob Cliffe via Python-list
On 02/02/2023 09:31, mutt...@dastardlyhq.com wrote: On Wed, 1 Feb 2023 18:28:04 +0100 "Peter J. Holzer" wrote: --b2nljkb3mdefsdhx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2023-02-01 09:00:39 -,

Re: Evaluation of variable as f-string

2023-01-31 Thread Rob Cliffe via Python-list
On 27/01/2023 23:41, Chris Angelico wrote: On Sat, 28 Jan 2023 at 10:08, Rob Cliffe via Python-list wrote: Whoa! Whoa! Whoa! I appreciate the points you are making, Chris, but I am a bit taken aback by such forceful language. The exact same points have already been made, but not listened

Re: evaluation question

2023-01-30 Thread Rob Cliffe via Python-list
On 30/01/2023 09:41, mutt...@dastardlyhq.com wrote: On Sun, 29 Jan 2023 23:57:51 -0500 Thomas Passin wrote: On 1/29/2023 4:15 PM, elvis-85...@notatla.org.uk wrote: On 2023-01-28, Louis Krupp wrote: On 1/27/2023 9:37 AM, mutt...@dastardlyhq.com wrote: eval("print(123)") 123 Does OP

Re: Evaluation of variable as f-string

2023-01-27 Thread Rob Cliffe via Python-list
Whoa! Whoa! Whoa! I appreciate the points you are making, Chris, but I am a bit taken aback by such forceful language. On 27/01/2023 19:18, Chris Angelico wrote: On Sat, 28 Jan 2023 at 05:31, Rob Cliffe via Python-list wrote: On 23/01/2023 18:02, Chris Angelico wrote: Maybe, rather than

Re: Evaluation of variable as f-string

2023-01-27 Thread Rob Cliffe via Python-list
On 23/01/2023 18:02, Chris Angelico wrote: On Tue, 24 Jan 2023 at 04:56, Johannes Bauer wrote: Hi there, is there an easy way to evaluate a string stored in a variable as if it were an f-string at runtime? ... This is supposedly for security reasons. However, when trying to emulate this

Re: bool and int

2023-01-27 Thread Rob Cliffe via Python-list
On 24/01/2023 04:22, Dino wrote: $ python Python 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> b = True >>> isinstance(b,bool) True >>> isinstance(b,int) True >>> That immediately tells you that either

Re: Evaluation of variable as f-string

2023-01-27 Thread Rob Cliffe via Python-list
On 25/01/2023 19:38, Thomas Passin wrote: Stack overflow to the rescue: Search phrase:  "python evaluate string as fstring" https://stackoverflow.com/questions/47339121/how-do-i-convert-a-string-into-an-f-string def effify(non_f_str: str):     return eval(f'f"""{non_f_str}"""')

Re: ok, I feel stupid, but there must be a better way than this! (finding name of unique key in dict)

2023-01-20 Thread Rob Cliffe via Python-list
On 20/01/2023 15:29, Dino wrote: let's say I have this list of nested dicts: [   { "some_key": {'a':1, 'b':2}},   { "some_other_key": {'a':3, 'b':4}} ] I need to turn this into: [   { "value": "some_key", 'a':1, 'b':2},   { "value": "some_other_key", 'a':3, 'b':4} ] Assuming that I believe

Re: Top level of a recursive function

2022-12-17 Thread Rob Cliffe via Python-list
On 14/12/2022 13:49, Stefan Ram wrote: I also found an example similar to what was discussed here in pypy's library file "...\Lib\_tkinter\__init__.py": |def _flatten(item): |def _flatten1(output, item, depth): |if depth > 1000: |raise ValueError("nesting too deep

Re: Single line if statement with a continue

2022-12-17 Thread Rob Cliffe via Python-list
On 15/12/2022 04:35, Chris Angelico wrote: On Thu, 15 Dec 2022 at 14:41, Aaron P wrote: I occasionally run across something like: for idx, thing in enumerate(things): if idx == 103: continue do_something_with(thing) It seems more succinct and cleaner to use: if idx ==

Re: for -- else: what was the motivation?

2022-10-14 Thread Rob Cliffe via Python-list
I too have occasionally used for ... else.  It does have its uses. But oh, how I wish it had been called something else more meaningful, whether 'nobreak' or whatever.  It used to really confuse me.  Now I've learned to mentally replace "else" by "if nobreak", it confuses me a bit less. Rob

Re: Byte arrays and DLLs

2022-07-03 Thread Rob Cliffe via Python-list
That worked.  Many thanks Eryk. Rob On 30/06/2022 23:45, Eryk Sun wrote: On 6/30/22, Rob Cliffe via Python-list wrote: AKAIK it is not possible to give ctypes a bytearray object and persuade it to give you a pointer to the actual array data, suitable for passing to a DLL. You're overlooking

Byte arrays and DLLs

2022-06-30 Thread Rob Cliffe via Python-list
I have an application in which I wanted a fixed-length "array of bytes" (that's intended as an informal term) where I could read and write individual bytes and slices, and also pass the array to a DLL (one I wrote in C) which expects an "unsigned char *" parameter. I am using ctypes to talk to

Re: REPL with multiple function definitions

2022-06-28 Thread Rob Cliffe via Python-list
On 26/06/2022 23:22, Jon Ribbens via Python-list wrote: On 2022-06-26, Rob Cliffe wrote: This 2-line program def f(): pass def g(): pass runs silently (no Exception).  But: 23:07:02 c:\>python Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32

REPL with multiple function definitions

2022-06-26 Thread Rob Cliffe via Python-list
This 2-line program def f(): pass def g(): pass runs silently (no Exception).  But: 23:07:02 c:\>python Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> def f(): pass ...

Re: Non-deterministic set ordering

2022-05-15 Thread Rob Cliffe via Python-list
Thanks, Paul.  Question answered! Rob Cliffe On 16/05/2022 04:36, Paul Bryan wrote: This may explain it: https://stackoverflow.com/questions/27522626/hash-function-in-python-3-3-returns-different-results-between-sessions On Mon, 2022-05-16 at 04:20 +0100, Rob Cliffe via Python-list wrote

Re: Non-deterministic set ordering

2022-05-15 Thread Rob Cliffe via Python-list
On 16/05/2022 04:13, Dan Stromberg wrote: On Sun, May 15, 2022 at 8:01 PM Rob Cliffe via Python-list wrote: I was shocked to discover that when repeatedly running the following program (condensed from a "real" program) under Python 3.8.3 for p in { ('x','y'

Non-deterministic set ordering

2022-05-15 Thread Rob Cliffe via Python-list
I was shocked to discover that when repeatedly running the following program (condensed from a "real" program) under Python 3.8.3 for p in { ('x','y'), ('y','x') }:     print(p) the output was sometimes ('y', 'x') ('x', 'y') and sometimes ('x', 'y') ('y', 'x') Can anyone explain why

Re: Printing Unicode strings in a list

2022-04-28 Thread Rob Cliffe via Python-list
On 28/04/2022 14:27, Stephen Tucker wrote: To Cameron Simpson, Thanks for your in-depth and helpful reply. I have noted it and will be giving it close attention when I can. The main reason why I am still using Python 2.x is that my colleagues are still using a GIS system that has a Python

Re: Style for docstring

2022-04-25 Thread Rob Cliffe via Python-list
Well, de gustibus non est disputandum.  For me, the switch from the imperative mode to the descriptive mode produces a mild cognitive dissonance. Best wishes Rob Cliffe On 25/04/2022 23:34, Cameron Simpson wrote: On 23Apr2022 03:26, Avi Gross wrote: We know some people using "professional"

Re: Style for docstring

2022-04-22 Thread Rob Cliffe via Python-list
I don't use docstrings much; instead I put a line or two of comments after the `def ` line. But my practice in such situations is as per the OP's 3rd suggestion, e.g.     # Returns True if . I'm curious as to why so many people prefer "Return" to "Returns". Checking out help() on a few

Re: Behavior of the for-else construct

2022-03-05 Thread Rob Cliffe via Python-list
On 05/03/2022 01:15, Cameron Simpson wrote: I sort of wish it had both "used break" and "did not use break" branches, a bit like try/except/else. And "zero iterations". Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Behavior of the for-else construct

2022-03-04 Thread Rob Cliffe via Python-list
On 04/03/2022 20:52, Avi Gross via Python-list wrote: I have an observation about exception handling in general. Some people use exceptions, including ones they create and throw, for a similar idea. You might for example try to use an exception if your first attempt fails that specifies

Re: Behavior of the for-else construct

2022-03-03 Thread Rob Cliffe via Python-list
On 04/03/2022 00:55, Chris Angelico wrote: for victim in debtors: if victim.pay(up): continue if victim.late(): break or else: victim.sleep_with(fishes) If you mean "or else" to be synonymous with "else", then only the last debtor is killed, whether he has paid up or not,

Re: Behavior of the for-else construct

2022-03-03 Thread Rob Cliffe via Python-list
On 04/03/2022 01:44, Ethan Furman wrote: On 3/3/22 5:32 PM, Rob Cliffe via Python-list wrote: > There are three types of programmer: those that can count, and those that can't. Actually, there are 10 types of programmer:  those that can count in binary, and those that can't. 1, 10, m

Re: Behavior of the for-else construct

2022-03-03 Thread Rob Cliffe via Python-list
On 04/03/2022 00:43, Chris Angelico wrote: On Fri, 4 Mar 2022 at 11:14, Rob Cliffe via Python-list wrote: I find it so hard to remember what `for ... else` means that on the very few occasions I have used it, I ALWAYS put a comment alongside/below the `else` to remind myself (and anyone

Re: Behavior of the for-else construct

2022-03-03 Thread Rob Cliffe via Python-list
Having a way to enter them using keyboards is a challenge. Back to the topic, I was thinking wickedly of a way to extend the FOR loop with existing keywords while sounding a tad ominous is not with an ELSE but a FOR ... OR ELSE ... -----Original Message- From: Rob Cliffe via Python-list To:

Re: Behavior of the for-else construct

2022-03-03 Thread Rob Cliffe via Python-list
On 04/03/2022 00:34, Chris Angelico wrote: On Fri, 4 Mar 2022 at 10:09, Avi Gross via Python-list wrote: The drumbeat I keep hearing is that some people hear/see the same word as implying something else. ELSE is ambiguous in the context it is used. What I'm hearing is that there are,

Re: Behavior of the for-else construct

2022-03-03 Thread Rob Cliffe via Python-list
I find it so hard to remember what `for ... else` means that on the very few occasions I have used it, I ALWAYS put a comment alongside/below the `else` to remind myself (and anyone else unfortunate enough to read my code) what triggers it, e.g.     for item in search_list:         ...        

Re: Behavior of the for-else construct

2022-03-03 Thread Rob Cliffe via Python-list
It has occasional uses (I THINK I've used it myself) but spelling it `else` is very confusing.  So there have been proposals for an alternative spelling, e.g. `nobreak`. There have also been suggestions for adding other suites after `for', e.g.     if the loop WAS exited with `break`     if the

Re: All permutations from 2 lists

2022-03-03 Thread Rob Cliffe via Python-list
On 03/03/2022 14:07, Larry Martell wrote: On Wed, Mar 2, 2022 at 9:42 PM Avi Gross via Python-list wrote: Larry, i waited patiently to see what others will write and perhaps see if you explain better what you need. You seem to gleefully swat down anything offered. So I am not tempted to

Re: All permutations from 2 lists

2022-03-01 Thread Rob Cliffe via Python-list
I would not use `os` as an identifier, as it is the name of an important built-in module. I think itertools.product is what you need. Example program: import itertools opsys = ["Linux","Windows"] region = ["us-east-1", "us-east-2"] print(list(itertools.product(opsys, region))) Output:

Re: Global VS Local Subroutines

2022-02-10 Thread Rob Cliffe via Python-list
On 10/02/2022 21:43, Friedrich Rentsch wrote: I believe to have observed a difference which also might be worth noting: the imbedded function a() (second example) has access to all of the imbedding function's variables, which might be an efficiency factor with lots of variables. The access

Re: Global VS Local Subroutines

2022-02-10 Thread Rob Cliffe via Python-list
On 10/02/2022 12:13, BlindAnagram wrote: Is there any difference in performance between these two program layouts:    def a(): ...    def(b): c = a(b) or    def(b): def a():    ... c = a(b) I would appreciate any insights on which layout to choose in which

Re: A decade or so of Python programming, and I've never thought to "for-elif"

2021-12-01 Thread Rob Cliffe via Python-list
If for ... else was spelt more intelligibly, e.g. for ... nobreak, there would be no temptation to use anything like `elif'. `nobreakif' wouldn't be a keyword. Rob Cliffe On 30/11/2021 06:24, Chris Angelico wrote: for ns in namespaces: if name in ns: print("Found!")

Re: Negative subscripts

2021-11-26 Thread Rob Cliffe via Python-list
You could evaluate y separately: yval = for item in x[:-yval] if yval else x:     [do stuff] or you could do it using the walrus operator: for item in x[:-yval] if (yval := ) else x:     [do stuff] or, perhaps simplest, you could do for item in x[:-y or None]: # a value of None for a slice

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Rob Cliffe via Python-list
On 21/11/2021 01:02, Chris Angelico wrote: If you have a number with a finite binary representation, you can guarantee that it can be represented finitely in decimal too. Infinitely repeating expansions come from denominators that are coprime with the numeric base. Not quite, e.g. 1/14 is

Re: Unexpected behaviour of math.floor, round and int functions (rounding)

2021-11-20 Thread Rob Cliffe via Python-list
On 20/11/2021 22:59, Avi Gross via Python-list wrote: there are grey lines along the way where some mathematical proofs do weird things like IGNORE parts of a calculation by suggesting they are going to zero much faster than other parts and then wave a mathematical wand about what happens when

Re: [tkinter][Windows]Unexpected state report for the tab key

2021-10-25 Thread Rob Cliffe via Python-list
On 25/10/2021 02:57, Stefan Ram wrote: GetKeyState still returns that the tab key is pressed after the tab key already has been released. Well, how then am I going to make my slide show stop the moment the key is being released? Does tkinter allow you to trap KeyUp (and KeyDown)

Re: importing a module from a file without the '.py' suffix

2021-10-22 Thread Rob Cliffe via Python-list
As far as I know, it can't be done. If I was REALLY desperate I might try (tested) import os os.rename('myfile.myext', 'myfile.py') import myfile os.rename('myfile.py', 'myfile.myext') # with appropriate modifications if myfile is not in the current directory but this is a horrible solution,

Re: OT: AttributeError

2021-09-29 Thread Rob Cliffe via Python-list
Ah, Z80s (deep sigh).  Those were the days!  You could disassemble the entire CP/M operating system (including the BIOS), and still have many Kb to play with!  Real programmers don't need gigabytes! On 29/09/2021 03:03, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-09-29 at 09:21:34

Re: Problem with python

2021-09-04 Thread Rob Cliffe via Python-list
Well, up to a point. In Python 2 the output from     print 1, 2 is '1 2' In Python 3 if you add brackets:     print(1, 2) the output is the same. But if you transplant that syntax back into Python 2, the output from     print(1, 2) is '(1, 2)'.  The brackets have turned two separate items into a

Re: some problems for an introductory python test

2021-08-11 Thread Rob Cliffe via Python-list
On 11/08/2021 19:10, MRAB wrote: On 2021-08-11 18:10, Wolfram Hinderer via Python-list wrote: Am 11.08.2021 um 05:22 schrieb Terry Reedy: Python is a little looser about whitespace than one might expect from reading 'normal' code when the result is unambiguous in that it cannot really mean

Re: Anaconda navigator not working

2021-06-20 Thread Rob Cliffe via Python-list
I'm afraid I can't help at all, but I have many times (well, it feels like many) encountered the     "%1 is not a valid Win32 application" error message.  It looks like a format string that has not been given an argument to format. I would guess it's a bug either in Windows or somewhere in

Re: Strange disassembly

2021-06-19 Thread Rob Cliffe via Python-list
On 19/06/2021 07:50, Chris Angelico wrote: On Sat, Jun 19, 2021 at 4:16 PM Rob Cliffe via Python-list wrote: On 18/06/2021 11:04, Chris Angelico wrote: sys.version '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' def chk(x): ... if not(0 < x < 10):

Re: Strange disassembly

2021-06-19 Thread Rob Cliffe via Python-list
On 18/06/2021 11:04, Chris Angelico wrote: sys.version '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' def chk(x): ... if not(0 < x < 10): raise Exception ... dis.dis(chk) 2 0 LOAD_CONST 1 (0) 2 LOAD_FAST

Re: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it?

2021-06-14 Thread Rob Cliffe via Python-list
This puzzled me, so I played around with it a bit (Python 3.8.3): n = [] for i in range(3):     n.append((1,7,-3,None,"x")) for i in range(3):     n.append((1,7,-3,None,"x")) print([id(x) for x in n]) a = 4 n = [] for i in range(3):     n.append((1,7,-3,a,None,"x")) for i in range(3):    

Re: learning python ...

2021-05-24 Thread Rob Cliffe via Python-list
Please don't be put off by your experience so far.  Everyone stumbles along the way and runs into "gotchas" when learning a new language.  Python is a fantastic language for development.  One of my early "epiphany" moments was experimenting with different algorithms to try to find the right

Re: learning python ...

2021-05-24 Thread Rob Cliffe via Python-list
On 24/05/2021 14:34, hw wrote: Your claim that I'm insulting python or anoyone is ridiculous. According to your logic, C is insulting python.  I suggest you stop making assumptions. Calling a mature, widely used language "unfinished" because of what *you* see as a defect *is* insulting.

Re: Style qeustion: Multiple return values

2021-04-12 Thread Rob Cliffe via Python-list
On 12/04/2021 09:29, Steve Keller wrote: Just a short style question: When returning multiple return values, do you use parenthesis? E.g. would you write def foo(): return 1, 2 a, b = foo() or do you prefer def foo(): return (1, 2) (a, b) = foo()

Re: Friday Finking: initialising values and implied tuples

2021-04-05 Thread Rob Cliffe via Python-list
On 05/04/2021 18:33, Chris Angelico wrote: Firstly, anything with any variable at all can involve a lookup, which can trigger arbitrary code (so "variables which do not occur on the LHS" is not sufficient). Interesting.  I was going to ask: How could you make a variable lookup trigger

Re: Friday Finking: initialising values and implied tuples

2021-04-05 Thread Rob Cliffe via Python-list
On 05/04/2021 17:52, Chris Angelico wrote: I don't understand.  What semantic difference could there be between     x = { 1: 2 }    ;    y = [3, 4]   ;   z = (5, 6) and     x, y, z = { 1:2 }, [3, 4], (5, 6) ?  Why is it not safe to convert the latter to the former? But I withdraw "set" from my

Re: Friday Finking: initialising values and implied tuples

2021-04-05 Thread Rob Cliffe via Python-list
On 05/04/2021 17:52, Chris Angelico wrote: On Tue, Apr 6, 2021 at 2:32 AM Rob Cliffe via Python-list wrote: It doesn't appear to, at least not always. In Python 3.8.3: from dis import dis def f(): x = 1 ; y = 2 def g(): (x,y) = (1,2) dis(f) dis(g) Output: 2 0 LOAD_CONST

Re: Friday Finking: initialising values and implied tuples

2021-04-05 Thread Rob Cliffe via Python-list
On 05/04/2021 00:47, dn via Python-list wrote: On 04/04/2021 01.00, Rob Cliffe via Python-list wrote: On 03/04/2021 04:09, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-04-03 at 02:41:59 +0100, Rob Cliffe via Python-list wrote: x1 = 42; y1 =  3;  z1 = 10 x2 = 41; y2 = 12

Re: Friday Finking: initialising values and implied tuples

2021-04-03 Thread Rob Cliffe via Python-list
On 03/04/2021 04:09, 2qdxy4rzwzuui...@potatochowder.com wrote: On 2021-04-03 at 02:41:59 +0100, Rob Cliffe via Python-list wrote:     x1 = 42; y1 =  3;  z1 = 10     x2 = 41; y2 = 12; z2 = 9     x3 =  8;  y3 =  8;  z3 = 10 (please imagine it's in a fixed font with everything neatly

Re: Friday Finking: initialising values and implied tuples

2021-04-02 Thread Rob Cliffe via Python-list
On 02/04/2021 23:10, dn via Python-list wrote: (f) the space-saver: resource = "Oil"; time = 1; crude = 2; residue = 3; my_list = "long" IMO This can be OK when the number of items is VERY small (like 2) and not expected to increase (or decrease).  Especially if there are multiple

Re: memory consumption

2021-03-31 Thread Rob Cliffe via Python-list
On 31/03/2021 09:35, Alexey wrote: среда, 31 марта 2021 г. в 01:20:06 UTC+3, Dan Stromberg: What if you increase the machine's (operating system's) swap space? Does that take care of the problem in practice? I can`t do that because it will affect other containers running on this host. In my

REPL peculiarity

2021-03-11 Thread Rob Cliffe via Python-list
This is a valid Python program: def f(): pass print(f) But at the REPL: >>> def f(): pass ... print(f)   File "", line 2     print(f)     ^ SyntaxError: invalid syntax It doesn't seem to matter what the second line is.  In the REPL you have to leave a blank line after the "def" line.  Why?

a + not b

2021-03-03 Thread Rob Cliffe via Python-list
I can't work out why     1 + - 1     1 + (not 1) are legal syntax, but     1 + not 1 isn't. Is there a good reason for this? Thanks Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: why sqrt is not a built-in function?

2021-01-15 Thread Rob Cliffe via Python-list
On 14/01/2021 17:44, Denys Contant wrote: I don't understand why sqrt is not a built-in function. Why do we have to first import the function from the math module? I use it ALL THE TIME! I agree that, especially if you have experience in other languages, this feels odd, and I have some

Re: Error in lambda function..!

2020-08-29 Thread Rob Cliffe via Python-list
On 29/08/2020 08:58, Shivlal Sharma wrote: from functools import* nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] add = reduce(lambda a : a + 1, nums) print(add) error: - TypeError Traceback (most recent call last) in () 1 from functools import* 2 nums = [1,

Re: About float/double type number in range.

2020-08-26 Thread Rob Cliffe via Python-list
On 26/08/2020 12:02, Peter J. Holzer wrote: On 2020-08-26 22:40:36 +1200, dn via Python-list wrote: On 26/08/2020 19:58, Joel Goldstick wrote: [...] <<< Code NB Python v3.8 >>> def fp_range( start:float, stop:float, step:float=1.0 )->float: """Generate a range of floating-point

Re: Program chaining on Windows

2020-08-24 Thread Rob Cliffe via Python-list
On 24/08/2020 19:54, Terry Reedy wrote: On 8/23/2020 3:31 AM, Rob Cliffe via Python-list wrote: On WIndows 10, running Python programs in a DOS box, Please don't use 'DOS box' for Windows Command Prompt or other Windows consoles for running Windows programs from a command line.  DOSBox

Re: Program chaining on Windows

2020-08-24 Thread Rob Cliffe via Python-list
On 24/08/2020 13:20, Eryk Sun wrote: You can work with job objects via ctypes or PyWin32's win32job module. I can provide example code for either approach. No need, I'm already convinced that this is not the way for me to go. from the DOS prompt, it works as expected. You're not running

  1   2   >