Re: how to discover what values produced an exception?

2024-05-04 Thread Dieter Maurer via Python-list
Johanne Fairchild wrote at 2024-5-3 10:56 -0300: >How to discover what values produced an exception? Or perhaps---why >doesn't the Python traceback show the values involved in the TypeError? >For instance: > >--8<>8--- (0,0) < 4

Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Dieter Maurer via Python-list
dieter.mau...@online.de wrote at 2024-3-22 18:28 +0100: >Thomas Nyberg wrote at 2024-3-22 11:08 +0100: >> ... `future` use across thread boundaries ... >> Here's an example using just the standard library that >> exhibits the same issue: > ... >For use across thread boundaries, you likely will use

Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Dieter Maurer via Python-list
Thomas Nyberg wrote at 2024-3-22 11:08 +0100: > ... `future` use across thread boundaries ... > Here's an example using just the standard library that > exhibits the same issue: I think all `asyncio` objects (futures, tasks, ...) are meant to be used in a single thread. If you use them across

Re: Popping key causes dict derived from object to revert to object

2024-03-21 Thread Dieter Maurer via Python-list
Loris Bennett wrote at 2024-3-21 10:56 +0100: > ... >So as I understand it, I need to convert the InstanceState-objects to, >say, dicts, in order to print them. However I also want to remove one >of the keys from the output and assumed I could just pop it off each >event dict, thus: > >

Re: Error in Module

2024-03-11 Thread Dieter Maurer via Python-list
Sanskar Mukeshbhai Joshi wrote at 2024-3-10 18:08 +: >I had made my project in BCA in Python. When I had complete my project and run >the program, at that time I got the error in runnig my project. The error was >ModuleNotFoundError: No module named 'flask'. `flask` is not part of the

RE: Extract lines from file, add to new files

2024-01-29 Thread Dieter Maurer via Python-list
Rich Shepard wrote at 2024-1-29 08:15 -0800: > ... >If this explanation is not sufficiently clear I'll re-write it. :-) Have you read "https://docs.python.org/3/library/io.html#module-io;? -- https://mail.python.org/mailman/listinfo/python-list

Re: Await expressions (Posting On Python-List Prohibited)

2024-01-27 Thread Dieter Maurer via Python-list
>On 27/01/24 10:46 am, Stefan Ram wrote: >>But your explanation seems to have no mention of the "something" / >>"the awaitable object" part following the preposition "on". Shouldn't >>this awaitable object play a rôle in the explanation of what happens? You can explain a function call

Re: Question about garbage collection

