Is there a way to implement the ** operator on a custom object

2024-02-08 Thread Tony Flury via Python-list
I know that mappings by default support the ** operator, to unpack the mapping into key word arguments. Has it been considered implementing a dunder method for the ** operator so you could unpack an object into a key word argument, and the developer could choose which keywords would be

Re: Python-pickle error

2023-05-09 Thread Tony Flury via Python-list
Charles, by your own admission, you deleted your pkl file, And your code doesn't write that pkl file (pickle.dumps(...) doesn't write a file it creates a new string and at no point will it write to the file : What you need is this : import pickle number=2

Re: Starting using Python

2022-01-27 Thread Tony Flury via Python-list
On 03/01/2022 12:45, Joao Marques wrote: Good morning: I have a very simple question: I want to start writing programs in Python so I went to the Microsoft Store and installed Python3.9. No problem so far. I would prefer to have a gui interface, an interface that I can use file-->Open and

Re: Puzzling behaviour of Py_IncRef

2022-01-26 Thread Tony Flury via Python-list
On 26/01/2022 22:41, Barry wrote: Run python and your code under a debugger and check the ref count of the object as you step through the code. Don’t just step through your code but also step through the C python code. That will allow you to see how this works at a low level. Setting a

Re: Puzzling behaviour of Py_IncRef

2022-01-26 Thread Tony Flury via Python-list
On 26/01/2022 08:20, Chris Angelico wrote: On Wed, 26 Jan 2022 at 19:04, Tony Flury via Python-list wrote: So according to that I should increment twice if and only if the calling code is using the result - which you can't tell in the C code - which is very odd behaviour. No, the return

Re: Puzzling behaviour of Py_IncRef

2022-01-26 Thread Tony Flury via Python-list
On 26/01/2022 01:29, MRAB wrote: On 2022-01-25 23:50, Tony Flury via Python-list wrote: On 25/01/2022 22:28, Barry wrote: On 25 Jan 2022, at 14:50, Tony Flury via Python-list  wrote:  On 20/01/2022 23:12, Chris Angelico wrote: On Fri, 21 Jan 2022 at 10:10, Greg Ewing  wrote: On 20/01

Re: Puzzling behaviour of Py_IncRef

2022-01-25 Thread Tony Flury via Python-list
On 25/01/2022 22:28, Barry wrote: On 25 Jan 2022, at 14:50, Tony Flury via Python-list wrote:  On 20/01/2022 23:12, Chris Angelico wrote: On Fri, 21 Jan 2022 at 10:10, Greg Ewing wrote: On 20/01/22 12:09 am, Chris Angelico wrote: At this point, the refcount has indeed been increased

Re: Puzzling behaviour of Py_IncRef

2022-01-25 Thread Tony Flury via Python-list
On 20/01/2022 23:12, Chris Angelico wrote: On Fri, 21 Jan 2022 at 10:10, Greg Ewing wrote: On 20/01/22 12:09 am, Chris Angelico wrote: At this point, the refcount has indeed been increased. return self; } And then you say "my return value is this object". So you're

Re: Puzzling behaviour of Py_IncRef

2022-01-19 Thread Tony Flury via Python-list
On 19/01/2022 11:09, Chris Angelico wrote: On Wed, Jan 19, 2022 at 10:00 PM Tony Flury via Python-list wrote: Extension function : static PyObject *_Node_test_ref_count(PyObject *self) { printf("\nIncrementing ref count for self - just for the hell of

Puzzling behaviour of Py_IncRef

2022-01-19 Thread Tony Flury via Python-list
I am writing a C extension module for an AVL tree, and I am trying to ensure reference counting is done correctly. I was having a problem with the reference counting so I worked up this little POC of the problem, and I hope someone can explain this. Extension function : static PyObject

Re: pyinstaller wrong classified as Windows virus

2021-11-28 Thread Tony Flury via Python-list
Have you tried using Nuitka - rather than pyInstalller - it means you distribute a single executable and the Python run time library (which they probably have already), and it has the advantage that it is a bit quicker than standard python. Rather than bundle the source code and interpreter

Re: Embedding version in command-line program

2020-10-17 Thread Tony Flury via Python-list
On 07/10/2020 12:06, Loris Bennett wrote: Hi, I have written a program, which I can run on the command-line thus mypyprog --version and the get the version, which is currently derived from a variable in the main module file. However, I also have the version in an __init__.py file and in

Simple question - end a raw string with a single backslash ?

2020-10-13 Thread Tony Flury via Python-list
I am trying to write a simple expression to build a raw string that ends in a single backslash. My understanding is that a raw string should ignore attempts at escaping characters but I get this : >>> a = r'end\'   File "", line 1     a = r'end\'   ^ SyntaxError:

Re: Any ideas for a new language inspired to Python?

2020-09-05 Thread Tony Flury via Python-list
C/machine code. -- Tony Flury -- https://mail.python.org/mailman/listinfo/python-list

Re: Solved: Re: Missing python curses functions?

2020-06-29 Thread Tony Flury via Python-list
Maybe you should raise a bug (bugs.python.org) and flag that this function is missing. It could be that it can be introduced by whoever is maintaining the existing code. On 20/05/2020 08:31, Alan Gauld via Python-list wrote: On 19/05/2020 20:53, Alan Gauld via Python-list wrote: One of

Re: Floating point problem

2020-06-23 Thread Tony Flury via Python-list
On 18/04/2020 15:29, Grant Edwards wrote: On 2020-04-18, Souvik Dutta wrote: I literally tried it!!! And it did not stop because I did not get any 1.0 rather I got 0.999 But why does this happen. This is a simple math which according to normal human logic should give perfect numbers

Re: How to test?

2020-06-19 Thread Tony Flury via Python-list
On 24/04/2020 19:40, Manfred Lotz wrote: I have a command like application which checks a directory tree for certain things. If there are errors then messages will be written to stdout. How to test this in the best way? One idea was for the error situations to write messages to files and

Re: Function to avoid a global variable

2020-04-29 Thread Tony Flury via Python-list
foo(i): foo.bar += i foo.bar = 5 --Jach And as you have shown - foo.bar is effectively a global variable - just one with a qualified name :-) -- Tony Flury -- https://mail.python.org/mailman/listinfo/python-list

Re: RFC: For Loop Invariants

2020-04-20 Thread Tony Flury via Python-list
On 10/04/2020 21:44, Elliott Dehnbostel wrote: *We could do this:* chars = "abcaaabkjzhbjacvb" seek = {'a','b','c'} count = sum([1 for a in chars if a in seek]) However, this changes important semantics by creating an entire new list before summing. Creating the list is pointless in this

Re: on sorting things

2020-01-28 Thread Tony Flury via Python-list
On 20/12/2019 18:59, Peter Otten wrote: Chris Angelico wrote: On Sat, Dec 21, 2019 at 5:03 AM Peter Otten <__pete...@web.de> wrote: PS: If you are sorting files by size and checksum as part of a deduplication effort consider using dict-s instead: Yeah, I'd agree if that's the purpose. But

[issue22318] unitest documentation on assertItemsEqual misleading

2014-08-31 Thread Tony Flury
New submission from Tony Flury: The notes on assertItemsEqual do not make it clear that the comparison works by using their hash value, and not their __eq__ implementation - i.e. it does an 'is' not an '==' between objects in the sequence. If the sequences being compared contain user created