Re: UTF_16 question

2024-05-01 Thread jak via Python-list
Richard Damon ha scritto: On Apr 29, 2024, at 12:23 PM, jak via Python-list wrote: Hi everyone, one thing that I do not understand is happening to me: I have some text files with different characteristics, among these there are that they have an UTF_32_le coding, utf_32be, utf_16_le, utf_16_b

Re: UTF_16 question

2024-04-29 Thread Richard Damon via Python-list
> On Apr 29, 2024, at 12:23 PM, jak via Python-list > wrote: > > Hi everyone, > one thing that I do not understand is happening to me: I have some text > files with different characteristics, among these there are that they > have an UTF_32_le coding, utf_32be, utf_16_le, utf_16_be all of them

Re: UTF_16 question

2024-04-29 Thread jak via Python-list
Stefan Ram ha scritto: jak wrote or quoted: I read it, both with encoding='utf_16_be' and with 'utf_16_le' without errors but in the last case the bytes are inverted. I think the order of the octets (bytes) is exactly the difference between these two encodings,

UTF_16 question

2024-04-29 Thread jak via Python-list
Hi everyone, one thing that I do not understand is happening to me: I have some text files with different characteristics, among these there are that they have an UTF_32_le coding, utf_32be, utf_16_le, utf_16_be all of them without BOM. With those utf_32_xx I have no problem but with the UTF_16_xx

Re: A question about import

2024-02-16 Thread Cameron Simpson via Python-list
On 16Feb2024 20:32, MRAB wrote: On 2024-02-16 20:07, Gabor Urban via Python-list wrote: I need something about modules to be clarified. Suppose I have written a module eg: ModuleA which imports an other module, let us say the datetime. If I import ModuleA in a script, will be datetime importe

Re: A question about import

2024-02-16 Thread MRAB via Python-list
On 2024-02-16 20:07, Gabor Urban via Python-list wrote: Hi guys, I need something about modules to be clarified. Suppose I have written a module eg: ModuleA which imports an other module, let us say the datetime. If I import ModuleA in a script, will be datetime imported automatically? Yes.

A question about import

2024-02-16 Thread Gabor Urban via Python-list
Hi guys, I need something about modules to be clarified. Suppose I have written a module eg: ModuleA which imports an other module, let us say the datetime. If I import ModuleA in a script, will be datetime imported automatically? Thanks in advance, -- Urbán Gábor Linux is like a wigwam: no G

Re: Question about garbage collection

2024-01-17 Thread Left Right via Python-list
So, here's some info about how to see what's going on with Python's memory allocation: https://docs.python.org/3/library/tracemalloc.html . I haven't looked into this in a long time, but it used to be the case that you needed to compile native modules (and probably Python itself?) so that instrumen

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 de

Re: Question about garbage collection

2024-01-16 Thread Greg Ewing via Python-list
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 deleted, I make them weak references. I don't see how wea

Re: Question about garbage collection

2024-01-16 Thread Greg Ewing via Python-list
On 17/01/24 4:00 am, Chris Angelico wrote: class Form: def __init__(self): self.elements = [] class Element: def __init__(self, form): self.form = form form.elements.append(self) If you make the reference from Element to Form a weak reference, it won't keep

Re: Question about garbage collection

2024-01-16 Thread Barry via Python-list
> On 16 Jan 2024, at 12:10, Frank Millman via Python-list > wrote: > > My problem is that my app is quite complex, and it is easy to leave a > reference dangling somewhere which prevents an object from being gc'd. What I do to track these problems down is use gc.get_objects() then summerize

Re: Question about garbage collection

2024-01-16 Thread Barry via Python-list
> On 16 Jan 2024, at 13:17, Thomas Passin via Python-list > wrote: > > The usual advice is to call deleteLater() on objects derived from PyQt > classes. I don't know enough about PyQt to know if this takes care of all > dangling reference problems, though. It works well and robustly. Bar

Re: Question about garbage collection

2024-01-16 Thread Chris Angelico via Python-list
, so the Element also refers to the corresponding Column. If the Form and Element aren't in a refloop, this shouldn't be a problem. However, if this is the same Table and Column that you referred to above, that might be the answer to my question. Are you "done" with the Table at

Re: Question about garbage collection