2024-01-15 Thread Dieter Maurer via Python-list
Frank Millman wrote at 2024-1-15 15:51 +0200: >I have read that one should not have to worry about garbage collection >in modern versions of Python - it 'just works'. There are still some isolated cases when not all objects in an unreachable cycle are destroyed (see e.g. step 2 of

Re: extend behaviour of assignment operator

2024-01-10 Thread Dieter Maurer via Python-list
Guenther Sohler wrote at 2024-1-9 08:14 +0100: >when i run this code > >a = cube([10,1,1]) >b = a > >i'd like to extend the behaviour of the assignment operator >a shall not only contain the cube, but the cube shall also know which >variable name it >was assigned to, lately. I'd like to use that

Re: Context without manager

2023-11-26 Thread Dieter Maurer via Python-list
Piergiorgio Sartor wrote at 2023-11-25 22:15 +0100: > ... >Apparently, the "with" context manager is not usable >in classes, at least not with __init__() & co. You can use `with` in classes -- with any context manager. However, you would usually not use `with` with a file you have opened in

Re: __set_name__ equivalent for instance

2023-11-16 Thread Dieter Maurer via Python-list
Dom Grigonis wrote at 2023-11-16 21:11 +0200: > ... >> On 16 Nov 2023, at 21:00, Dieter Maurer wrote: >> ... >> Methods are not bound during instance creation, they are bound during >> access. > >Good to know. What is the criteria for binding then? Does i

Re: __set_name__ equivalent for instance

2023-11-16 Thread Dieter Maurer via Python-list
Dom Grigonis wrote at 2023-11-16 20:12 +0200: >What I am interested in is a callback. >Preferably just after methods get bound. So in `object.__new__`. >I have done it via metaclass, but it is not ideal as there would be too much >overhead. > >I think what I am looking for is custom method

Re: __set_name__ equivalent for instance

2023-11-16 Thread Dieter Maurer via Python-list
Dom Grigonis wrote at 2023-11-15 18:44 +0200: >So there is a method __set_name__ which is called on class creation. > >The functionality that I am interested in is not retrieving name, but the fact >that it also receives `owner` argument. > >Thus, allowing simulation of bound class method. > >I

Re: Detect naming typos (AttributeError) in function names

2023-11-06 Thread Dieter Maurer via Python-list
c.bu...@posteo.jp wrote at 2023-11-6 12:47 +: >I would like to know how to detect (e.g. via a linter) typos in function >names imported from another module. One option is a test suite (--> Python's "unittest" package) with a sufficiently high coverage (near 100 %). --

Re: pip/pip3 confusion and keeping up to date

2023-11-06 Thread Dieter Maurer via Python-list
Karsten Hilbert wrote at 2023-11-5 23:19 +0100: > ... >do you happen to know where to read up on how to fit a pip >constraint file into a Debian package creation workflow ? I have only rudimentary `apt` knowledge. I know it is quite flexible, e.g. it used to handle `flash` in a special way. I

Re: pip/pip3 confusion and keeping up to date

2023-11-03 Thread Dieter Maurer via Python-list
Karsten Hilbert wrote at 2023-11-3 14:47 +0100: > ... >> Are they not available in your system's package manager? > >... this clearly often answers to "no" for applications of >any complexity. > >Is there a suggested proper path to deal with that (Debian is >of interest to me here) ? Complex

Re: pip/pip3 confusion and keeping up to date

2023-11-02 Thread Dieter Maurer via Python-list
Chris Green wrote at 2023-11-2 10:58 +: > ... >So, going on from this, how do I do the equivalent of "apt update; apt >upgrade" for my globally installed pip packages? `pip list -o` will tell you for which packages there are upgrades available. `pip install -U ...` will upgrade packages. Be

Re: How to find any documentation for smbus?

2023-10-30 Thread Dieter Maurer via Python-list
Chris Green wrote at 2023-10-28 17:08 +0100: >I am using the python3 smbus module, but it's hard work because of the >lack of documentation. Web searches confirm that the documentation is >somewhat thin! > >If you do the obvious this is what you get:- > >>>> import smbus >>>> dir (smbus)

Re: NameError: name '__version__' is not defined

2023-10-27 Thread Dieter Maurer via Python-list
Loris Bennett wrote at 2023-10-27 09:29 +0200: > ... >For the application with the system Python this mechanism works, but for >the non-system Python I get the error: > > NameError: name '__version__' is not defined If you get exceptions (they usually end in `Error` (such as `NameError`)), look

Re: Question(s)

2023-10-25 Thread Dieter Maurer via Python-list
o1bigtenor wrote at 2023-10-25 08:29 -0500: > ... >It would appear that something has changed. > >Went to the Eclipse download page, downloaded and verified (using sha-512). >Expanded software to # opt . >There is absolutely NO mention of anything python - - - java, c and >its permutations,

Re: Question(s)

2023-10-25 Thread Dieter Maurer via Python-list
o1bigtenor wrote at 2023-10-25 07:50 -0500: >> There are several others, >> e.g. "ECLIPSE" can be used for Python development. > >Is 'Eclipse' a Windows oriented IDE? No. ==> "https://en.wikipedia.org/wiki/Eclipse_(software)" -- https://mail.python.org/mailman/listinfo/python-list

Re: Question(s)

2023-10-25 Thread Dieter Maurer via Python-list
o1bigtenor wrote at 2023-10-25 06:44 -0500: >On Wed, Oct 25, 2023 at 6:24?AM Dieter Maurer wrote: > ... >> There are different kinds of errors. >> >> Some can be avoided by using an integrated development environment >> (e.g. misspellings, type mismatches, ...). &g

Re: Simple webserver

2023-10-25 Thread Dieter Maurer via Python-list
Frank Millman wrote at 2023-10-25 09:57 +0200: > ... >Based on this, I am considering the following - > >1. Replace my HTTP handler with Uvicorn. Functionality should be the >same, but performance should be improved. > >2. Instead of running as a stand-alone server, run my app as a >reverse-proxy

Re: Question(s)

2023-10-25 Thread Dieter Maurer via Python-list
o1bigtenor wrote at 2023-10-24 07:22 -0500: > ... >Is there a way to verify that a program is going to do what it is >supposed to do even >before all the hardware has been assembled and installed and tested? Others have already noted that "verify" is a very strong aim. There are different kinds

Re: Simple webserver

2023-10-22 Thread Dieter Maurer via Python-list
Janis Papanagnou wrote at 2023-10-21 04:03 +0200: > ... >I'd like to ask; where do you see the specific risks with Python >(as language per se) and it's (web-socket-)libraries here? The web server in Python's runtime library is fairly simple, focusing only on the HTTP requirements. You might

Re: How to write list of integers to file with struct.pack_into?

2023-10-02 Thread Dieter Maurer via Python-list
Jen Kris wrote at 2023-10-2 00:04 +0200: >Iwant to write a list of 64-bit integers to a binary file. Everyexample I >have seen in my research convertsit to .txt, but I want it in binary. I wrote >this code,based on some earlier work I have done: > >buf= bytes((len(qs_array)) * 8) > >for offset

Re: Passing info to function used in re.sub

2023-09-04 Thread Dieter Maurer via Python-list
Jan Erik Moström wrote at 2023-9-3 18:10 +0200: >I'm looking for some advice for how to write this in a clean way > ... >The "problem" is that I've currently written some code that works but it uses >global variables ... and I don't like global variables. I assume there is a >better way to write

Re: GNU gettext: Print string translated and untranslated at the same time

2023-08-17 Thread Dieter Maurer via Python-list
c.bu...@posteo.jp wrote at 2023-8-17 07:10 +: >I want to display one string in its original source (untranslated) >version and in its translated version site by site without duplicating >the string in the python source code? You could try to translate into an unknown language: this should

Re: GNU gettext: Print string translated and untranslated at the same time

2023-08-17 Thread Dieter Maurer via Python-list
c.bu...@posteo.jp wrote at 2023-8-17 07:10 +: >I want to display one string in its original source (untranslated) >version and in its translated version site by site without duplicating >the string in the python source code? Is it an option for you to replace the `gettext` binding by

Re: How to find the full class name for a frame

2023-08-04 Thread Dieter Maurer via Python-list
Jason Friedman wrote at 2023-8-3 21:34 -0600: > ... >my_frame = inspect.currentframe() > ... >My question is: let's say I wanted to add a type hint for my_frame. `my_frame` will be an instance of `Types.FrameType`. -- https://mail.python.org/mailman/listinfo/python-list

Re: Fallback for operator and other dunder methods

2023-07-26 Thread Dieter Maurer via Python-list
Dom Grigonis wrote at 2023-7-26 05:22 +0300: > ... >Is there a way to achieve it without actually implementing operators? >I have looked at Proxy objects, but they do not seem suited to achieve this. Proxying is a good approach: you might have a look at `dm.reuse.proxy.OverridingProxy` (-->

Re: Meta Class Maybe?

2023-07-23 Thread Dieter Maurer via Python-list
Chris Nyland wrote at 2023-7-22 19:12 -0400: >So I am stuck on a problem. I have a class which I want to use to create >another class without having to go through the boiler plate of subclassing. Do you know about `__init_subclass__`? It is called whenever a class is subclassed and can be used to

Re: Canonical list of Python security vulnerabilities

2023-07-15 Thread Dieter Maurer via Python-list
Bob Kline wrote at 2023-7-14 13:35 -0400: >Can someone point me to the official catalog of security vulnerabilities in >Python (by which I mean cpython and the standard libraries)? I found >https://www.cvedetails.com/vulnerability-list/vendor_id-10210/product_id-18230/Python-Python.html >but that

Re: "Invalid literal for int() with base 10": is it really a literal?

2023-05-26 Thread Dieter Maurer
Chris Angelico wrote at 2023-5-26 18:29 +1000: > ... >However, if you want to change the wording, I'd be more inclined to >synchronize it with float(): > float("a") >Traceback (most recent call last): > File "", line 1, in >ValueError: could not convert string to float: 'a' +1 --

Re: Do subprocess.PIPE and subprocess.STDOUT sametime

2023-05-10 Thread Dieter Maurer
Horst Koiner wrote at 2023-5-9 11:13 -0700: > ... >For production i run the program with stdout=subprocess.PIPE and i can fetch >than the output later. For just testing if the program works, i run with >stdout=subprocess.STDOUT and I see all program output on the console, but my >program

Re: What do these '=?utf-8?' sequences mean in python?

2023-05-08 Thread Dieter Maurer
Chris Green wrote at 2023-5-6 15:58 +0100: >Chris Green wrote: >> I'm having a real hard time trying to do anything to a string (?) >> returned by mailbox.MaildirMessage.get(). >> >What a twit I am :-) > >Strings are immutable, I have to do:- > >newstring = oldstring.replace("_", " ") The

Re: Using loguru in a library

2023-05-02 Thread Dieter Maurer
Roy Hann wrote at 2023-4-30 15:40 -: >Is there anyone using loguru (loguru 0.5.3 in my case) successfully in a >library? > ... > import mylib > logger.enable('mylib') > >expecting that it would report any log messages above level DEBUG, just >as it does when I don't disable logging. Have

Re: Embedded python is not 100% stable

2023-04-13 Thread Dieter Maurer
Guenther Sohler wrote at 2023-4-13 09:40 +0200: > ... >I have been working on adding embedded python into OpenSCAD ( >www.openscad.org) >for some time already. For that i coded/added an additional Python Type >Object >which means to hold openscad geometric data. > >It works quite well but

Re: Problem in using libraries

2023-04-04 Thread Dieter Maurer
Pranav Bhardwaj wrote at 2023-4-3 22:13 +0530: >Why can't I able to use python libraries such as numpy, nudenet, playsound, >pandas, etc in my python 3.11.2. It always through the error "import >'numpy' or any other libraries could not be resolved". The "libraries" you speak of are extensions

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

2023-03-06 Thread Dieter Maurer
aapost wrote at 2023-3-5 09:35 -0500: > ... >If a file is still open, even if all the operations on the file have >ceased for a time, the tail of the written operation data does not get >flushed to the file until close is issued and the file closes cleanly. This is normal: the buffer is flushed

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

2023-03-01 Thread Dieter Maurer
Chris Angelico wrote at 2023-3-1 12:58 +1100: > ... > The >atomicity would be more useful in that context as it would give >lock-free ID generation, which doesn't work in Python. I have seen `itertools.count` for that. This works because its `__next__` is implemented in "C" and therefore will not

Re: semi colonic

2023-02-23 Thread Dieter Maurer
Thomas Passin wrote at 2023-2-22 21:04 -0500: >On 2/22/2023 7:58 PM, avi.e.gr...@gmail.com wrote: > ... >> So can anyone point to places in Python where a semicolon is part of a best >> or even good way to do anything? > >Mostly I use it to run small commands on the command line with python >-c.

Re: File write, weird behaviour

2023-02-19 Thread Dieter Maurer
Azizbek Khamdamov wrote at 2023-2-19 19:03 +0500: > ... >Example 2 (weird behaviour) > >file = open("D:\Programming\Python\working_with_files\cities.txt", >'r+') ## contains list cities ># the following code DOES NOT add new record TO THE BEGINNING of the >file IF FOLLOWED BY readline() and

Re: asyncio questions

2023-01-26 Thread Dieter Maurer
Frank Millman wrote at 2023-1-26 12:12 +0200: >I have written a simple HTTP server using asyncio. It works, but I don't >always understand how it works, so I was pleased that Python 3.11 >introduced some new high-level concepts that hide the gory details. I >want to refactor my code to use these

Re: [Help Request] Embedding Python in a CPP Application Responsibly & Functionally

2023-01-26 Thread Dieter Maurer
John McCardle wrote at 2023-1-25 22:31 -0500: > ... >1) To get the compiled Python to run independently, I have to hack >LD_LIBRARY_PATH to get it to execute. `LD_LIBRARY_PATH=./Python-3.11.1 >./Python-3.11.1/python` . The need to set `LD_LIBRARY_PATH` usually can be avoided via a link time

Re: Python - working with xml/lxml/objectify/schemas, datatypes, and assignments

2023-01-11 Thread Dieter Maurer
aapost wrote at 2023-1-10 22:15 -0500: >On 1/4/23 12:13, aapost wrote: >> On 1/4/23 09:42, Dieter Maurer wrote: >> ... >>> You might have a look at `PyXB`, too. >>> It tries hard to enforce schema restrictions in Python code. >> ... >Unfortunately pick

Re: Mailing-Lists (pointer)

2023-01-11 Thread Dieter Maurer
Cameron Simpson wrote at 2023-1-11 08:37 +1100: > ... >There's a Discourse forum over at discuss.python.org. I use it in >"mailing list mode" and do almost all my interactions via email, exactly >as I do for python-list. Posts come to me and land in the same local >mail folder I use for

Re: Mailing-Lists (pointer)

2023-01-10 Thread Dieter Maurer
Chris Green wrote at 2023-1-10 08:45 +: > ... >Yes, this is important I think. Plus, if possible, if it's decided to >move to a forum format make that accessible by E-Mail. I much prefer a mailing list over an http based service. With mailing lists, all interesting messages arrive in my

Re: hello can I be in your group?

2023-01-07 Thread Dieter Maurer
Keith Thompson wrote at 2023-1-6 17:02 -0800: >September Skeen writes: >> I was wondering if I could be in your group > >This is an unmoderated Usenet newsgroup. In fact, there are several access channels, Usenet newsgroup is one of them. Another channel is the python-list mailing list. You can

Re: Python - working with xml/lxml/objectify/schemas, datatypes, and assignments

2023-01-04 Thread Dieter Maurer
aapost wrote at 2023-1-3 22:57 -0500: > ... >Consider the following: > >from lxml import objectify, etree >schema = etree.XMLSchema(file="path_to_my_xsd_schema_file") >parser = objectify.makeparser(schema=schema, encoding="UTF-8") >xml_obj = objectify.parse("path_to_my_xml_file", parser=parser)

Re: How make your module substitute a python stdlib module.

2022-12-27 Thread Dieter Maurer
Antoon Pardon wrote at 2022-12-27 14:25 +0100: > ... >> But a simple "sys.modules['threading'] = QYZlib.threaders" will work. >> Of course, how *well* this works depends also on how well that module >> manages to masquerade as the threading module, but I'm sure you've >> figured that part out :) >

Re: ContextVars in async context

2022-12-21 Thread Dieter Maurer
Marce Coll wrote at 2022-12-20 22:09 +0100: >Hi python people, hope this is the correct place to ask this! > >For a transactional async decorator I'm building I am using contextvars in >order to know when a transaction is open in my current context. > >My understanding is that if given the

Re: pip issue

2022-11-30 Thread Dieter Maurer
Gisle Vanem wrote at 2022-11-30 10:51 +0100: >I have an issue with 'pip v. 22.3.1'. On any >'pip install' command I get warning like this: > c:\> pip3 install asciinema > WARNING: Ignoring invalid distribution -arkupsafe > (f:\gv\python310\lib\site-packages) > WARNING: Ignoring invalid

Re: Importlib behaves differently when importing pyd file

2022-11-16 Thread Dieter Maurer
Jach Feng wrote at 2022-11-15 22:52 -0800: >My working directory d:\Works\Python\ has a package 'fitz' looks like this: > >fitz\ >__init__.py >fitz.py >utils.py >_fitz.pyd > >There is a statement in fitz.py: >return importlib.import_module('fitz._fitz') >

Re: Dealing with non-callable classmethod objects

2022-11-11 Thread Dieter Maurer
Ian Pilcher wrote at 2022-11-11 15:29 -0600: > ... >In searching, I've found a few articles that discuss the fact that >classmethod objects aren't callable, but the situation actually seems to >be more complicated. > > >>> type(DuidLLT._parse_l2addr) > > >>> callable(DuidLLT._parse_l2addr) >True >

Re: Superclass static method name from subclass

2022-11-11 Thread Dieter Maurer
Ian Pilcher wrote at 2022-11-11 10:21 -0600: >Is it possible to access the name of a superclass static method, when >defining a subclass attribute, without specifically naming the super- >class? > >Contrived example: > > class SuperClass(object): > @staticmethod > def foo(): >

Re: setup.py + cython == chicken and the egg problem

2022-08-17 Thread Dieter Maurer
Dan Stromberg wrote at 2022-8-16 14:03 -0700: > ... >I'm attempting to package up a python package that uses Cython. > ... > Installing build dependencies ... error > error: subprocess-exited-with-error > > ×? pip subprocess to install build dependencies did not run successfully. > ?? exit

Re: Parallel(?) programming with python

2022-08-11 Thread Dieter Maurer
Dennis Lee Bieber wrote at 2022-8-10 14:19 -0400: >On Wed, 10 Aug 2022 19:33:04 +0200, "Dieter Maurer" > ... >>You could also use the `sched` module from Python's library. > >Time to really read the library reference manual again... > > Thoug

RE: Parallel(?) programming with python

2022-08-10 Thread Dieter Maurer
Schachner, Joseph (US) wrote at 2022-8-9 17:04 +: >Why would this application *require* parallel programming? This could be >done in one, single thread program. Call time to get time and save it as >start_time. Keep a count of the number of 6 hour intervals, initialize it to >0. You

Re: Trying to understand nested loops

2022-08-05 Thread Dieter Maurer
ojomooluwatolami...@gmail.com wrote at 2022-8-5 08:34 +0100: >Hello, I’m new to learning python and I stumbled upon a question nested loops. For future, more complex, questions of this kind, you might have a look at the module `pdb` in Python's runtime library. It implements a debugger which

Re: Register multiple excepthooks?

2022-08-01 Thread Dieter Maurer
Albert-Jan Roskam wrote at 2022-7-31 11:39 +0200: > I have a function init_logging.log_uncaught_errors() that I use for > sys.excepthook. Now I also want to call another function (ffi.dlclose()) > upon abnormal termination. Is it possible to register multiple > excepthooks, like with

Re: Fwd: timedelta object recursion bug

2022-07-28 Thread Dieter Maurer
Please stay on the list (such that others can help, too) Ben Hirsig wrote at 2022-7-29 06:53 +1000: >Thanks for the replies, I'm just trying to understand why this would be >useful? > >E.g. why does max need a min/max/resolution, and why would these attributes >themselves need a

Re: Fwd: timedelta object recursion bug

2022-07-28 Thread Dieter Maurer
Ben Hirsig wrote at 2022-7-28 19:54 +1000: >Hi, I noticed this when using the requests library in the response.elapsed >object (type timedelta). Tested using the standard datetime library alone >with the example displayed on

Re: argparse modify

2022-06-24 Thread Dieter Maurer
נתי שטרן wrote at 2022-6-24 08:28 +0300: >I copied code from argparse library and modified it > >בתאריך יום חמישי, 23 ביוני 2022, מאת Dieter Maurer : > >> נתי שטרן wrote at 2022-6-23 15:31 +0300: >> >how to solve this (argparse) >> > >> > >&g

Re: argparse modify

2022-06-23 Thread Dieter Maurer
נתי שטרן wrote at 2022-6-23 15:31 +0300: >how to solve this (argparse) > > >traceback: >Traceback (most recent call last): > File "u:\oracle\RTR.py", line 10, in >class sre_constants(): > File "u:\oracle\RTR.py", line 77, in sre_constants >MAXREPEAT = _NamedIntConstant(32,name=str(32))

Re: Logging into single file from multiple modules in python when TimedRotatingFileHandler is used

2022-06-22 Thread Dieter Maurer
Chethan Kumar S wrote at 2022-6-21 02:04 -0700: > ... >I have a main process which makes use of different other modules. And these >modules also use other modules. I need to log all the logs into single log >file. Due to use of TimedRotatingFileHandler, my log behaves differently after

Re: traceback Shows path to my python libraries

2022-06-21 Thread Dieter Maurer
jsch...@sbcglobal.net wrote at 2022-6-20 13:49 -0500: >I coded an application with a 64-bit executable using cython with the embed >option and gcc and I received a traceback showing the path to my python >installation. Is that normal or does that mean the application is going >outside of my

Re: Issue sending data from C++ to Python

2022-05-19 Thread Dieter Maurer
Pablo Martinez Ulloa wrote at 2022-5-18 15:08 +0100: >I have been using your C++ Python API, in order to establish a bridge from >C++ to Python. Do you know `cython`? It can help very much in the implementation of bridges between Python and C/C++. --

Re: Functionality like local static in C

2022-04-14 Thread Dieter Maurer
Cecil Westerhof wrote at 2022-4-14 17:02 +0200: >In C when you declare a variable static in a function, the variable >retains its value between function calls. >The first time the function is called it has the default value (0 for >an int). >But when the function changes the value in a call (for

Re: Comparing sequences with range objects

2022-04-07 Thread Dieter Maurer
Antoon Pardon wrote at 2022-4-7 17:16 +0200: > ... >Sorry I wasn't clear. The data contains information about persons. But not >all records need to be complete. So a person can occur multiple times in >the list, while the records are all different because they are missing >different bits. > >So

[issue47246] Race condition in `threadig.Thread._wait_for_tstate_lock`

2022-04-07 Thread Dieter Maurer
Dieter Maurer added the comment: The observation was caused by a bug which has been fixed in newer Python versions (3.9+ if I remember correctly). `isAlive` was called on a `_DummyThread` (while `_DummyThread` overides `is_alive` it had forgotten to override `isAlive` as well

[issue47246] Race condition in `threadig.Thread._wait_for_tstate_lock`

2022-04-07 Thread Dieter Maurer
Dieter Maurer added the comment: Apparently, the explanation is not that easy: `_stop` first sets `_is_stopped` to `True` and only then `_tstate_lock` to `None`. Therefore, the race should not cause the `AssertionError`. I observed the `AssertionError` in Python 3.6. The related `threading

[issue47246] Race condition in `threadig.Thread._wait_for_tstate_lock`

2022-04-07 Thread Dieter Maurer
New submission from Dieter Maurer : I have observed an `AssertionError (assert self._is_stopped)` in `threading.Thread._wait_for_tstate_lock`. This indicates that Python's internal state has been corrupted. The analysis revealed the following race condition: `_wait_for_tstate:lock` contains

Re: dict.get_deep()

2022-04-03 Thread Dieter Maurer
Marco Sulla wrote at 2022-4-3 21:17 +0200: >On Sun, 3 Apr 2022 at 18:57, Dieter Maurer wrote: >> You know you can easily implement this yourself -- in your own >> `dict` subclass. > >Well, of course, but the question is if such a method is worth to be >builtin, in a w

Re: dict.get_deep()

2022-04-03 Thread Dieter Maurer
Marco Sulla wrote at 2022-4-2 22:44 +0200: >A proposal. Very often dict are used as a deeply nested carrier of >data, usually decoded from JSON. Sometimes I needed to get some of >this data, something like this: > >data["users"][0]["address"]["street"] > >What about something like this instead? >

Re: Exchange OWA using Python?

2022-03-31 Thread Dieter Maurer
Grant Edwards wrote at 2022-3-31 07:41 -0700: >Is anybody aware of any Python code for the Exchange OWA protocol/API? According to "https://en.wikipedia.org/wiki/Outlook.com#Mail_client_access; Outlook.com (the modern name for OWA) supports "pop3" and "imap", both supported by Python library

Re: Typing on child class' methods of a Generic base class

2022-03-12 Thread Dieter Maurer
Nicolas Haller wrote at 2022-3-12 12:05 -0500: >On 2022-03-10 12:31, Dieter Maurer wrote: >> Nicolas Haller wrote at 2022-3-9 10:53 -0500: >>> ... >>> The documentation about "user-defined generic types"[1] says that I can >>> fix some types

Re: How to test input via subprocess.Popen with data from file

2022-03-10 Thread Dieter Maurer
Loris Bennett wrote at 2022-3-11 07:40 +0100: > ... I want to test the parsing ... >Sorry if I was unclear but my question is: > >Given that the return value from Popen is a Popen object and given that >the return value from reading a file is a single string or maybe a list >of strings, what

Re: Typing on child class' methods of a Generic base class

2022-03-10 Thread Dieter Maurer
Nicolas Haller wrote at 2022-3-9 10:53 -0500: > ... >The documentation about "user-defined generic types"[1] says that I can >fix some types on a child class (class MyDict(Mapping[str, T]):) but >doesn't say much about the signature of the methods I need to >implement/override on that child class.

Re: How to test input via subprocess.Popen with data from file

2022-03-10 Thread Dieter Maurer
Loris Bennett wrote at 2022-3-10 13:16 +0100: >I have a command which produces output like the >following: > > Job ID: 9431211 > Cluster: curta > User/Group: build/staff > State: COMPLETED (exit code 0) > Nodes: 1 > Cores per node: 8 > CPU Utilized: 01:30:53 > CPU Efficiency: 83.63% of

Re: Execute in a multiprocessing child dynamic code loaded by the parent process

2022-03-07 Thread Dieter Maurer
Martin Di Paola wrote at 2022-3-6 20:42 +: >>Try to use `fork` as "start method" (instead of "spawn"). > >Yes but no. Indeed with `fork` there is no need to pickle anything. In >particular the child process will be a copy of the parent so it will >have all the modules loaded, including the

Re: Execute in a multiprocessing child dynamic code loaded by the parent process

2022-03-06 Thread Dieter Maurer
Martin Di Paola wrote at 2022-3-6 12:42 +: >Hi everyone. I implemented time ago a small plugin engine to load code >dynamically. > >So far it worked well but a few days ago an user told me that he wasn't >able to run in parallel a piece of code in MacOS. > >He was using multiprocessing.Process

Re: Behavior of the for-else construct

2022-03-04 Thread Dieter Maurer
Avi Gross wrote at 2022-3-4 16:43 +: >Your use is creative albeit it is not "needed" since all it does is make sure >your variable is initialized to something, specifically None. > >So would this not do the same thing? > > eye = None > > for eye in range(0): > print(eye) > > eye It

Re: Behavior of the for-else construct

2022-03-03 Thread Dieter Maurer
Rob Cliffe wrote at 2022-3-4 00:13 +: >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 else unfortunate enough to read my >code) what triggers it, e.g. > >    

Re: Behavior of the for-else construct

2022-03-03 Thread Dieter Maurer
computermaster360 wrote at 2022-3-3 14:24 +0100: >Do you find the for-else construct useful? Yes. >Have you used it in practice? Yes -- https://mail.python.org/mailman/listinfo/python-list

Re: lxml empty versus self closed tag

2022-03-03 Thread Dieter Maurer
Robin Becker wrote at 2022-3-3 09:21 +: >On 02/03/2022 18:39, Dieter Maurer wrote: >> Robin Becker wrote at 2022-3-2 15:32 +: >>> I'm using lxml.etree.XMLParser and would like to distinguish >>> >>> >>> >>> from >>> >>&g

Re: lxml empty versus self closed tag

2022-03-02 Thread Dieter Maurer
Robin Becker wrote at 2022-3-2 15:32 +: >I'm using lxml.etree.XMLParser and would like to distinguish > > > >from > > > >I seem to have e.getchildren()==[] and e.text==None for both cases. Is there a >way to get the first to have e.text=='' I do not think so (at least not without a DTD): `'

Re: Why does not Python accept functions with no names?

2022-02-20 Thread Dieter Maurer
Abdur-Rahmaan Janhangeer wrote at 2022-2-20 19:32 +0400: >Out of curiosity, why doesn't Python accept >def (): >return '---' > >() > >Where the function name is ''? Python knows about (somewhat restricted) anonymous functions: it calls them `lambda` expressions (the body of those functions

Re: Correct way to setup a package with both compiled C code and Python code?

2022-02-09 Thread Dieter Maurer
Christian Gollwitzer wrote at 2022-2-8 22:43 +0100: >Am 08.02.22 um 18:57 schrieb Dieter Maurer: >> Christian Gollwitzer wrote at 2022-2-7 20:33 +0100: >>> we've developed a Python pacakge which consists of both a compiled >>> extension module and some

Re: Correct way to setup a package with both compiled C code and Python code?

2022-02-08 Thread Dieter Maurer
Christian Gollwitzer wrote at 2022-2-7 20:33 +0100: >we've developed a Python pacakge which consists of both a compiled >extension module and some helper functions in Python. Is there a >tutorial on how to package such an extension? Look at "https://package.python.org;, especially

Re: ssl server: how to disable client cert verfication?

2022-02-04 Thread Dieter Maurer
Grant Edwards wrote at 2022-2-3 14:36 -0800: >On 2022-02-03, Barry wrote: > ... >I've looked through the ssl.Context documentation multiple times, and >haven't been able to spot any option or flag that disables client >certificate validation or allows the user to override the actual >client

Re: PYTHONPATH vs Python Virtual Environment

2022-02-04 Thread Dieter Maurer
Sina Mobasheri wrote at 2022-2-4 15:55 +: >it's not good title defiantly and I don't mean to compare apples and oranges > >when I start using python virtual environment it was because isolation >proposes and everyone say about its benefits in isolation and working with >different versions of

Re: http.client and dns lookups

2022-02-02 Thread Dieter Maurer
Michael Welle wrote at 2022-2-1 19:28 +0100: > ... >That doesn't happen when the 'real' issue occurs. Attaching strace to >the Python process I can see that resolv.conf is stat'ed and open'ed. I >guess now I'm more confused than before ;). There must be an additional >condition that I'm missing.

Re: http.client and dns lookups

2022-01-31 Thread Dieter Maurer
Michael Welle wrote at 2022-1-30 09:18 +0100: > ... The machine this is running on regularly switches >its network configuration without restarting the Python application. Now >it turns out that the application is still using an old, outdated dns >server after such a network configuration switch.

Re: "undefined symbol" in C extension module

2022-01-23 Thread Dieter Maurer
Robert Latest wrote at 2022-1-22 11:29 GMT: >I've written some CPython extension modules in the past without problems. Now >after moving to a new Archlinux box with Python3.10 installed, I can't build >them any more. Or rather, I can build them but not use them due to "undefined >symbols" during

Re: preserving entities with lxml

2022-01-13 Thread Dieter Maurer
Robin Becker wrote at 2022-1-13 09:13 +: >On 12/01/2022 20:49, Dieter Maurer wrote: > ... >> Apparently, the `resolve_entities=False` was not effective: otherwise, >> your tree content should have more structure (especially some >> entity reference children). >&g

Re: preserving entities with lxml

2022-01-12 Thread Dieter Maurer
Robin Becker wrote at 2022-1-12 10:22 +: >I have a puzzle over how lxml & entities should be 'preserved' code below >illustrates. To preserve I change & --> >in the source and add resolve_entities=False to the parser definition. The >escaping means we only have one kind of >entity which

Re: Script profiling details

2022-01-11 Thread Dieter Maurer
Joseph L. Casale wrote at 2022-1-10 18:43 +: > ... >I expected this given the implementation, but I was hoping to get some >finer details so I can track down the specific module or at least the specific >file so I have a place to start reviewing code for optimizations. > >Is there something I

Re: What's the public API alternative to _PyObject_GC_IS_TRACKED()?

2021-12-29 Thread Dieter Maurer
Marco Sulla wrote at 2021-12-29 11:59 +0100: >On Wed, 29 Dec 2021 at 09:12, Dieter Maurer wrote: >> `MutableMapping` is a so called abstract base class (--> `abc`). >> >> It uses the `__subclass_check__` (and `__instance_check__`) of >> `abc.ABCMeta` to ensure `i

Re: What's the public API alternative to _PyObject_GC_IS_TRACKED()?

2021-12-29 Thread Dieter Maurer
Marco Sulla wrote at 2021-12-29 09:29 +0100: >On second thought, I think I'll do this for the pure py version. But I >will definitely not do this for the C extension Are you sure you need to implement your type in C at all? I made a small `timeit` test: ``` >>> class cd(dict): pass ... >>>

  1   2   3   4   >