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

2024-03-24 Thread Frank Millman via Python-list
On 2024-03-23 3:25 PM, Frank Millman via Python-list wrote: It is not pretty! call_soon_threadsafe() is a loop function, but the loop is not accessible from a different thread. Therefore I include a reference to the loop in the message passed to in_queue, which in turn passes it to

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

2024-03-23 Thread Frank Millman via Python-list
's ideas, here is a version that works. It is not pretty! call_soon_threadsafe() is a loop function, but the loop is not accessible from a different thread. Therefore I include a reference to the loop in the message passed to in_queue, which in turn passes it to out_queue. Frank ==

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

2024-03-22 Thread Frank Millman via Python-list
On 2024-03-22 1:23 PM, Frank Millman via Python-list wrote: On 2024-03-22 12:09 PM, Frank Millman via Python-list wrote: I am no expert. However, I do have something similar in my app, and it works. I do not use 'await future', I use 'asyncio.wait_for(future)'. I test

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

2024-03-22 Thread Frank Millman via Python-list
On 2024-03-22 12:09 PM, Frank Millman via Python-list wrote: I am no expert. However, I do have something similar in my app, and it works. I do not use 'await future', I use 'asyncio.wait_for(future)'. I tested it and it did not work. I am not sure, but I think the

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

2024-03-22 Thread Frank Millman via Python-list
PT_DYNAMIC Debian 6.1.76-1 (2024-02-01) x86_64 GNU/Linux $ python3 -V Python 3.11.2 $ pip3 freeze asgiref==3.7.2 blinker==1.7.0 click==8.1.7 Flask==3.0.2 itsdangerous==2.1.2 Jinja2==3.1.3 MarkupSafe==2.1.5 Werkzeug==3.0.1 ``` Thanks for any help! Cheers, Thomas Hi Thomas I am no exper

Re: Question about garbage collection

2024-01-16 Thread Frank Millman via Python-list
On 2024-01-17 3:01 AM, Greg Ewing via Python-list wrote: On 17/01/24 1:01 am, Frank Millman wrote: I sometimes need to keep a reference from a transient object to a more permanent structure in my app. To save myself the extra step of removing all these references when the transient object is

Re: Question about garbage collection

2024-01-16 Thread Frank Millman via Python-list
ings. I will start with a fresh approach tomorrow. If you don't hear from me again, you will know that I have solved it! Thanks for the input, it definitely helped. Frank -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about garbage collection

2024-01-16 Thread Frank Millman via Python-list
On 2024-01-15 3:51 PM, Frank Millman via Python-list wrote: Hi all I have read that one should not have to worry about garbage collection in modern versions of Python - it 'just works'. I don't want to rely on that. My app is a long-running server, with multiple clients lo

Question about garbage collection

2024-01-15 Thread Frank Millman via Python-list
ry simple program to illustrate this. Am I missing something? All comments appreciated. Frank Millman == import gc class delwatcher:     # This stores enough information to identify the object being watched.     # It does not store a reference

Type hints - am I doing it right?

2023-12-12 Thread Frank Millman via Python-list
'DbParams']). But I would still like an answer to the original question, as I am sure similar situations will occur without such a simple solution. Thanks Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: Simple webserver

2023-10-25 Thread Frank Millman via Python-list
github.com/FrankMillman/AccInABox. You are welcome to look at it, but it needs a lot of tidying up before it will be ready for a wider audience. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

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

2023-03-05 Thread Frank B
run from interpreter directly: f = open("abc", "w") for i in range(5):   f.write(str(i) + "\n") use with open("abc", "w") as f: for i in range(5): f.write(str(i) + "\n") and all is well Frank -- https://mail.python.org/mailman/listinfo/python-list

Re: Changing the original SQLite version to the latest

2023-02-14 Thread Frank Millman
On 2023-02-15 5:59 AM, Thomas Passin wrote: > > "Download the latest release from http://www.sqlite.org/download.html > and manually copy sqlite3.dll into Python's DLLs subfolder." > I have done exactly this a number of times and it has worked for me. Frank Millman

Re: asyncio questions

2023-01-27 Thread Frank Millman
On 2023-01-27 2:14 PM, Frank Millman wrote: I have changed it to async, which I call with 'asyncio.run'. It now looks like this -     server = await asyncio.start_server(handle_client, host, port)     await setup_companies()     session_check = asyncio.create_task(     chec

Re: asyncio questions

2023-01-27 Thread Frank Millman
On 2023-01-26 7:16 PM, Dieter Maurer wrote: 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 de

asyncio questions

2023-01-26 Thread Frank Millman
nner I have not figured out how to adapt my code to use this new approach. Any suggestions appreciated. Frank Millman P.S. Might it be better to ask these questions on the Async_SIG Discussion Forum? -- https://mail.python.org/mailman/listinfo/python-list

Re: To clarify how Python handles two equal objects

2023-01-14 Thread Frank Millman
largely independently of the names that are or are not referencing the objects. My 'aha' moment came when I understood that a python object has only three properties - a type, an id, and a value. It does *not* have a name. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: Trying to understand nested loops

2022-08-05 Thread Frank Millman
not, feel free to come back with more questions. BTW, there is an indentation error in your original post - line 5 should line up with line 4. It is preferable to copy/paste your code into any messages posted here rather than type it in, as that avoids the possibility of any typos. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: list indices must be integers or slices, not str

2022-07-21 Thread Frank Millman
://github.com/python/cpython/issues/95088 Frank -- https://mail.python.org/mailman/listinfo/python-list

Re: list indices must be integers or slices, not str

2022-07-20 Thread Frank Millman
On 2022-07-20 12:31 PM, Frank Millman wrote: On 2022-07-20 11:37 AM, Chris Angelico wrote: On Wed, 20 Jul 2022 at 18:34, Frank Millman wrote: Hi all C:\Users\E7280>python Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32 Type "help"

Re: list indices must be integers or slices, not str

2022-07-20 Thread Frank Millman
On 2022-07-20 11:37 AM, Chris Angelico wrote: On Wed, 20 Jul 2022 at 18:34, Frank Millman wrote: Hi all C:\Users\E7280>python Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits"

list indices must be integers or slices, not str

2022-07-20 Thread Frank Millman
> >>> '{x[1]}'.format(**vars()) '1' >>> >>> '{x[-1]}'.format(**vars()) Traceback (most recent call last):   File "", line 1, in TypeError: list indices must be integers or slices, not str >>> Can anyone explain this

Re: One-liner to merge lists?

2022-02-22 Thread Frank Millman
7;] Now that's what I was looking for. I am not saying that I will use it, but as an academic exercise I felt sure that there had to be a one-liner in pure python. I had forgotten about nested comprehensions. Thanks for the reminder. Frank -- https://mail.python.org/mailman/listinfo/python-list

Re: One-liner to merge lists?

2022-02-22 Thread Frank Millman
On 2022-02-22 11:30 AM, Chris Angelico wrote: On Tue, 22 Feb 2022 at 20:24, Frank Millman wrote: Hi all I think this should be a simple one-liner, but I cannot figure it out. I have a dictionary with a number of keys, where each value is a single list - >>> d = {1: ['aaa

One-liner to merge lists?

2022-02-22 Thread Frank Millman
7;, 'fff', 'ggg'] I can also do this - >>> from itertools import chain >>> a = list(chain(*d.values())) >>> a ['aaa', 'bbb', 'ccc', 'fff', 'ggg'] >>> Is there a simpler way? Thanks Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

A bit of nostalgia

2022-01-30 Thread Frank Millman
ing in assembler. I recall my boss telling me that the ICL assembler was called PLAN, which was an acronym, but I forget what it stood for. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: Negative subscripts

2021-11-26 Thread Frank Millman
On 2021-11-26 11:24 PM, dn via Python-list wrote: On 26/11/2021 22.17, Frank Millman wrote: 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 the entire list 'x', but of course -0 equ

Re: Negative subscripts

2021-11-26 Thread Frank Millman
On 2021-11-26 11:17 AM, 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 the entire list 'x', but of course -0 equals 0, so it returns an empt

Negative subscripts

2021-11-26 Thread Frank Millman
item in x[:-y] if y else x: ...    [do stuff] But in my actual program, both x and y are fairly long expressions, so the result is pretty ugly. Are there any other techniques anyone can suggest, or is the only alternative to use if...then...else to cater for y = 0? Thanks Frank Millman -- ht

Re: Fun Generators

2021-04-22 Thread Frank Millman
y *fun* generators people may have seen or written? Not so much the cool or clever ones. Or the mathematical ones (e.g. fib). Something more inane and "fun". But still showcasing generators uniqueness. Short and simple is good. Thanks in advance! Have you looked at this? http://www.da

Re: Yield after the return in Python function.

2021-04-05 Thread Frank Millman
#x27;Calling' a generator function does not execute the function, it returns a generator object. You have to iterate over the generator object (e.g. by calling next() on it) in order to execute the function and return values. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about generators

2021-03-05 Thread Frank Millman
On 2021-03-06 8:21 AM, Frank Millman wrote: Hi all This is purely academic, but I would like to understand the following - >>> >>> a = [('x', 'y')] >>> >>> s = [] >>> for b, c in a: ...   s.append((b, c)) ... >>>

Question about generators

2021-03-05 Thread Frank Millman
I expected. >>> >>> s = [] >>> s.append(((b, c) for b, c in a)) >>> s [ at 0x019FC3F863C0>] >>> I expected the same as the first one. I understand the concept that a generator does not return a value until you call next() on it, but I have

Re: name for a mutually inclusive relationship

2021-02-24 Thread Frank Millman
I use for this arrangement is 'sub-types'. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

etree, gzip, and BytesIO

2021-01-20 Thread Frank Millman
ee.parse(gf) to convert to an etree object It works. But I don't know what goes on under the hood, so I don't know if this achieves anything. If any of the steps involves decompressing the data and storing the entire string in memory, I may as well stick to my present approach. Any

Re: strip() method makes me confused

2020-11-07 Thread Frank Millman
On 2020-11-07 1:28 PM, Frank Millman wrote: On 2020-11-07 1:03 PM, Bischoop wrote: [...] another example: text = "this is text, there should be not commas, but as you see there are still" y = txt.strip(",") print(text) output: this is text, there should be not commas,

Re: strip() method makes me confused

2020-11-07 Thread Frank Millman
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string HTH Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: Is there a conflict of libraries here?

2020-11-05 Thread Frank Millman
move the line 'from datetime import datetime'. 2. Change dt = datetime.fromisoformat(ItemDateTime) to dt = datetime.datetime.fromisoformat(ItemDateTime) Unless I have missed something, that should work. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

asyncio question

2020-11-03 Thread Frank Millman
x27; method, KeyboardInterrupt is not caught by 'server.serve_forever()' but by 'asyncio.run()'. It is too late to do any cleanup at this point, as the loop has already been stopped. Is it ok to stick to the 'old' method, or is there a better way to do this. Thanks Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: Basic Python help

2020-10-23 Thread Frank Millman
ng. So the result is the concatenation of - 1. '\n' + '#' + length of string + '\n' as the start delimiter 2. the string itself 3. '\n' + '#' + '#' + '\n' as the end delimiter Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Frank Millman
On 2020-10-16 9:42 AM, Steve wrote: d2 = datetime.datetime.now() #Time Right now Show this: 2020-10-16 02:53 and not this: 2020-10-16 02:53:48.585865 >>> >>> str(d2) '2020-10-16 10:29:38.423371' >>> >>> d2.strftime('%Y-%m-%d %H:%M

Re: Debugging technique

2020-10-03 Thread Frank Millman
On 2020-10-03 8:58 AM, Chris Angelico wrote: On Sat, Oct 3, 2020 at 4:53 PM Frank Millman wrote: Hi all When debugging, I sometimes add a 'breakpoint()' to my code to examine various objects. However, I often want to know how I got there, so I replace the 'breakpoint()&#x

Debugging technique

2020-10-02 Thread Frank Millman
using the extra info from the traceback. Is there a way to combine these into one step, so that, while in the debugger, I can find out how I got there? Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: list comprehension namespace problem

2020-09-24 Thread Frank Millman
On 2020-09-25 7:46 AM, Chris Angelico wrote: On Fri, Sep 25, 2020 at 3:43 PM Frank Millman wrote: Hi all I have a problem related (I think) to list comprehension namespaces. I don't understand it enough to figure out a solution. In the debugger, I want to examine the contents of the cu

list comprehension namespace problem

2020-09-24 Thread Frank Millman
ing on? Q2. Is there a way to get what I want? Thanks Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: Pythonic style

2020-09-21 Thread Frank Millman
I made the mistake of relying on the error message in my logic, to distinguish between 'too few' and 'too many'. Guess what happened - Python changed the wording of the messages, and my logic failed. After messing about with some alternatives, I ended up with the OP's f

wxpython-OGL fails to render objects with Python-3

2020-09-17 Thread Frank Miles
I have a substantial wxpython-based application that I'm trying to port from python-2 to -3. Almost everything is working properly, except for a few small but important sections that use the OGL library. That executes without any exceptions, but the objects created within the diagram/canvas

Re: Need tests of turtledemo.colordemo on Windows installations

2020-09-13 Thread Frank Millman
On 2020-09-14 7:07 AM, Frank Millman wrote: On 2020-09-14 3:18 AM, Terry Reedy wrote: User Tushar Sadhwani and I both have Win 10 with 3.8.5 installed. When he runs ...> py -3.8 -m turtledemo.colormixer and moves the sliders a reasonable amount, he repeatably gets Fatal Python error: Can

Re: Need tests of turtledemo.colordemo on Windows installations

2020-09-13 Thread Frank Millman
est with no issues at all. I will upgrade to 3.8.5 later today and try again. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Access last element after iteration

2020-07-07 Thread Frank Millman
using the last element, I assume that this would be the way to do it - >>> for i in range(5): ... print(i) ... j = i ... 0 1 2 3 4 >>> print(j) 4 >>> Alternatively, this also works, but is this one guaranteed? >>> for i in range(5): ... print(i) .

Re: Bulletproof json.dump?

2020-07-06 Thread Frank Millman
On 2020-07-06 3:08 PM, Jon Ribbens via Python-list wrote: On 2020-07-06, Frank Millman wrote: On 2020-07-06 2:06 PM, Jon Ribbens via Python-list wrote: While I agree entirely with your point, there is however perhaps room for a bit more helpfulness from the json module. There is no sensible

Re: Bulletproof json.dump?

2020-07-06 Thread Frank Millman
'datetime.date(2020, 7, 6)'. I look for that pattern on retrieval to detect that it is actually a date object. I use the same trick for Decimal objects. Maybe the OP could do something similar. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: [Beginner] Spliting input

2020-06-25 Thread Frank Millman
input("enter 1st and 2nd no ").split() ValueError: not enough values to unpack (expected 2, got 1) Without arguments, split() splits on whitespace. If you entered 2 numbers separated by a comma, but no spaces, there is no split. Maybe you meant split(',') whi

Re: Strings: double versus single quotes

2020-05-24 Thread Frank Millman
On 2020-05-24 9:58 AM, DL Neil via Python-list wrote: On 24/05/20 5:43 PM, Frank Millman wrote: On 2020-05-23 9:45 PM, DL Neil via Python-list wrote: My habit with SQL queries is to separate them from other code, cf the usual illustration of having them 'buried' within the code, i

Re: Strings: double versus single quotes

2020-05-23 Thread Frank Millman
dding more and more SQL in my code. How do you handle parameters? Do you leave placeholders ('?' or '%s') in the query, and leave it to the 'importer' of the query to figure out what is required? Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: "pip" error message

2020-04-21 Thread Frank Millman
re discussing how to improve the download experience on Windows for newbies. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Python version and Apache mod_python mismatching version

2020-04-03 Thread frank . scarpa
Hello, I have a Centos7 web server with python 2.7 installed and I want Apache to serve python scripts so I figure I have to install mod_python: i know that this module is deprecated, but I need it only for internal pourposes. Is the mod_python version (which is 3.5 with Python 3 support) someho

Re: Intermittent bug with asyncio and MS Edge

2020-03-24 Thread Frank Millman
On 2020-03-24 8:39 PM, Barry Scott wrote: On 24 Mar 2020, at 11:54, Frank Millman wrote: I decided to concentrate on using Wireshark to detect the difference between a Python3.7 session and a Python3.8 session. Already I can see some differences. There is only one version of my program

Re: Intermittent bug with asyncio and MS Edge

2020-03-24 Thread Frank Millman
On 2020-03-24 1:54 PM, Frank Millman wrote: On 2020-03-23 1:56 PM, Frank Millman wrote: I have one frustration with Wireshark. I will mention it in case anyone has a solution. I can see that Edge opens multiple connections. I am trying to track the activity on each connection separately. I

Re: Intermittent bug with asyncio and MS Edge

2020-03-24 Thread Frank Millman
On 2020-03-23 1:56 PM, Frank Millman wrote: On 2020-03-23 12:57 PM, Chris Angelico wrote: On Mon, Mar 23, 2020 at 8:03 PM Frank Millman wrote: On 2020-03-22 12:11 PM, Chris Angelico wrote: On Sun, Mar 22, 2020 at 8:30 PM Frank Millman wrote: On 2020-03-22 10:45 AM, Chris Angelico wrote

Re: Intermittent bug with asyncio and MS Edge

2020-03-23 Thread Frank Millman
On 2020-03-23 12:57 PM, Chris Angelico wrote: On Mon, Mar 23, 2020 at 8:03 PM Frank Millman wrote: On 2020-03-22 12:11 PM, Chris Angelico wrote: On Sun, Mar 22, 2020 at 8:30 PM Frank Millman wrote: On 2020-03-22 10:45 AM, Chris Angelico wrote: If you can recreate the problem with a

Re: Intermittent bug with asyncio and MS Edge

2020-03-23 Thread Frank Millman
On 2020-03-22 12:11 PM, Chris Angelico wrote: On Sun, Mar 22, 2020 at 8:30 PM Frank Millman wrote: On 2020-03-22 10:45 AM, Chris Angelico wrote: If you can recreate the problem with a single socket and multiple requests, that would be extremely helpful. I also think it's highly likely

Re: Intermittent bug with asyncio and MS Edge

2020-03-22 Thread Frank Millman
On 2020-03-22 1:01 PM, Chris Angelico wrote: On Sun, Mar 22, 2020 at 12:45 AM Frank Millman wrote: Hi all I have a strange intermittent bug. The role-players - asyncio on Python 3.8 running on Windows 10 Microsoft Edge running as a browser on the same machine The bug does not

Re: Intermittent bug with asyncio and MS Edge

2020-03-22 Thread Frank Millman
On 2020-03-22 11:00 AM, Barry Scott wrote: On 22 Mar 2020, at 07:56, Frank Millman wrote: On 2020-03-21 8:04 PM, Barry Scott wrote: I'd look at the network traffic with wireshark to see if there is anything different between edge and the other browsers. You are leading me into

Re: Intermittent bug with asyncio and MS Edge

2020-03-22 Thread Frank Millman
On 2020-03-22 10:45 AM, Chris Angelico wrote: On Sun, Mar 22, 2020 at 6:58 PM Frank Millman wrote: I'd look at the network traffic with wireshark to see if there is anything different between edge and the other browsers. You are leading me into deep waters here :-) I have never

Re: Intermittent bug with asyncio and MS Edge

2020-03-22 Thread Frank Millman
On 2020-03-21 8:04 PM, Barry Scott wrote: On 21 Mar 2020, at 13:43, Frank Millman wrote: Hi all I have a strange intermittent bug. The role-players - asyncio on Python 3.8 running on Windows 10 Microsoft Edge running as a browser on the same machine The bug does not occur with

Intermittent bug with asyncio and MS Edge

2020-03-21 Thread Frank Millman
() writer.close() await writer.wait_closed() I have asked the same question on StackOverflow, from an MS Edge perspective - https://stackoverflow.com/questions/60785767/ms-edge-randomly-does-not-load-script I don't know whether the problem lies with Python or MS Edge, but a

Groovy to Python Converter ?

2020-02-29 Thread Frank Rentmeister
In my new project, I am supposed to bring the current test cases, all written in Groovy, to a Python base. We are talking about several thousand test cases that have accumulated over the last years. Since the test cases are also to be extended towards API gateway testing, and since we work with

Re: Asyncio question (rmlibre)

2020-02-28 Thread Frank Millman
ime efficient at handling large numbers of > concurrent async tasks. > Thanks for the reply. That is exactly what I want, and in an earlier response Greg echoes what what you say here - background tasks are lightweight and are ideal for my situation. Frank -- https://mail.python.org/mailman/listinfo/python-list

Re: python

2020-02-22 Thread Frank Millman
IN, or is ignored as neither. Now -- write a program does just that... """ Try his suggestion, and come back here if you get stuck. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Why is passing loop argument to asyncio.Event deprecated?

2020-02-22 Thread Frank Millman
Hi all Why is 'explicit passing of a loop argument to asyncio.Event' deprecated (see What's new in Python 3.8)? I use this in my project. I can find a workaround, but it is not elegant. I can explain my use case if requested, but I was just curious to find out the reason.

Re: Asyncio question

2020-02-21 Thread Frank Millman
On 2020-02-21 11:13 PM, Greg Ewing wrote: On 21/02/20 7:59 pm, Frank Millman wrote: My first attempt was to create a background task for each session which runs for the life-time of the session, and 'awaits' its queue. It works, but I was concerned about having a lot a background tas

Asyncio question

2020-02-20 Thread Frank Millman
he session is closed. Is this better, worse, or does it make no difference? If it makes no difference, I will lean towards the first approach, as it is easier to reason about what is going on. Thanks for any advice. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: Change in behaviour Python 3.7 > 3.8

2020-02-07 Thread Frank Millman
On 2020-02-07 1:06 PM, Barry Scott wrote: On 7 Feb 2020, at 05:27, Frank Millman wrote: @Barry I agree that __del__() is rarely useful, but I have not come up with an alternative to achieve what I want to do. My app is a long-running server, and creates many objects on-the-fly depending

Re: Change in behaviour Python 3.7 > 3.8

2020-02-06 Thread Frank Millman
On 2020-02-06 2:58 PM, Frank Millman wrote: [...] I have a module (A) containing common objects shared by other modules. I have a module (B) which imports one of these common objects - a set(). [...] This has worked for years, but now when the __del__ method is called, the common object

Change in behaviour Python 3.7 > 3.8

2020-02-06 Thread Frank Millman
. I have a workaround, so I am just reporting this for the record. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: lxml - minor problem appending new element

2020-02-03 Thread Frank Millman
On 2020-02-03 10:39 AM, Peter Otten wrote: Frank Millman wrote: This is a minor issue, and I have found an ugly workaround, but I thought I would mention it. Like this? children = list(xml) for y in children: print(etree.tostring(y)) if y.get('z') == 'c&#

lxml - minor problem appending new element

2020-02-02 Thread Frank Millman
', 'b', 'c', 'd'] >>> >>> lmx = '' >>> xml = etree.fromstring(lmx) >>> for y in xml: ... print(etree.tostring(y)) ... if y.get('z') == 'c': ... xml.append(etree.Element('y', attrib={'z': 'd'})) ... b'' b'' b'' >>> etree.tostring(xml) b'' As you can see, the last element is correctly appended, but is not included in the iteration. Is there any chance that this can be looked at, or is it just the way it works? BTW, I see that ElementTree in the standard library does not have this problem. Thanks Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: Print statement

2020-01-28 Thread Frank Millman
can't multiply sequence by non-int of type 'float' >>> You probably meant float(squares) * float(.15) or more simply float(squares) * .15 HTH Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: Fun with IO

2020-01-21 Thread Frank Millman
On 2020-01-21 6:17 PM, Maxime S wrote: Hi, Le ven. 17 janv. 2020 à 20:11, Frank Millman a écrit : It works perfectly. However, some pdf's can be large, and there could be concurrent requests, so I wanted to minimise the memory footprint. So I tried passing the client_writer directly t

Re: Sandboxing eval()

2020-01-21 Thread Frank Millman
quite difficult" I realised that my method is vulnerable to this and, like Robin, I have not come up with an easy way to guard against it. Frank Millman Just use floats instead of integers. I like that idea. I will probably use Decimal instead of float, but the principle is the sa

Re: Sandboxing eval()

2020-01-20 Thread Frank
seems quite difficult" I realised that my method is vulnerable to this and, like Robin, I have not come up with an easy way to guard against it. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Fun with IO

2020-01-17 Thread Frank Millman
wait pdf_handler(client_writer) client_writer.write(b'\r\n') It works! ReportLab accepts client_writer as a file-like object, and writes to it directly. I cannot use chunking, so I just let it do its thing. Can anyone see any problem with this? Thanks Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: name 'sys' is not defined

2019-12-29 Thread Frank Millman
o add this line - import sys HTH Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: Lists And Missing Commas

2019-12-23 Thread Frank Millman
mon. More likely is the use of a newline. I use this from time to time when constructing long string literals - long_string = ( "this is the first chunk " "this is the second chunk " "etc etc" ) My 0.02c Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: datetime gotcha

2019-12-12 Thread Frank Millman
found a workaround. >>> from datetime import date as dt, datetime as dtm >>> type(dtm.now()) is dtm True >>> type(dtm.now()) is dt False >>> I will run with this. Frank -- https://mail.python.org/mailman/listinfo/python-list

datetime gotcha

2019-12-10 Thread Frank Millman
object." If it was using multiple inheritance, a dtm should also be an instance of tm, but it is not. This is using Python 3.7.2. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: Instantiating sub-class from super

2019-10-24 Thread Frank Millman
On 2019-10-19 12:37 AM, DL Neil via Python-list wrote: On 16/10/19 6:33 PM, Frank Millman wrote: On 2019-10-14 10:55 PM, DL Neil via Python-list wrote: Is there a technique or pattern for taking a (partially-) populated instance of a class, and re-creating it as an instance of one of its sub

Re: Instantiating sub-class from super

2019-10-16 Thread Frank Millman
On 2019-10-16 7:33 AM, Frank Millman wrote: Here is a link to an article entitled 'Understanding Hidden Subtypes'. It dates back to 2004, but I think it is still relevant. It addresses precisely the issues that you raise, but from a data-modelling perspective, not a programming o

Re: Instantiating sub-class from super

2019-10-15 Thread Frank Millman
ure 2) showing the data relationships. I downloaded the original article onto my computer years ago, and my local copy does have the images, so if you would like to see them let me know and I will upload my version somewhere to make it accessible. Frank Millman -- https://mail.python.org/m

Re: sqlalchemy & #temp tables

2019-10-07 Thread Frank Millman
you have a large volume of temp data, but it may be worth trying. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Python in The Economist

2019-09-24 Thread Frank Millman
ng machines. That approach has attracted interest from DARPA ..." Hope this is of interest. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: phyton

2019-09-10 Thread Frank Millman
>>> my_dict = dict() >>> my_dict {} >>> my_dict = {} # this does the same, but is shorter >>> my_dict {} >>> my_dict['high'] = 21 >>> my_dict {'high': 21} >>> Try that, and report back with any questions Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: ``if var'' and ``if var is not None''

2019-08-31 Thread Frank Millman
On 2019-09-01 8:12 AM, Hongyi Zhao wrote: Hi, The following two forms are always equivalent: ``if var'' and ``if var is not None'' Regards Not so. Here is an example - >>> var = [] >>> bool(var) False >>> bool(var is not None) True >>

Re: Compare zip lists where order is important

2019-08-28 Thread Frank Millman
x27;, 2)] What's a working way to go about this? This would have worked if you sorted your lists first - >>> [i for i, j in zip(sorted(teams), sorted(shuffle_teams)) if i != j] [('Ally', 2), ('Fredricka', 3), ('Tim', 1)] Except you wanted to see the re

Re: How should we use global variables correctly?

2019-08-23 Thread Frank Millman
27;, whereas with a global 'foo' there can only be one value of 'foo' for the module. It would make sense to use the 'global' keyword if you have a module with various functions, several of which refer to 'foo', but only one of which changes the value of 'foo'. Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: Enumerate - int object not subscriptable

2019-08-20 Thread Frank Millman
): print(num[idx + 1], num) I am expecting 2, 1. But am receiving TypeError: 'int' object is not subscriptable Why? I think you want a[idx+1], not num[idx+1]. Bear in mind that you will get IndexError for the last item in the list. Frank Millman -- https://mail.python.org/mailma

Re: Accumulate , Range and Zeros

2019-07-13 Thread Frank Millman
default, range() starts from 0. Anything multiplied by 0 equals 0. So you can multiply as many numbers as you like, if the first one is 0, the rest will also be 0. QED Frank Millman -- https://mail.python.org/mailman/listinfo/python-list

Re: How Do You Replace Variables With Their Values?

2019-07-10 Thread Frank Millman
eparate lists called 'Starters', 'Main Course', and 'Desert'?", the code that you started with is exactly what you asked for. I think you were asking how to create a variable called 'Starters' containing the list of starters. It can be done, using th

Re: pyodbc -> MS-SQL Server Named Instance ?

2019-07-02 Thread Frank Millman
On 2019-07-02 3:41 PM, Adam Tauno Williams wrote: On Tue, 2019-07-02 at 07:36 +0200, Frank Millman wrote: On 2019-07-01 10:13 PM, Adam Tauno Williams wrote: I am trying to connect to a Named Instance on an MS-SQL server using pyODBC. This is what I use -  conn = pyodbc.connect

  1   2   3   4   5   6   7   8   9   10   >