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

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
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? (Chunk  '(a a   b    a a a   b b))     ==> ((a a) (b)  (a a a) (b b)) (Chunk  '(a a a a 

Re: IDLE: clearing the screen

2024-06-08 Thread Rob Cliffe via Python-list
uot; 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
.  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:34, Cave Man

Beep on WIndows 11

2023-11-11 Thread Rob Cliffe via Python-list
rograms that 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 ) #\_/# (Executes

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
ocus 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
ssible 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-22 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
=...)     On 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
rant, 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'word') hash

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
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
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 a code snippet belo

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 of Rob Cli

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/listinfo/python

Re: Cutting slices

2023-03-05 Thread Rob Cliffe via Python-list
his 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
f 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
ial + 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
COT', 'BANANA', 'CANDY'])) The output: BAPPRICNANADYOTLE which has the same length as the answer I came up with trying to solve it with my unaided brain, which may or may not be reassuring , and also contains a much-needed BRANDY. I expect there are simpler and more efficient solutions. Best wish

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
aged (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
cPay(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/listinfo

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

Re: evaluation question

2023-01-30 Thread Rob Cliffe via Python-list
ite() 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, when print was made a function. Best

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
ively 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
tionaries 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
ncisely as: listOfDescriptors = [     { (L := list(D.items())[0])[1] } | {'value' : L[0] }     for D in origListOfDescriptors]     # untested Best wishes Rob Cliffe I actually did it with: listOfDescriptors = list() for cd in origListOfDescriptors:     cn = list(cd.keys())[0] # There

Re: Top level of a recursive function

2022-12-17 Thread Rob Cliffe via Python-list
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
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", it confuses

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
roach, 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 Cliffe -- htt

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','y'

Non-deterministic set ordering

2022-05-15 Thread Rob Cliffe via Python-list
xplain 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
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
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 addressed to him

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
; to mean '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. 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
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 have had

Re: Behavior of the for-else construct

2022-03-03 Thread Rob Cliffe via Python-list
em 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

Re: All permutations from 2 lists

2022-03-03 Thread Rob Cliffe via Python-list
p - 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
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: If I have 2 lists, e.g.: os = ["Linux","Windows"] region

Re: Global VS Local Subroutines

2022-02-10 Thread Rob Cliffe via Python-list
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 Cliffe

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: print("

[issue45896] Conflicting statements in docs about default support for asyncio subprocesses on Windows

2021-11-29 Thread Rob
Change by Rob : -- keywords: +patch pull_requests: +28085 stage: -> patch review pull_request: https://github.com/python/cpython/pull/29857 ___ Python tracker <https://bugs.python.org/issu

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 process

[issue45896] Conflicting statements in docs about default support for asyncio subprocesses on Windows

2021-11-24 Thread Rob
Rob added the comment: Ok will do. Thanks for confirming. -- ___ Python tracker <https://bugs.python.org/issue45896> ___ ___ Python-bugs-list mailing list Unsub

[issue45896] Conflicting statements in docs about default support for asyncio subprocesses on Windows

2021-11-24 Thread Rob
New submission from Rob : Hi, In the docs for the asyncio event loop, it has a note on page: https://docs.python.org/3/library/asyncio-eventloop.html#running-subprocesses "Note The default asyncio event loop on Windows does not support subprocesses. See Subprocess Support on Wi

[issue45888] Revisit: start_tls() difficult when using asyncio.start_server()

2021-11-23 Thread Rob Blackbourn
New submission from Rob Blackbourn : The issue 34975 "start_tls() difficult when using asyncio.start_server()" was closed because streams was being re-written, but it's still a useful enhancement, and a fairly simple change. Could this be revisited? I've done a proof of concept he

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

2021-11-20 Thread Rob Cliffe via Python-list
is 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

[issue44495] wrong FNAME in tarfile if tgz extension is used

2021-11-01 Thread Rob Nelson
Rob Nelson added the comment: The code referenced in the previous comment only hits for tarfiles built from Streams. The same (incorrect) code exists in the gzip.py library as well, and hits the more common usecase of building a tar.gz from a set of files on disk. def _write_gzip_header

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
, 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 extension? Best wishes Rob Cliffe On 22/10/2021 12

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

[issue22239] asyncio: nested event loop

2021-09-28 Thread Rob Moore
Change by Rob Moore : -- nosy: +rob.moore ___ Python tracker <https://bugs.python.org/issue22239> ___ ___ Python-bugs-list mailing list Unsubscribe:

Re: Problem with python

2021-09-04 Thread Rob Cliffe via Python-list
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:47 -0500, Igor Korot wrote: Will this syntax work in python 2? Yes. It's just a redundant

Re: some problems for an introductory python test

2021-08-11 Thread Rob Cliffe via Python-list
ever 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
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 work. When i check i

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
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 Tue,

Re: learning python ...

2021-05-24 Thread Rob Cliffe via Python-list
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
ence 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
)                                    # 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

Re: Friday Finking: initialising values and implied tuples

2021-04-05 Thread Rob Cliffe via Python-list
t; from my "safe" list because I now realise that "set" could be reassigned. Correction: set literals like {7,8} should still be OK as far as I can see. 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
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

  1   2   3   4   5   6   7   8   9   10   >