Re: Searching for a file

2025-05-24 Thread Rob Cliffe via Python-list
On 25/05/2025 00:18, Mats Wichmann wrote: On 5/23/25 16:05, Rob Cliffe via Python-list wrote: On 23/05/2025 18:55, Mats Wichmann wrote: On 5/22/25 21:04, Rob Cliffe via Python-list wrote: It occurs to me that it might be useful if Python provided a function to search for a file with a

Re: Searching for a file

2025-05-23 Thread Rob Cliffe via Python-list
On 23/05/2025 18:55, Mats Wichmann wrote: On 5/22/25 21:04, Rob Cliffe via Python-list wrote: It occurs to me that it might be useful if Python provided a function to search for a file with a given name in various directories (much as the import.import_lib function searches for a module in

Searching for a file

2025-05-22 Thread Rob Cliffe via Python-list
ing like     C:\Python311\Lib\os.py This idea was partly inspired by Michael Stemper asking about best practice for placing, and finding, a configuration file. Thoughts? Best wishes Rob Cliffe -- https://mail.python.org/mailman3//lists/python-list.python.org

Re: Best practice for config files?

2025-05-22 Thread Rob Cliffe via Python-list
isn't).  Alternatively look at the PATH envronment variable, which contains a list of directories separated by semicolons and which you can access as os.environ['PATH'] . Best wishes, Rob Cliffe -- https://mail.python.org/mailman3//lists/python-list.python.org

Re: Dynamic classes

2025-05-19 Thread Rob Cliffe via Python-list
#x27;Flag2': 2, 'Flag3: 4, ' '__init__' : __init__}) This is not my area of expertise, but there is a misplaced quote before     '__init__' that should be after     'Flags3 Correct this, and your example runs without error. Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

sys.call_tracing

2025-01-30 Thread Rob Cliffe via Python-list
call_tracing()| enables explicit recursion of the tracing function. Is there any reason it doesn't support sys.call_tracing(/func/, /args/, kargs) to call func(*args, **kargs) ? Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-12 Thread Rob Cliffe via Python-list
On 12/11/2024 08:52, Loris Bennett via Python-list wrote: Cameron Simpson writes: Generally you should put a try/except around the smallest possible piece of code. That is excellent advice. Best wishes Rob Cliffe So: config = configparser.ConfigParser() try

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-08 Thread Rob Cliffe via Python-list
hat the follwing is less ugly: try: do something except: log something return try: .commit() except: log some more return Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-07 Thread Rob Cliffe via Python-list
interested in, which you seem to be already doing.) Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Best use of "open" context manager

2024-07-08 Thread Rob Cliffe via Python-list
On 06/07/2024 12:57, Oscar Benjamin via Python-list wrote: On Sat, 6 Jul 2024 at 11:55, Rob Cliffe via Python-list wrote: Consider this scenario (which I ran into in real life): I want to open a text file and do a lot of processing on the lines of that file. If the file does not

Re: Best use of "open" context manager

2024-07-07 Thread Rob Cliffe via Python-list
On 07/07/2024 02:08, Cameron Simpson wrote: On 06Jul2024 11:49, Rob Cliffe wrote: try:     f = open(FileName) as f:     FileLines = f.readlines() except FileNotFoundError:     print(f"File {FileName} not found")     sys.exit() # I forgot to put "f.close()" here -:)

Best use of "open" context manager

2024-07-06 Thread Rob Cliffe via Python-list
modify the last attempt to open the file twice, which would work, but seems like a kludge (subject to race condition, inefficient). Is there a better / more Pythonic solution? Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

win32clipboard writing to clipboard on Windows 11

2024-06-17 Thread Rob Cliffe via Python-list
o far Traceback (most recent call last):   File "C:\TEST*.PY", line 8, in     SetClipboardData(CF_UNICODETEXT, "0") pywintypes.error: (0, 'SetClipboardData', 'No error message is available') Can anyone shed light on this? Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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

2024-06-11 Thread Rob Cliffe via Python-list
## Program output: ['aaa', 'bb', '', 'aa'] [('a', 3), ('b', 2), ('c', 4), ('a', 2)] Rob Cliffe On 09/06/2024 22:20, HenHanna via Python-list wrote: Chunk, ChunkC -- nice simple way(s) to write these in Python? (Ch