2024-01-16 Thread Frank Millman via Python-list
On 2024-01-16 2:15 PM, Chris Angelico via Python-list wrote: Where do you tend to "leave a reference dangling somewhere"? How is this occurring? Is it a result of an incomplete transaction (like an HTTP request that never finishes), or a regular part of the operation of the server? I have a c

Re: Question about garbage collection

2024-01-16 Thread Thomas Passin via Python-list
On 1/16/2024 4:17 AM, Barry wrote: On 16 Jan 2024, at 03:49, Thomas Passin via Python-list wrote: This kind of thing can happen with PyQt, also. There are ways to minimize it but I don't know if you can ever be sure all Qt C++ objects will get deleted. It depends on the type of object an

Re: Question about garbage collection

2024-01-16 Thread Chris Angelico via Python-list
On Tue, 16 Jan 2024 at 23:08, Frank Millman via Python-list wrote: > > 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 r

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 logging on, doing stu

Re: Question about garbage collection

2024-01-16 Thread Barry via Python-list
> On 16 Jan 2024, at 03:49, Thomas Passin via Python-list > wrote: > > This kind of thing can happen with PyQt, also. There are ways to minimize it > but I don't know if you can ever be sure all Qt C++ objects will get deleted. > It depends on the type of object and the circumstances. Whe

Re: Question about garbage collection

