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

2023-02-25 Thread Weatherby,Gerard
ehalf of Peter J. Holzer Date: Saturday, February 25, 2023 at 5:21 PM To: python-list@python.org Subject: Re: Why doesn't Python (error msg) tell me WHAT the actual (arg) values are ? On 2023-02-25 21:58:18 +, Weatherby,Gerard wrote: > I only use asserts for things I know to be true.

Programming by contract.

2023-02-25 Thread Weatherby,Gerard
The discussion of asserts got me thinking about Programming by Contract. Back in the 90s, I had occasion to learn Eiffel programming language. ( https://en.wikipedia.org/wiki/Eiffel_(programming_language) The concepts are intriguing, although Eiffel itself had barriers to widespread adoption. R

Python type system

2023-02-27 Thread Weatherby,Gerard
When I first started transitioning to Python as a Perl replacement, with my Java/C++ baggage, I thought Pythnon had some loosey-goosey type system. I thought int() and str() were casts, not constructors. I now realize Python has a great strong type system. Duck typing. If it walks like a duck, q

Re: How to escape strings for re.finditer?

2023-02-28 Thread Weatherby,Gerard
Regex is fine if it works for you. The critiques – “difficult to read” –are subjective. Unless the code is in a section that has been profiled to be a bottleneck, I don’t sweat performance at this level. For me, using code that has already been written and vetted is the preferred approach to wr

Re: Look free ID genertion (was: Is there a more efficient threading lock?)

2023-03-01 Thread Weatherby,Gerard
So I guess we know what would have happened. Get Outlook for iOS From: Python-list on behalf of Chris Angelico Sent: Wednesday, March 1, 2023 8:45:50 PM To: python-list@python.org Subject: Re: Look free ID genertion (was: Is there a more

Re: Packing Problem

2023-03-02 Thread Weatherby,Gerard
Haven’t look at it all in detail, but I’d replace the list comprehensions with a loop: CopyOfWords = list(Words) Words = [(w[1:] if w[0] == ch else w) for w in Words] Words = [w for w in Words if w != ''] nextWords = [] for w in CopyOfWords:

Re: Python list insert iterators

2023-03-04 Thread Weatherby,Gerard
Python lists are arrays in other languages. You’ll have to roll your own or find something in https://pypi.org, etc. I think this incomplete implementation does the trick. # # MIT licensed # from dataclasses import dataclass from typing import TypeVar, Generic T = TypeVar("T") @dataclass clas

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread Weatherby,Gerard
Nope. No consensus. I’d use self.__class__ . Seems more explicit and direct to me. From: Python-list on behalf of Ian Pilcher Date: Thursday, March 2, 2023 at 4:17 PM To: python-list@python.org Subject: Which more Pythonic - self.__class__ or type(self)? *** Attention: This is an external ema

Re: Fast full-text searching in Python (job for Whoosh?)

2023-03-06 Thread Weatherby,Gerard
Not sure if this is what Thomas meant, but I was also thinking dictionaries. Dino could build a set of dictionaries with keys “a” through “z” that contain data with those letters in them. (I’m assuming case insensitive search) and then just search “v” if that’s what the user starts with. Increa

Re: Fast full-text searching in Python (job for Whoosh?)

2023-03-06 Thread Weatherby,Gerard
“Dino, Sending lots of data to an archived forum is not a great idea. I snipped most of it out below as not to replicate it.” Surely in 2023, storage is affordable enough there’s no need to criticize Dino for posting complete information. If mailing space is a consideration, we could all help by

Re: Bug 3.11.x behavioral, open file buffers not flushed til file closed.

2023-03-06 Thread Weatherby,Gerard
Add f.reconfigure it you want line buffering in your example: f = open("abc", "w") f.reconfigure(line_buffering=True) for i in range(5): f.write(str(i) + "\n") More Pythonic would be: with open("abc", "w") as f: for i in range(5000): print(i,file=f) From: Python-list on behalf

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Weatherby,Gerard
Other than the admittedly subjective viewpoint that using the lambda is confusing, there’s probably nothing wrong with the lambda approach. A couple of alternatives: def e(): for e in (e1,e2,e3): e.config(state="normal") b = tk.Button(master=main, text="Enable",command=e) or b =

Re: Baffled by readline module

2023-03-10 Thread Weatherby,Gerard
I would say, “No, readline is not the right tool.” cmd.Cmd is: https://docs.python.org/3/library/cmd.html. I have a couple of cmd.Cmd modules, one of which I use daily and the other weekly. From: Python-list on behalf of Grant Edwards Date: Thursday, March 9, 2023 at 2:29 PM To: python-list@p

Re: Baffled by readline module

2023-03-10 Thread Weatherby,Gerard
Edwards Date: Friday, March 10, 2023 at 9:39 AM To: python-list@python.org Subject: Re: Baffled by readline module *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** On 2023-03-10, Weatherby,Gerard wrote: > I would say, “No, readline

Re: Baffled by readline module

2023-03-10 Thread Weatherby,Gerard
alf of Cameron Simpson Date: Friday, March 10, 2023 at 5:15 PM To: python-list@python.org Subject: Re: Baffled by readline module *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** On 10Mar2023 09:12, Grant Edwards wrote: >On 202

Re: Tkinter and cv2: "not responding" popup when imshow launched from tk app

2023-03-14 Thread Weatherby,Gerard
Assuming you’re using opencv-python, I’d post query at https://github.com/opencv/opencv-python/issues. From: Python-list on behalf of John O'Hagan Date: Tuesday, March 14, 2023 at 6:56 AM To: Python list Subject: Tkinter and cv2: "not responding" popup when imshow launched from tk app *** At

Re: Distributing program for Linux

2023-03-14 Thread Weatherby,Gerard
It’s really going to depend on the distribution and whether you have root access. If you have Ubuntu and root access, you can add the deadsnakes repo, https://launchpad.net/~deadsnakes, and install whatever Python you want. The default ‘python3’ remains but you can called a specific Python, (e.

Re: Debugging reason for python running unreasonably slow when adding numbers

2023-03-15 Thread Weatherby,Gerard
Sum is faster than iteration in the general case. Lifting a test program from Stack Overflow https://stackoverflow.com/questions/24578896/python-built-in-sum-function-vs-for-loop-performance, import timeit def sum1(): s = 0 for i in range(100): s += i return s def sum2(

Re: Debugging reason for python running unreasonably slow when adding numbers

2023-03-15 Thread Weatherby,Gerard
.timeit(sum2, number=100)) --- For Loop Sum: 6.984986504539847 Built-in Sum: 0.5175364706665277 From: Weatherby,Gerard Date: Wednesday, March 15, 2023 at 1:09 PM To: python-list@python.org Subject: Re: Debugging reason for python running unreasonably slow when adding numbers Sum is faster t

Re: Implementing a plug-in mechanism

2023-03-15 Thread Weatherby,Gerard
Yes, that works, and I’ve used that on a couple of projects. Another alternative is defining an Abstract Base Class, https://docs.python.org/3/library/abc.html, and having an institution-specific implementation passed into your module. From: Python-list on behalf of Loris Bennett Date: Wedne

Re: Implementing a plug-in mechanism

2023-03-15 Thread Weatherby,Gerard
I do something similar to Thomas. (Also MIT licensed). I like objects. I like type hints. Each plugin needs to have check and purpose functions and accepts either PluginSpec (by default) or AddonSpec if it defines addon = True This requires a single-level plugin directory with no extra files in

Re: Friday finking: IDE 'macro expansions'

2023-03-18 Thread Weatherby,Gerard
I send ~99% of Python coding time in PyCharm. Likewise, IntelliJ and Clion for Java and C++, respectively. Mostly use: Tab completion for variable names Letting PyCharm figure out imports for me, and cleaning up old, unused imports. Jumping to definitions of symbols. Tellling me I’ve made a type

<    1   2