Re: IDLE: clearing the screen

2024-06-08 Thread Rob Cliffe via Python-list
ot;>>>" prompt appears on the SECOND line. (This blank line is because the IDLE prints the blank value returned by "return ''" and adds a newline to it, as it does when printing the value of any expression.) Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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

Fwd: IDLE: clearing the screen

2024-06-04 Thread Rob Cliffe via Python-list
esult.  So without the "x=" you get an extra line at the top of the screen containing "0".) I am sure that some jiggery-pokery could be used so you don't have to type the "()".  But that's more advanced ... Best wishes Rob Cliffe On 04/06/2024 14:3

Beep on WIndows 11

2023-11-11 Thread Rob Cliffe via Python-list
beep. Can anyone shed light on this, and perhaps give a simpler fix? Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Writing to clipboard in Python 3.11

2023-11-07 Thread Rob Cliffe via Python-list
_UNICODETEXT, "0") pywintypes.error: (0, 'SetClipboardData', 'No error message is available') I can get round the problem by using SetClipboardText().  But can anyone shed light on this? Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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 ) #\_/#

Re: Tkinter ttk Treeview binding responds to past events!

2023-09-12 Thread Rob Cliffe via Python-list
don't know), and error-prone if I want to add some more Things. Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Tkinter ttk Treeview binding responds to past events!

2023-09-11 Thread Rob Cliffe via Python-list
mouse is clicked on a widget and tk responds by giving that widget the focus, but I don't want that to happen. I can't AFAIK prevent the focus change, but I can immediately cancel it with     X.after(0, SomeOtherWidget.focus_set) where X is any convenient object with the "after" method (just about any widget, or the root). Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

f-string error message

2023-08-30 Thread Rob Cliffe via Python-list
e value supplied to it. Would it be possible to have a different error message, something like ValueError: int expected in format string but decimal.Decimal found Or am I missing something? Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

divmod with negative Decimal values

2023-08-21 Thread Rob Cliffe via Python-list
60) (Decimal('-0'), Decimal('-1')) Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Tkinter docs?

2023-05-30 Thread Rob Cliffe via Python-list
my platform (Windows10) the shadowing of tk.Button objects is more conspicuous (without using styles or whatever). Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Tkinter docs?

2023-05-23 Thread Rob Cliffe via Python-list
ace somewhere. Now, my remarks are as a tk newbie; they may be naive and ignorant, perhaps even laughable.  But IMO it is often worth listening to input from newbies to consider how things might be improved. Comments, anyone? Better yet (holds breath ...) can anyone point me towards some decent tkinter documentation? Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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'w

Re: Addition of a .= operator

2023-05-23 Thread Rob Cliffe via Python-list
might return Unicode, depending on which server it was talking to.) Peter's actual code feels more Pythonic to me.  (It's even 2 lines shorter! 😎) Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Addition of a .= operator

2023-05-23 Thread Rob Cliffe via Python-list
course, in your use case it may be perfectly appropriate to write "num = num.value" as you did. But IMO it's not something that should be encouraged in general. Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Learning tkinter

2023-05-18 Thread Rob Cliffe via Python-list
"license" for more information. >>> import tkinter >>> tkinter.messagebox Traceback (most recent call last):   File "", line 1, in AttributeError: module 'tkinter' has no attribute 'messagebox' >>> Why is this? TIA Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Question regarding unexpected behavior in using __enter__ method

2023-04-25 Thread Rob Cliffe via Python-list
X.func:     X.func() # Called with no arguments Best wishes Rob Cliffe On 20/04/2023 23:44, Lorenzo Catoni wrote: Dear Python Mailing List members, I am writing to seek your assistance in understanding an unexpected behavior that I encountered while using the __enter__ method. I have provided

Re: Packing Problem

2023-03-18 Thread Rob Cliffe via Python-list
!= ''] nextWords = [] for w in CopyOfWords: if w[0] != ch: nextWords.append(w) elif len(w) > 1: nextWords.append(w[1:]) assert Words == nextWords Why? Rob Cliffe From: Python-list on behalf o