2024-01-15 Thread Thomas Passin via Python-list
On 1/15/2024 9:47 PM, Akkana Peck via Python-list wrote: I wrote: Also be warned that some modules (particularly if they're based on libraries not written in Python) might not garbage collect, so you may need to use other methods of cleaning up after those objects. Chris Angelico writes: Go

Re: Question about garbage collection

2024-01-15 Thread Chris Angelico via Python-list
On Tue, 16 Jan 2024 at 13:49, Akkana Peck via Python-list wrote: > > I wrote: > > > Also be warned that some modules (particularly if they're based on > > > libraries not written in Python) might not garbage collect, so you may > > > need to use other methods of cleaning up after those objects.

Re: Question about garbage collection

2024-01-15 Thread Akkana Peck via Python-list
I wrote: > > Also be warned that some modules (particularly if they're based on > > libraries not written in Python) might not garbage collect, so you may need > > to use other methods of cleaning up after those objects. Chris Angelico writes: > Got any examples of that? The big one for me was

Re: Question about garbage collection

2024-01-15 Thread Chris Angelico via Python-list
On Tue, 16 Jan 2024 at 06:32, Akkana Peck via Python-list wrote: > > > 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'. > > Dieter Maurer via Python-list writes: > > There

Re: Question about garbage collection

2024-01-15 Thread Akkana Peck 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'. Dieter Maurer via Python-list writes: > There are still some isolated cases when not all objects > in an unreachable cycle a

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 "https://devgui

Re: Question about garbage collection

2024-01-15 Thread Skip Montanaro via Python-list
> I do have several circular references. My experience is that if I do not > take some action to break the references when closing the session, the > objects remain alive. Below is a very simple program to illustrate this. > > Am I missing something? All comments appreciated. Python has normal ref

Question about garbage collection

2024-01-15 Thread Frank Millman via Python-list
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 logging on, doing stuff, and logging off. They can create many objects, some of t

Re: mypy question

2024-01-13 Thread Karsten Hilbert via Python-list
Am Sat, Jan 13, 2024 at 09:20:00PM +0100 schrieb Karsten Hilbert via Python-list: > > I was wondering if > > your type hint for queries shouldn't be the following. > > > > queries:list[dict[str,str]|dict[str,list]|dict[str,dict[str, dict[str, > > Ant]]] Wait, not really. Let me give an example.

Re: mypy question

2024-01-13 Thread Karsten Hilbert via Python-list
Am Fri, Jan 12, 2024 at 02:23:43PM +0100 schrieb Antoon Pardon via Python-list: > > queries:list[dict[str, str | list | dict[str, Any]]]=None, > > > >into > > > > "List[Dict[str, Union[str, List[Any], Dict[str, Any" > > > >seems accurate. I just don't understand why list[dict[str, > >s

Re: mypy question

2024-01-12 Thread Antoon Pardon via Python-list
Op 29/12/2023 om 16:02 schreef Karsten Hilbert via Python-list: Am Fri, Dec 29, 2023 at 07:49:17AM -0700 schrieb Mats Wichmann via Python-list: I am not sure why mypy thinks this gmPG2.py:554: error: Argument "queries" to "run_rw_queries" has incompatible type "List[Dict[str, str]]"; expecte

Re: mypy question

2023-12-31 Thread Karsten Hilbert via Python-list
Thanks to all. I ended up using Sequence for the list part and Mapping for the dict part, which does require "import typing" which I would rather have avoided. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B -- https://mail.python.org/mailman/listinfo/python-list

Re: mypy question

2023-12-30 Thread Greg Ewing via Python-list
On 31/12/23 10:06 am, Thomas Passin wrote: my suggestion above does work, *except* that you cannot mix-and-match different DictTypex types Have you tried declaring the argument as a Mapping instead of a dict? Seeing as Thomas Passin's Sequence experiment worked, it seems like this should work t

Re: Aw: Re: mypy question

2023-12-30 Thread Greg Ewing via Python-list
On 31/12/23 8:05 am, Chris Angelico wrote: Ah, I think you've hit on the problem there. Consider this: def add_item(stuff: dict[str: str | int]): stuff["spam"] = "ham" stuff["vooom"] = 1_000_000 Yep, that's it exactly. It's not the union itself that's the problem, but the fact that t

Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list
On 12/30/2023 9:14 AM, Thomas Passin via Python-list wrote: On 12/29/2023 10:02 AM, Karsten Hilbert via Python-list wrote: I agree that mypy's grasp of my intent from queries:list[dict[str, str | list | dict[str, Any]]]=None, into "List[Dict[str, Union[str, List[Any], Dict[str, Any]]]

Re: Aw: Re: mypy question

2023-12-30 Thread Chris Angelico via Python-list
On Sun, 31 Dec 2023 at 03:38, Thomas Passin via Python-list wrote: > I am not very expert in Python type hints. In working up the example > program I just posted, I got an error message from mypy that remarked > that "list" is invariant, and to try Sequence which is "covariant". I > don't know w

Re: mypy question

2023-12-30 Thread Barry via Python-list
> On 30 Dec 2023, at 15:11, Karsten Hilbert via Python-list > wrote: > > queries = [{'SQL': 'SELECT %(value)s', 'args': {'value': 1}}] > > and > > run_queries(conn, queries:list[str|dict[str, Any]]): In cases like this I often use a wrapper class in place of a simple str. If you have a cla

Aw: Re: Re: mypy question

2023-12-30 Thread Karsten Hilbert via Python-list
> I'm fairly sure your database queries don't actually give you strings or > dicts, right? You probably get lists (or iterators) of tuples and > somewhere you convert them to the arguments you are feeding to > run_queries(). Ah, no, those queries are enshrined within the middleware as Python stri

Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list
On 12/29/2023 10:02 AM, Karsten Hilbert via Python-list wrote: Am Fri, Dec 29, 2023 at 07:49:17AM -0700 schrieb Mats Wichmann via Python-list: I am not sure why mypy thinks this gmPG2.py:554: error: Argument "queries" to "run_rw_queries" has incompatible type "List[Dict[str, str]]"; expected

Aw: Re: Re: mypy question

2023-12-30 Thread Karsten Hilbert via Python-list
> It occurs to me that you could simplify things if you converted those > plain query strings to dicts: > > 'SELECT 1' --> {'SQL': 'SELECT 1'} Ha, indeed. There's likely not that many "simple string SQL queries" in that codebase so I shall take it as an opportunity to refactor them. So, at least

Re: Aw: Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list
On 12/30/2023 10:08 AM, Karsten Hilbert via Python-list wrote: Dear Thomas, thanks for taking the time to look into my issue. Maybe it helps if I explain what I want (sorry that my web mailer does not respect indentation, I will insert dots). I want a function to run SQL queries: run_queries

Re: Aw: Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list
On 12/30/2023 10:08 AM, Karsten Hilbert via Python-list wrote: Dear Thomas, thanks for taking the time to look into my issue. Maybe it helps if I explain what I want (sorry that my web mailer does not respect indentation, I will insert dots). I want a function to run SQL queries: run_queries

Aw: Re: mypy question

2023-12-30 Thread Karsten Hilbert via Python-list
Dear Thomas, thanks for taking the time to look into my issue. Maybe it helps if I explain what I want (sorry that my web mailer does not respect indentation, I will insert dots). I want a function to run SQL queries: run_queries(conn, queries): ...for q in queries: ..conn.execute(q) I no

Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list
On 12/29/2023 10:02 AM, Karsten Hilbert via Python-list wrote: I agree that mypy's grasp of my intent from queries:list[dict[str, str | list | dict[str, Any]]]=None, into "List[Dict[str, Union[str, List[Any], Dict[str, Any" seems accurate. I just don't understand why list[

Aw: Re: mypy question

2023-12-30 Thread Karsten Hilbert via Python-list
Hi Greg, > dict[str, str] is not a subtype of dict[str, str | something_else] > because you can assign a value of type something_else to the latter > but not the former. I understand what you are saying but I do not yet understand why this applies to my situation. I don't have Python at hand cur

Re: mypy question

2023-12-29 Thread Greg Ewing via Python-list
On 30/12/23 4:02 am, Karsten Hilbert wrote: def run_rw_queries ( link_obj:_TLnkObj=None, queries:list[dict[str, str | list | dict[str, Any]]]=None, Given that I would have thought that passing in list[dict[str, str]] for "queries" ought to be type safe.

Re: mypy question

2023-12-29 Thread Karsten Hilbert via Python-list
Am Fri, Dec 29, 2023 at 11:04:59AM -0700 schrieb Mats Wichmann via Python-list: > >For what it's worth here's the signature of that function: > > > > def run_rw_queries ( > > link_obj:_TLnkObj=None, > > queries:list[dict[str, str | list | dict[str, Any]]]=None, > >

Re: mypy question

2023-12-29 Thread Mats Wichmann via Python-list
On 12/29/23 08:02, Karsten Hilbert via Python-list wrote: Dict[str, str] means the key type and value type should both be strings, Indeed, I know that much, list[dict[str, str]] is what is getting passed in in this particular invocation of run_rw_queries(). For what it's worth here's the sign

Re: mypy question

2023-12-29 Thread Karsten Hilbert via Python-list
Am Fri, Dec 29, 2023 at 07:49:17AM -0700 schrieb Mats Wichmann via Python-list: > >I am not sure why mypy thinks this > > > >gmPG2.py:554: error: Argument "queries" to "run_rw_queries" has incompatible > >type "List[Dict[str, str]]"; expected > >"List[Dict[str, Union[str, List[Any], Dict[str, Any

Re: mypy question

2023-12-29 Thread Mats Wichmann via Python-list
On 12/29/23 05:15, Karsten Hilbert via Python-list wrote: Hi all, I am not sure why mypy thinks this gmPG2.py:554: error: Argument "queries" to "run_rw_queries" has incompatible type "List[Dict[str, str]]"; expected "List[Dict[str, Union[str, List[Any], Dict[str, Any" [arg-type]

Re: mypy question

2023-12-29 Thread Karsten Hilbert via Python-list
Am Fri, Dec 29, 2023 at 01:15:29PM +0100 schrieb Karsten Hilbert via Python-list: > I am not sure why mypy thinks this > > gmPG2.py:554: error: Argument "queries" to "run_rw_queries" has incompatible > type "List[Dict[str, str]]"; expected > "List[Dict[str, Union[str, List[Any], Dict[str, Any]]]

mypy question

2023-12-29 Thread Karsten Hilbert via Python-list
Hi all, I am not sure why mypy thinks this gmPG2.py:554: error: Argument "queries" to "run_rw_queries" has incompatible type "List[Dict[str, str]]"; expected "List[Dict[str, Union[str, List[Any], Dict[str, Any" [arg-type] rows, idx = run_rw_queries(link_obj = conn, queri

RE: Newline (NuBe Question)

2023-11-27 Thread AVI GROSS via Python-list
ble. Have to head out as this is already long enough. -Original Message- From: 'DL Neil' Sent: Monday, November 27, 2023 2:49 AM To: avi.e.gr...@gmail.com; python-list@python.org Subject: Re: Newline (NuBe Question) Avi, On 11/27/2023 4:15 PM, avi.e.gr...@gmail.com wrote: &g

Re: Newline (NuBe Question)

2023-11-26 Thread 'DL Neil' via Python-list
Avi, On 11/27/2023 4:15 PM, avi.e.gr...@gmail.com wrote: Dave, Back on a hopefully more serious note, I want to make a bit of an analogy with what happens when you save data in a format like a .CSV file. Often you have a choice of including a header line giving names to the resulting columns,

RE: Newline (NuBe Question)

2023-11-26 Thread AVI GROSS via Python-list
L Neil via Python-list Sent: Sunday, November 26, 2023 5:19 PM To: python-list@python.org Subject: Re: Newline (NuBe Question) On 11/27/2023 10:04 AM, Peter J. Holzer via Python-list wrote: > On 2023-11-25 08:32:24 -0600, Michael F. Stemper via Python-list wrote: >> On 24/11/2023 21.45, av

Re: Newline (NuBe Question)

2023-11-26 Thread Chris Angelico via Python-list
On Mon, 27 Nov 2023 at 13:52, AVI GROSS via Python-list wrote: > Be that as it > may, and I have no interest in this topic, in the future I may use the ever > popular names of Primus, Secundus and Tertius and get blamed for using > Latin. > Imperious Prima flashes forth her edict to "begin it".

RE: Newline (NuBe Question)

2023-11-26 Thread AVI GROSS via Python-list
y, November 26, 2023 4:58 PM To: python-list@python.org Subject: Re: Newline (NuBe Question) On 11/27/2023 12:48 AM, Chris Angelico via Python-list wrote: > On Sun, 26 Nov 2023 at 21:08, Michael F. Stemper via Python-list > wrote: >> >> On 24/11/2023 21.45, avi.e.gr...@gmail.com

Re: Newline (NuBe Question)

2023-11-26 Thread DL Neil via Python-list
On 11/27/2023 10:04 AM, Peter J. Holzer via Python-list wrote: On 2023-11-25 08:32:24 -0600, Michael F. Stemper via Python-list wrote: On 24/11/2023 21.45, avi.e.gr...@gmail.com wrote: Of course, for serious work, some might suggest avoiding constructs like a list of lists and switch to using m

Re: Newline (NuBe Question)

2023-11-26 Thread DL Neil via Python-list
On 11/27/2023 1:08 AM, Roel Schroeven via Python-list wrote: I prefer namedtuples or dataclasses over tuples. They allow you to refer to their fields by name instead of index: student.gpa is much clearer than student[2], and makes it less likely to accidentally refer to the wrong field. +1 re

Re: RE: Newline (NuBe Question)

2023-11-26 Thread Chris Angelico via Python-list
On Mon, 27 Nov 2023 at 06:15, wrote: > But I learn from criticism. If I ever write a program like that and do not > feel like typing, will this do? > > dents = [ ...] > > Or will that not include students who happen to be edentulous? > If they're learning to drive, this variable name would make c

Re: Newline (NuBe Question)

2023-11-26 Thread DL Neil via Python-list
On 11/27/2023 12:48 AM, Chris Angelico via Python-list wrote: On Sun, 26 Nov 2023 at 21:08, Michael F. Stemper via Python-list wrote: On 24/11/2023 21.45, avi.e.gr...@gmail.com wrote: Grizz[l]y, I think the point is not about a sorted list or sorting in general It is about reasons why mainta

Re: Newline (NuBe Question)

2023-11-26 Thread Peter J. Holzer via Python-list
On 2023-11-25 08:32:24 -0600, Michael F. Stemper via Python-list wrote: > On 24/11/2023 21.45, avi.e.gr...@gmail.com wrote: > > Of course, for serious work, some might suggest avoiding constructs like a > > list of lists and switch to using modules and data structures [...] > > Those who would rec

RE: RE: Newline (NuBe Question)

2023-11-26 Thread AVI GROSS via Python-list
al Message- From: Python-list On Behalf Of Chris Angelico via Python-list Sent: Sunday, November 26, 2023 6:49 AM To: python-list@python.org Subject: Re: RE: Newline (NuBe Question) On Sun, 26 Nov 2023 at 21:08, Michael F. Stemper via Python-list wrote: > > On 24/11/2023 21.45, avi.e.gr...

RE: RE: Newline (NuBe Question)

2023-11-26 Thread AVI GROSS via Python-list
E: Newline (NuBe Question) On 24/11/2023 21.45, avi.e.gr...@gmail.com wrote: > Grizz[l]y, > > I think the point is not about a sorted list or sorting in general It is > about reasons why maintaining a data structure such as a list in a program > can be useful beyond printing things once

Re: Newline (NuBe Question)

2023-11-26 Thread Roel Schroeven via Python-list
Michael F. Stemper via Python-list schreef op 25/11/2023 om 15:32: On 24/11/2023 21.45,avi.e.gr...@gmail.com wrote: > Grizz[l]y, > > I think the point is not about a sorted list or sorting in general It is > about reasons why maintaining a data structure such as a list in a program > can be us

Re: RE: Newline (NuBe Question)

2023-11-26 Thread Chris Angelico via Python-list
On Sun, 26 Nov 2023 at 21:08, Michael F. Stemper via Python-list wrote: > > On 24/11/2023 21.45, avi.e.gr...@gmail.com wrote: > > Grizz[l]y, > > > > I think the point is not about a sorted list or sorting in general It is > > about reasons why maintaining a data structure such as a list in a progr

Re: RE: Newline (NuBe Question)

2023-11-26 Thread Michael F. Stemper via Python-list
On 24/11/2023 21.45, avi.e.gr...@gmail.com wrote: Grizz[l]y, I think the point is not about a sorted list or sorting in general It is about reasons why maintaining a data structure such as a list in a program can be useful beyond printing things once. There are many possible examples such as hav

RE: Newline (NuBe Question)

2023-11-24 Thread AVI GROSS via Python-list
ta structure facilitates ... -Original Message- From: Python-list On Behalf Of Grizzy Adams via Python-list Sent: Thursday, November 16, 2023 8:41 AM To: python-list@python.org Subject: Re: Newline (NuBe Question) Thursday, November 16, 2023 at 7:47, Thomas Passin via Python-list wr

Re: Code improvement question

2023-11-21 Thread Rimu Atkinson via Python-list
re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt) \b - a word boundary. [0-9]{2,7} - 2 to 7 digits - - a hyphen-minus [0-9]{2} - exactly 2 digits - - a hyphen-minus [0-9]{2} - exactly 2 digits \b - a word boundary. Seems quite straightforward to me.

RE: Code improvement question

2023-11-17 Thread AVI GROSS via Python-list
question On 2023-11-16 11:34:16 +1300, Rimu Atkinson via Python-list wrote: > > > Why don't you use re.findall? > > > > > > re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt) > > > > I think I can see what you did there but it won't make

Re: Code improvement question

2023-11-17 Thread jak via Python-list
MRAB ha scritto: Bare excepts are a very bad idea. I know, you're right but to test the CAS numbers were inside a string (txt) and instead of the 'open(file)' there was 'io.StingIO(txt)' so the risk was almost null. When I copied it here I didn't think about it. Sorry. -- https://mail.python.

Re: Code improvement question

2023-11-17 Thread MRAB via Python-list
ny hints Why don't you use re.findall? re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt) I think I can see what you did there but it won't make sense to me - or whoever looks at the code - in future. That answers your specific question. However, I am in awe of people who

Re: Code improvement question

2023-11-17 Thread jak via Python-list
e.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt) I think I can see what you did there but it won't make sense to me - or whoever looks at the code - in future. That answers your specific question. However, I am in awe of people who can just "do" regular expressions and

Re: Code improvement question

2023-11-17 Thread Thomas Passin via Python-list
On 11/17/2023 9:46 AM, Peter J. Holzer via Python-list wrote: On 2023-11-17 07:48:41 -0500, Thomas Passin via Python-list wrote: On 11/17/2023 6:17 AM, Peter J. Holzer via Python-list wrote: Oh, and Python (just like Perl) allows you to embed whitespace and comments into Regexps, which helps re

Re: Code improvement question

2023-11-17 Thread Peter J. Holzer via Python-list
On 2023-11-17 07:48:41 -0500, Thomas Passin via Python-list wrote: > On 11/17/2023 6:17 AM, Peter J. Holzer via Python-list wrote: > > Oh, and Python (just like Perl) allows you to embed whitespace and > > comments into Regexps, which helps readability a lot if you have to > > write long regexps. >

Re: Code improvement question

2023-11-17 Thread Thomas Passin via Python-list
e to me - or whoever looks at the code - in future. That answers your specific question. However, I am in awe of people who can just "do" regular expressions and I thank you very much for what would have been a monumental effort had I tried it. I feel the same way about regex. If I can

Re: Code improvement question

2023-11-17 Thread Peter J. Holzer via Python-list
sense to me - or > > whoever looks at the code - in future. > > > > That answers your specific question. However, I am in awe of people who > > can just "do" regular expressions and I thank you very much for what > > would have been a monumental effort had I tried

Re: Code improvement question

2023-11-16 Thread Mike Dewhirst via Python-list
nswers your specific question. However, I am in awe of people who can just "do" regular expressions and I thank you very much for what would have been a monumental effort had I tried it. I feel the same way about regex. If I can find a way to write something without regex I very much p

Re: Code improvement question

2023-11-16 Thread Rimu Atkinson via Python-list
Why don't you use re.findall? re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt) I think I can see what you did there but it won't make sense to me - or whoever looks at the code - in future. That answers your specific question. However, I am in awe of peop

Re: Code improvement question

2023-11-16 Thread MRAB via Python-list
len(bit) > 6 else "")       return " ".join(pieces) Many thanks for any hints Why don't you use re.findall? re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt) I think I can see what you did there but it won't make sense to me - or whoever looks a

Re: Code improvement question

2023-11-16 Thread Mike Dewhirst via Python-list
uot;.join(pieces) Many thanks for any hints Why don't you use re.findall? re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt) I think I can see what you did there but it won't make sense to me - or whoever looks at the code - in future. That answers your specific questi

Re: Newline (NuBe Question)

2023-11-16 Thread Grizzy Adams via Python-list
Thursday, November 16, 2023 at 7:47, Thomas Passin via Python-list wrote: Re: Newline (NuBe Question) (at least in part) >I wrote that you don't need the "students" list, which is correct. But >there could be a use for a list. It would let you change the order in >

Re: Newline (NuBe Question)

2023-11-16 Thread Thomas Passin via Python-list
On 11/16/2023 1:19 AM, Grizzy Adams via Python-list wrote: Wednesday, November 15, 2023 at 15:54, Thomas Passin via Python-list wrote: Re: Newline (NuBe Question) (at least in part) On 11/15/2023 2:04 PM, Grizzy Adams via Python-list wrote: Wednesday, November 15, 2023 at 12:19, Pierre

Re: Newline (NuBe Question)

2023-11-15 Thread Grizzy Adams via Python-list
Wednesday, November 15, 2023 at 15:54, Thomas Passin via Python-list wrote: Re: Newline (NuBe Question) (at least in part) >On 11/15/2023 2:04 PM, Grizzy Adams via Python-list wrote: >> Wednesday, November 15, 2023 at 12:19, Pierre Fortin wrote: >> Re: Newline (NuBe Question) (a

Re: Newline (NuBe Question)

2023-11-15 Thread Thomas Passin via Python-list
On 11/15/2023 2:04 PM, Grizzy Adams via Python-list wrote: Wednesday, November 15, 2023 at 12:19, Pierre Fortin wrote: Re: Newline (NuBe Question) (at least in part) On Wed, 15 Nov 2023 16:51:09 - Grizzy Adams via Python-list wrote: I don't give solutions; just a nudge... you appea

Re: Newline (NuBe Question)

2023-11-15 Thread Grizzy Adams via Python-list
Wednesday, November 15, 2023 at 12:19, Pierre Fortin wrote: Re: Newline (NuBe Question) (at least in part) >On Wed, 15 Nov 2023 16:51:09 - Grizzy Adams via Python-list wrote: > >I don't give solutions; just a nudge... you appear not to fully grok >"list"; yo

Re: Newline (NuBe Question)

2023-11-15 Thread Pierre Fortin via Python-list
On Wed, 15 Nov 2023 16:51:09 - Grizzy Adams via Python-list wrote: I don't give solutions; just a nudge... you appear not to fully grok "list"; your list is ONE list with no delineation between students. You want a "list of lists"... >['Example High', 'Mary', 89.6, 'Pass', 'Example High', 'M

Re: Newline (NuBe Question)

2023-11-15 Thread Grizzy Adams via Python-list
Wednesday, November 15, 2023 at 9:45, Thomas Passin via Python-list wrote: Re: Newline (NuBe Question) (at least in part) >On 11/15/2023 2:25 AM, Grizzy Adams via Python-list wrote: >> Hi & thanks for patience with what could be simple to you >You may see responses that sugg

Re: Newline (NuBe Question)

2023-11-15 Thread Thomas Passin via Python-list
On 11/15/2023 2:25 AM, Grizzy Adams via Python-list wrote: Hi & thanks for patience with what could be simple to you Have this (from an online "classes" tutorial) --- Start Code Snippit --- students = [] grades = [] for s in geographyClass: students.append(geographyStudent(s)) for s i

Re: Newline (NuBe Question)

2023-11-15 Thread Grizzy Adams via Python-list
Wednesday, November 15, 2023 at 9:50, Alan Gauld via Python-list wrote: Re: Newline (NuBe Question) (at least in part) >On 15/11/2023 07:25, Grizzy Adams via Python-list wrote: >> for s in students: >> grades.append(s.school) >>

Re: Newline (NuBe Question)

2023-11-15 Thread Cameron Simpson via Python-list
On 15Nov2023 07:25, Grizzy Adams wrote: Have this (from an online "classes" tutorial) Response inline below. students = [] grades = [] for s in geographyClass: students.append(geographyStudent(s)) for s in students: grades.append(s.school) grades.append(

Re: Newline (NuBe Question)

2023-11-15 Thread Alan Gauld via Python-list
On 15/11/2023 07:25, Grizzy Adams via Python-list wrote: > for s in students: > grades.append(s.school) > grades.append(s.name) > grades.append(s.finalGrade()) > if s.finalGrade()>82: > grades.append("Pass") >

Re: Newline (NuBe Question)

2023-11-15 Thread dn via Python-list
On 15/11/2023 20.25, Grizzy Adams via Python-list wrote: Hi & thanks for patience with what could be simple to you Have this (from an online "classes" tutorial) There are lots of on-line classes! --- Start Code Snippit --- students = [] grades = [] for s in geographyClass: student

Newline (NuBe Question)

2023-11-14 Thread Grizzy Adams via Python-list
Hi & thanks for patience with what could be simple to you Have this (from an online "classes" tutorial) --- Start Code Snippit --- students = [] grades = [] for s in geographyClass: students.append(geographyStudent(s)) for s in students: grades.append(s.school)

Re: Code improvement question

2023-11-14 Thread MRAB via Python-list
on't you use re.findall? re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt) I think I can see what you did there but it won't make sense to me - or whoever looks at the code - in future. That answers your specific question. However, I am in awe of people who can just "

Re: Code improvement question

2023-11-14 Thread Mike Dewhirst via Python-list
0-9]{2}-[0-9]{2}\b', txt) I think I can see what you did there but it won't make sense to me - or whoever looks at the code - in future. That answers your specific question. However, I am in awe of people who can just "do" regular expressions and I thank you very muc

Re: Code improvement question

2023-11-14 Thread MRAB via Python-list
On 2023-11-14 23:14, Mike Dewhirst via Python-list wrote: I'd like to improve the code below, which works. It feels clunky to me. I need to clean up user-uploaded files the size of which I don't know in advance. After cleaning they might be as big as 1Mb but that would be super rare. Perhaps on

Code improvement question

2023-11-14 Thread Mike Dewhirst via Python-list
I'd like to improve the code below, which works. It feels clunky to me. I need to clean up user-uploaded files the size of which I don't know in advance. After cleaning they might be as big as 1Mb but that would be super rare. Perhaps only for testing. I'm extracting CAS numbers and here is

Re: Question(s)

2023-10-27 Thread Greg Ewing via Python-list
On 25/10/23 2:32 pm, Chris Angelico wrote: Error correcting memory, redundant systems, and human monitoring, plus the ability to rewrite the guidance software on the fly if they needed to. Although the latter couldn't actually be done with the AGC, as the software was in ROM. They could poke va

Re: Question(s)

2023-10-26 Thread Thomas Passin via Python-list
On Behalf Of Thomas Passin via Python-list Sent: Thursday, October 26, 2023 6:50 PM To: python-list@python.org Subject: Re: Question(s) On 10/26/2023 6:36 PM, AVI GROSS via Python-list wrote: I am not one for IDLE worship, Tenor. But if you have been getting a message here, it is that there are

RE: Question(s)

2023-10-26 Thread AVI GROSS via Python-list
: Thursday, October 26, 2023 6:50 PM To: python-list@python.org Subject: Re: Question(s) On 10/26/2023 6:36 PM, AVI GROSS via Python-list wrote: > I am not one for IDLE worship, Tenor. But if you have been getting a message here, it is that there are an amazing number of programs that support your

  1   2   3   4   5   6   7   8   9   10   >