Re: xor operator

2023-11-13 Thread Michael Speer via Python-list
>AFAICT, it's not nothing at all to do with 'xor' in any sense. As much as I agree that the function needn't be in the base of python, I can easily follow the OP's logic on the function name. With two items in the iterator, it is a standard binary exclusive or. It is true if one of but not both

Re: xor operator

2023-11-13 Thread Michael Speer via Python-list
I don't think an exclusive-or/truthy-entries-count-checker needs to be a builtin by any stretch. >>> def xor( iterable, n = 1 ): ... return sum( map( bool, iterable ) ) == n Or if you insist on short circuiting: >>> def xor_ss( iterable, n = 1 ): ... for intermediate in itertools.accumulat

Re: Is there a more efficient threading lock?

2023-02-26 Thread Michael Speer
1 (vv) is effectively locked/atomic on post-3.10 interpreters, though this is neither portable nor guaranteed to stay that way into the future On Sun, Feb 26, 2023 at 10:19 PM Michael Speer wrote: > I wanted to provide an example that your claimed atomicity is simply > wrong, but I found there is

Re: Is there a more efficient threading lock?

2023-02-26 Thread Michael Speer
I wanted to provide an example that your claimed atomicity is simply wrong, but I found there is something different in the 3.10+ cpython implementations. I've tested the code at the bottom of this message using a few docker python images, and it appears there is a difference starting in 3.10.0 p

Re: In code, list.clear doesn't throw error - it's just ignored

2022-11-13 Thread Michael Speer
Python doesn't care what an expression returns. You've written an expression that returns the value of the 'clear' function that is bound to that particular list. The interpreter doesn't know or care if accessing that 'clear' attribute on the class returns a function or for some reason triggers a

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

2022-10-09 Thread Michael Speer
>Well, the value is productivity. No need to save puzzles "what this >hanging else belongs to?" if you get to the point where it's hard to tell which else lines up with which if or for statement, I would suggest breaking things out into well-named helper functions rather than worrying over orderin

Re: Renaming an import

2019-09-05 Thread Michael Speer
pkg/graph.py: from graphing_module_b import plot, axis pkg/foobar.py: from .graph import plot, axis Would it be sufficient to use a file for indirection? On Thu, Sep 5, 2019 at 7:11 PM Rob Gaddi wrote: > I'm trying to figure out how to rename an import globally for an entire > packa

Re: Proper shebang for python3

2019-07-20 Thread Michael Speer
You may want to use `#!/usr/bin/env python3` instead. There is a concept in python called the virtual environment. This used to be done with a tool called virtualenv in python2, and is now done mainly through a venv module in python3. A virtual environment goes into a directory of your choosing a

Re: Problem calling script with arguments

2013-10-15 Thread Michael Speer
> "/usr/sbin/ftpasswd" "--hash" You're missing a comma, and python automatically concatenates adjacent strings. On Tue, Oct 15, 2013 at 1:13 PM, Florian Lindner wrote: > Hello, > > I have a 3rd party perl script: > > head -n 1 /usr/sbin/ftpasswd > #!/usr/bin/perl > > I want to write data to s

Re: object.enable() anti-pattern

2013-05-09 Thread Michael Speer
By his reasoning it simply shouldn't exist. Instead you would access the information only like this: with open("myfile.dat") as f: data = f.read() Which is my preferred way to work with resources requiring cleanup in python anyways, as it ensures I have the least chance of messing things up, an

Re: newbie:this program stops responding after pressing quit button

2007-12-04 Thread Michael Speer
ers to it. Load up your interpreter and play with it interactively. Remember the dir( object ) command will give a full listing of the attributes of any given object. Looking at object.__doc__ will give you the documentation. There's probably something in there to hide the window if that

A context manager for temporary memoization.

2007-11-29 Thread Michael Speer
I posted this to my blog at http://michaelspeer.blogspot.com/2007/11/context-manager-for-temporary.html. I decided to forward it onto the list for comments. I thought someone might find it interesting. *** This is very much a fragile hack at the moment. It's an interesting idea I think. I was d

Haskell lambdas in python

2007-08-16 Thread Michael Speer
#x27;\\': return LAMBDAARGS; } to PyToken_TwoChars. The interactive runtime requires the OneChar definition, and the compilation process ( specifically pgen ) requires the TwoChar definition. If anyone wants the changes required to play around with it just email me and I'll