Re: =- and -= snag

2023-03-14 Thread Rob Cliffe via Python-list
it. +1 Whenever I see code with type hints, I have to edit them out, either mentally, or physically, to understand what the code is actually doing.  It's adding new syntax which I'm not used to and don't want to be forced to learn. Rob Cliffe -- https://mail.python.org/mailman/

Re: Cutting slices

2023-03-05 Thread Rob Cliffe via Python-list
are asking for     s[ 11 : -1] which correctly returns 'gamm'. You need to test for this condition. Alternatively you could ensure that there is a final separator:     s = 'alpha.beta.gamma.' but you would still need to test when the string was exhausted. Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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

2023-03-05 Thread Rob Cliffe via Python-list
uld be a good idea if software announcements would include a single paragraph (or maybe just a single sentence) summarizing what the software is and does. hp +1 Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Packing Problem

2023-03-02 Thread Rob Cliffe via Python-list
ne or len(res) < len(BestResult):     BestResult = res     return Initial + BestResult + Final print(Pack(['APPLE', 'PIE', 'APRICOT', 'BANANA', 'CANDY'])) Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Packing Problem

2023-03-02 Thread Rob Cliffe via Python-list
is None or len(res) < len(BestResult):     BestResult = res     return Initial + BestResult + Final print(Pack(['APPLE', 'PIE', 'APRICOT', 'BANANA', 'CANDY'])) The output: BAPPRICNANADYOTLE which has the same length as the answer I ca

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
t line with the others (in a fixed font of course). Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: semi colonic

2023-02-23 Thread Rob Cliffe via Python-list
notwithstanding that IMO it is occasionally appropriate). Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: semi colonic

2023-02-23 Thread Rob Cliffe via Python-list
alcPay(rate=1.5) if dow==6:     day="Sun"     calcPay(rate=2) Not so easy to spot the mistake now, is it? Not to mention the saving of vertical space. Best wishes Rob Cliffe PS If you really care, I can send you a more complicated example of real code from one of my programs which is HUGELY more readable when laid out in this way. -- https://mail.python.org/mailman/listinfo/python-list

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
like, perhaps, import os; print(os.path.exists(filename)) This way I can get rid of the debugging statement by deleting that single line.  This is non only quicker but I'm less likely to delete too much by mistake. I do exactly the same. Rob Cliffe -- https://mail.python.org/mailman/lis

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 measuring

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
f all available variables and their values?  If it were possible, it could be useful, and there would be no impact on Python run-time speed if it were only constructed on demand. Best wishes Rob -- https://mail.python.org/mailman/listinfo/python-list

Re: evaluation question

2023-02-06 Thread Rob Cliffe via Python-list
;t have it both ways. In any case, supporting two different syntaxes simultaneously would be messy and difficult to maintain. Better a clean break, with Python 2 support continuing for a long time (as it was). Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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 to

Re: evaluation question

2023-01-30 Thread Rob Cliffe via Python-list
statement. sys.stdout.write() does return the number of characters output (you could use this instead of print() if you need this; remember to add a '\n' character at the end of  a line).  I guess the option of making print() do the same either was not considered, or was rejected, whe

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
rden - to support a relatively rare requirement". Perhaps someone will be inspired to write a function to do it. 😎 Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: bool and int

2023-01-27 Thread Rob Cliffe via Python-list
isinstance(b,int) True >>> That immediately tells you that either     bool is a subclass of int     int is a subclass of bool     bool and int are both subclasses of some other class In fact the first one is true. This is not a logical necessity, but the way Python happens to be designe

Re: Evaluation of variable as f-string

2023-01-27 Thread Rob Cliffe via Python-list
d/or locals dictionaries as needed for eval to use.  Something like this: def effify(non_f_str, glob=None, loc=None):     return eval(f'f"""{non_f_str}"""',     glob if glob is not None else globals(),     loc if loc is not None else locals()) Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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
in origListOfDescriptors] I believe that from Python 3.9 onwards this can be written more concisely as: listOfDescriptors = [     { (L := list(D.items())[0])[1] } | {'value' : L[0] }     for D in origListOfDescriptors]     # untested Best wishes Rob Cliffe I actually did i

Re: Top level of a recursive function

2022-12-17 Thread Rob Cliffe via Python-list
ng it garbage-collected later). Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Single line if statement with a continue

2022-12-17 Thread Rob Cliffe via Python-list
often done in my own code, albeit with a feeling of guilt that I was breaking a Python taboo.  Now I will do it with a clear conscience. 😁 Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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"

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 overlo

Byte arrays and DLLs

2022-06-30 Thread Rob Cliffe via Python-list
a sensible approach, or am I still missing something? 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.  Is this (a) false (b) for historical reasons (c) for some other good reason? TIA Rob

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 wi

REPL with multiple function definitions

2022-06-26 Thread Rob Cliffe via Python-list
ot; for more information. >>> def f(): pass ... def g(): pass   File "", line 2     def g(): pass     ^ SyntaxError: invalid syntax >>> Is there a good reason for this? Thanks Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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

Non-deterministic set ordering

2022-05-15 Thread Rob Cliffe via Python-list
#x27;x', 'y') and sometimes ('x', 'y') ('y', 'x') Can anyone explain why running identical code should result in traversing a set in a different order? Thanks Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Printing Unicode strings in a list

2022-04-28 Thread Rob Cliffe via Python-list
doing that. Still, if you're feeling noble, you could start the work of making your code Python 3 compatible.😁 Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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 "profess

Re: Style for docstring

2022-04-22 Thread Rob Cliffe via Python-list
ive.  But who is it addresed to?  Is a function considered to be a sentient entity that can respond to a command?  Is it an invocation to the lines of code following the docstring: "Do this!" Might not the programmer mistakenly think (if only for a moment) that the imperative is a

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
h leads me right back to wondering why the sentinel approach is so bad! It's not that bad, but it's more convenient and readable if it can be avoided. Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Behavior of the for-else construct

2022-03-03 Thread Rob Cliffe via Python-list
#x27;if a break occurred', then at least only one debtor is killed, as an example to the others, and no Exception will occur in the unlikely event of "debtors" being empty. Happy fund-raising! Rob Cliffe There's something in this. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

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.

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
On 04/03/2022 00:38, Avi Gross via Python-list wrote: Rob, I regularly code with lots of comments like the one you describe, or mark the end of a region that started on an earlier screen such as a deeply nested construct. So do I (and not just in Python).  It's good practice. I hav

Re: Behavior of the for-else construct

2022-03-03 Thread Rob Cliffe via Python-list
trokes to bind them to and besides it can be fairly easy to select items and yank them and move to where you want them and replace them. SciTE has a "transpose lines" feature. I use it frequently. But editor features are quite different from language features. ChrisA [1] Something tells me I've heard this before Of course you have.  There are three types of programmer: those that can count, and those that can't. Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Behavior of the for-else construct

2022-03-03 Thread Rob Cliffe via Python-list
:         ...         ... break     else: # if no item in search_list matched the criteria You get the idea. If I really want to remember what this construct means, I remind myself that `else` here really means `no break`.  Would have been better if it had been spelt `nobreak` or similar in the first place. Rob

Re: Behavior of the for-else construct

2022-03-03 Thread Rob Cliffe via Python-list
    if the loop was executed zero times but these have not been accepted. Best wishes Rob Cliffe On 03/03/2022 13:24, computermaster360 wrote: I want to make a little survey here. Do you find the for-else construct useful? Have you used it in practice? Do you even know how it works, or that there

Re: All permutations from 2 lists

2022-03-03 Thread Rob Cliffe via Python-list
d help - but goodwill can be used up if it is abused. Respectfully, Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: All permutations from 2 lists

2022-03-01 Thread Rob Cliffe via Python-list
ect technical term). If you only want to use the result once you can write e.g.     for ops, reg in itertools.product(opsys, region):         etc. If you need it more than once, you can convert it to a list (or tuple), as above. Best wishes Rob Cliffe On 02/03/2022 00:12, Larry Martell wrote:

Re: Global VS Local Subroutines

2022-02-10 Thread Rob Cliffe via Python-list
ccess is read-only, though. If the inner function writes to one of the readable external variables, that variable becomes local to the inner function. You can make it continue to refer to the variables of the imbedding function, i.e. b(), by declaring them non-local, e.g.     nonlocal c Rob C

Re: Global VS Local Subroutines

2022-02-10 Thread Rob Cliffe via Python-list
things. But of course, performance is not the only consideration, as per Chris Angelico's answer. Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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:

Re: Negative subscripts

2021-11-26 Thread Rob Cliffe via Python-list
argument means "don't slice here"     [do stuff] Best wishes Rob Cliffe On 26/11/2021 09:17, Frank Millman wrote: Hi all In my program I have a for-loop like this - >>> for item in x[:-y]: ...    [do stuff] 'y' may or may not be 0. If it is 0 I want to pr

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

2021-11-20 Thread Rob Cliffe via Python-list
a repeating decimal but 14 and 10 are not coprime. I believe it is correct to say that infinitely recurring expansions occur when the denominator is divisible by a prime that does not divide the base. Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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

2021-11-20 Thread Rob Cliffe via Python-list
non-mathematician.  I think we have had enough denigration of experts. Best Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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

2021-10-25 Thread Rob Cliffe via Python-list
) events? (I'm not familiar with tkinter, but in wxpython you can.) And if so, does trapping KeyUp solve the problem? Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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

2021-10-22 Thread Rob Cliffe via Python-list
nt directory but this is a horrible solution, subject to race conditions, file permission errors, wrong state after a crash, and probably other problems. It could be cleaned up a bit with try ... except, but is still not to be recommended. Can you just create a copy of your file with a .py extens

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 +1000,

Re: Problem with python

2021-09-04 Thread Rob Cliffe via Python-list
    'print()' in Python 3 outputs a blank line.  In python 2 it prints a line containing a blank tuple: '()'. A 2/3-compatible way of outputting a blank line is     print('') Best wishes Rob Cliffe On 04/09/2021 20:50, Peter J. Holzer wrote: On 2021-09-04 14:29:4

Re: some problems for an introductory python test

2021-08-11 Thread Rob Cliffe via Python-list
that my assumption was wrong. I've never used type annotations, I've never planned to used them. And now that all is revealed, I'm afraid that my reaction is: I'm even more inclined never to use them, because these examples are (to me) so confusing. Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Anaconda navigator not working

2021-06-20 Thread Rob Cliffe via Python-list
n Windows or somewhere in Python. Can anybody shed light on this? Best wishes Rob Cliffe PS I have a very vague idea it's to do with mixing 32-bit and 64-bit software. On 20/06/2021 05:21, Liya Ann Sunny wrote: After installing Anaconda, I tried to open the anaconda navigator but it did not

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

Re: Strange disassembly

2021-06-18 Thread Rob Cliffe via Python-list
   22 POP_JUMP_IF_FALSE   21 (to 14) 24 LOAD_CONST   0 (None) 26 RETURN_VALUE >>> (there may be mistakes in this) but this is probably too much to expect of the compiler. Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

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
reate (or cause to get created) a single instance of it which is used when required.  Indeed disassembling the code shows that LOAD_CONST is used to get the tuple.  But it obviously can't do that when the tuple contains a variable. Rob Cliffe On 14/06/2021 20:35, Chris Angelico wrote: On

Re: learning python ...

2021-05-24 Thread Rob Cliffe via Python-list
ade it so easy to throw ideas around! Regards Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: learning python ...

2021-05-24 Thread Rob Cliffe via Python-list
nd it doesn't try to stop you.  I am sure after a little more experience with Python you will remember the commonest built-in types (int, float, list, dict, str etc.). Regards Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Style qeustion: Multiple return values

2021-04-12 Thread Rob Cliffe via Python-list
ession1, long-expression2)                                    # It might be hard to spot the comma at first glance so the parentheses might help to recognise a tuple. Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list

Re: Friday Finking: initialising values and implied tuples

2021-04-05 Thread Rob Cliffe via Python-list
p trigger arbitrary code? Then I saw your post in the "Yield after the return in Python function" thread.  (Took me a while to understand it.)  So I ask: Can you make a variable lookup trigger arbitrary code, other than in code passed to eval/exec/compile? TIA Rob Cliffe -- https://mai

  1   2   3   4   5   6   7   8   9   10   >