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

2024-03-25 Thread Jon Ribbens via Python-list
On 2024-03-25, Loris Bennett wrote: > "Michael F. Stemper" writes: > >> On 25/03/2024 01.56, Loris Bennett wrote: >>> Grant Edwards writes: >>> On 2024-03-22, Loris Bennett via Python-list wrote: > Yes, I was mistakenly thinking that the popping the element would >

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

2024-02-02 Thread Jon Ribbens via Python-list
On 2024-02-02, Lawrence D'Oliveiro wrote: > On 1 Feb 2024 10:09:10 GMT, Stefan Ram wrote: > >> Heck, even of the respected members of this newsgroup, IIRC, no one >> mentioned "__await__". > > It’s part of the definition of an “awaitable”, if you had looked that up. >

Re: How to enter multiple, similar, dictionaries?

2023-12-11 Thread Jon Ribbens via Python-list
On 2023-12-11, Chris Green wrote: > Chris Green wrote: >> Is there a way to abbreviate the following code somehow? >> >> lv = {'dev':'bbb', 'input':'1', 'name':'Leisure volts'} >> sv = {'dev':'bbb', 'input':'0', 'name':'Starter volts'} >> la = {'dev':'bbb', 'input':'2',

Re: Python Golf

2023-11-07 Thread Jon Ribbens via Python-list
On 2023-11-07, wrote: > Discussions like this feel a bit silly after a while. How long > something is to type on a command line is not a major issue and > brevity can lead to being hard to remember too especially using > obscure references. Of course it's silly, that's why it's called "golf"!

Re: Python Golf

2023-11-07 Thread Jon Ribbens via Python-list
On 2023-11-07, Stefan Ram wrote: > I read this in a shell newsgroup: > > perl -anE '$s += $F[1]; END {say $s}' in > > , so I wrote > > py -c "import sys; print(sum(int(F.split()[1])for F in sys.stdin))" > to show that this is possible with Python too. > > But now people complain that

Re: Checking if email is valid

2023-11-06 Thread Jon Ribbens via Python-list
On 2023-11-06, Mats Wichmann wrote: > On 11/6/23 01:57, Simon Connah via Python-list wrote: >> The thing I truly hate is when you have two telephone number fields. >> One for landline and one for mobile. I mean who in hell has a >> landline these days? > > People who live in places with spotty,

Re: Checking if email is valid

2023-11-06 Thread Jon Ribbens via Python-list
On 2023-11-06, D'Arcy Cain wrote: > On 2023-11-05 06:48, Jon Ribbens via Python-list wrote: >> Sometimes I think that these sorts of stupid, wrong, validation are the >> fault of idiot managers. When it's apostrophes though I'm suspicious >> that it may be idiot programme

Re: pip/pip3 confusion and keeping up to date

2023-11-05 Thread Jon Ribbens via Python-list
On 2023-11-05, Karsten Hilbert wrote: > Am Fri, Nov 03, 2023 at 01:53:32PM - schrieb Jon Ribbens via Python-list: > >> >> Are they not available in your system's package manager? >> > >> > ... this clearly often answers to "no

Re: Checking if email is valid

2023-11-05 Thread Jon Ribbens via Python-list
On 2023-11-05, Grant Edwards wrote: > On 2023-11-05, D'Arcy Cain via Python-list wrote: >> On 2023-11-05 00:39, Grant Edwards via Python-list wrote: >>> Definitely. Syntactic e-mail address "validation" is one of the most >>> useless and widely broken things on the Interwebs. People who do >>>

Re: pip/pip3 confusion and keeping up to date

2023-11-05 Thread Jon Ribbens via Python-list
On 2023-11-05, Chris Green wrote: > Jon Ribbens wrote: >> On 2023-11-03, Karsten Hilbert wrote: >> > Am Thu, Nov 02, 2023 at 04:07:33PM -0600 schrieb Mats Wichmann via >> > Python-list: >> >> >So they now have only python3 and there is no python executable in >> >> >PATH. >> >> >> >> FWIW, for

Re: pip/pip3 confusion and keeping up to date

2023-11-05 Thread Jon Ribbens via Python-list
On 2023-11-03, Karsten Hilbert wrote: > Am Thu, Nov 02, 2023 at 04:07:33PM -0600 schrieb Mats Wichmann via > Python-list: >> >So they now have only python3 and there is no python executable in >> >PATH. >> >> FWIW, for this you install the little stub package python-is-python3. >> Especially if

Re: Checking if email is valid

2023-11-05 Thread Jon Ribbens via Python-list
On 2023-11-05, D'Arcy Cain wrote: > On 2023-11-05 00:39, Grant Edwards via Python-list wrote: >> Definitely. Syntactic e-mail address "validation" is one of the most >> useless and widely broken things on the Interwebs. People who do >> anything other than require an '@' (and optionally make you

Re: pip/pip3 confusion and keeping up to date

2023-11-04 Thread Jon Ribbens via Python-list
On 2023-11-03, Karsten Hilbert wrote: > Am Thu, Nov 02, 2023 at 09:35:43PM - schrieb Jon Ribbens via Python-list: > > Regardless of ... > >> Because pip barely plays well by itself, let alone with other package >> managers at the same time. > > ... being tru

Re: Checking if email is valid

2023-11-03 Thread Jon Ribbens via Python-list
On 2023-11-03, Chris Angelico wrote: > On Fri, 3 Nov 2023 at 12:21, AVI GROSS via Python-list > wrote: >> My guess is that a first test of an email address might be to see if >> a decent module of that kind fills out the object to your >> satisfaction. You can then perhaps test parts of the

Re: pip/pip3 confusion and keeping up to date

2023-11-02 Thread Jon Ribbens via Python-list
On 2023-11-02, Chris Green wrote: > Jon Ribbens wrote: >> On 2023-11-02, Dieter Maurer wrote: >> > 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? >> > >> >

Re: pip/pip3 confusion and keeping up to date

2023-11-02 Thread Jon Ribbens via Python-list
On 2023-11-02, Chris Green wrote: > Jon Ribbens wrote: >> On 2023-11-02, Chris Green wrote: >> > I have a couple of systems which used to have python2 as well as >> > python3 but as Ubuntu and Debian verions have moved on they have >> > finally eliminated all dependencies on python2. >> > >> >

Re: pip/pip3 confusion and keeping up to date

2023-11-02 Thread Jon Ribbens via Python-list
On 2023-11-02, Chris Green wrote: > I have a couple of systems which used to have python2 as well as > python3 but as Ubuntu and Debian verions have moved on they have > finally eliminated all dependencies on python2. > > So they now have only python3 and there is no python executable in > PATH.

Re: pip/pip3 confusion and keeping up to date

2023-11-02 Thread Jon Ribbens via Python-list
On 2023-11-02, Dieter Maurer wrote: > 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. >

Re: Checking if email is valid

2023-11-02 Thread Jon Ribbens via Python-list
On 2023-11-02, Simon Connah wrote: > Valid as in conforms to the standard. Although having looked at the > standard that might be more difficult than originally planned. Yes. Almost nobody actually implements "the standard" as in RFC 2822 section 3.4.1 (which can contain, for example,

Re: Checking if email is valid

2023-11-02 Thread Jon Ribbens via Python-list
On 2023-11-02, D'Arcy Cain wrote: > On 2023-11-01 17:17, Chris Angelico via Python-list wrote: >> On Thu, 2 Nov 2023 at 08:09, Grant Edwards via Python-list >> wrote: >>> Make sure it has an '@' in it. Possibly require at least one '.' >>> after the '@'. >> >> No guarantee that there'll be a

Re: Checking if email is valid

2023-11-01 Thread Jon Ribbens via Python-list
On 2023-11-01, Chris Angelico wrote: > On Thu, 2 Nov 2023 at 05:21, Simon Connah via Python-list > wrote: >> Could someone push me in the right direction please? I just want to >> find out if a string is a valid email address. > > There is only one way to know that a string is a valid email

Re: path to python in venv

2023-09-27 Thread Jon Ribbens via Python-list
On 2023-09-27, Larry Martell wrote: > On Wed, Sep 27, 2023 at 12:42 PM Jon Ribbens via Python-list > wrote: >> On 2023-09-27, Larry Martell wrote: >> > I was under the impression that in a venv the python used would be in >> > the venv's bin dir. But in my ve

Re: path to python in venv

2023-09-27 Thread Jon Ribbens via Python-list
On 2023-09-27, Larry Martell wrote: > I was under the impression that in a venv the python used would be in > the venv's bin dir. But in my venvs I see this in the bin dirs: > > lrwxrwxrwx 1 larrymartell larrymartell7 Sep 27 11:21 python -> python3 > lrwxrwxrwx 1 larrymartell larrymartell

Re: isinstance()

2023-08-04 Thread Jon Ribbens via Python-list
On 2023-08-02, dn wrote: > Can you please explain why a multi-part second-argument must be a tuple > and not any other form of collection-type? The following comment may hold a clue: if (PyTuple_Check(cls)) { /* Not a general sequence -- that opens up the road to

Re: Bug in io.TextIOWrapper?

2023-06-19 Thread Jon Ribbens via Python-list
On 2023-06-19, Inada Naoki wrote: > I checked TextIOWrapper source code and confirmed that it doesn't call > encoder.write(text, finish=True) on close. > Since TextIOWrapper allows random access, it is difficult to call it > automatically. So please think it as just limitation rather than bug. >

Bug in io.TextIOWrapper?

2023-06-19 Thread Jon Ribbens via Python-list
io.TextIOWrapper() wraps a binary stream so you can write text to it. It takes an 'encoding' parameter, which it uses to look up the codec in the codecs registry, and then it uses the IncrementalEncoder and IncrementalDecoder classes for the appropriate codec. The IncrementalEncoder.encode()

Re: What to use instead of nntplib?

2023-05-22 Thread Jon Ribbens via Python-list
On 2023-05-22, Skip Montanaro wrote: >> My understanding is that nntplib isn't being erased from reality, >> it's merely being removed from the set of modules that are provided >> by default. >> >> I presume that once it's removed from the core, it will still be >> possible to install it via pip

Re: How to get get_body() to work? (about email)

2023-03-20 Thread Jon Ribbens via Python-list
On 2023-03-19, Greg Ewing wrote: > On 20/03/23 7:07 am, Jon Ribbens wrote: >> Ah, apparently it got removed in Python 3, which is a bit odd as the >> last I heard it was added in Python 2.2 in order to achieve consistency >> with other types. > > As far as I remember, the file type came into

Re: How to get get_body() to work? (about email)

2023-03-20 Thread Jon Ribbens via Python-list
On 2023-03-19, Stefan Ram wrote: > Jon Ribbens writes: >>(Also, I too find it annoying to have to avoid, but calling a local >>variable 'file' is somewhat suspect since it shadows the builtin.) > > Thanks for your remarks, but I'm not aware > of such a predefined name "file"! Ah, apparently

Re: How to get get_body() to work? (about email)

2023-03-20 Thread Jon Ribbens via Python-list
On 2023-03-19, Stefan Ram wrote: > Peng Yu writes: >>But when I try the following code, get_body() is not found. How to get >>get_body() to work? > > Did you know that this post of mine here was posted to > Usenet with a Python script I wrote? > > That Python script has a function to show

Re: =- and -= snag

2023-03-14 Thread Jon Ribbens via Python-list
On 2023-03-13, Morten W. Petersen wrote: > I was working in Python today, and sat there scratching my head as the > numbers for calculations didn't add up. It went into negative numbers, > when that shouldn't have been possible. > > Turns out I had a very small typo, I had =- instead of -=. > >

Re: Python 2.7 range Function provokes a Memory Error

2023-03-02 Thread Jon Ribbens via Python-list
On 2023-03-02, Stephen Tucker wrote: > The range function in Python 2.7 (and yes, I know that it is now > superseded), provokes a Memory Error when asked to deiliver a very long > list of values. > > I assume that this is because the function produces a list which it then > iterates through. > >

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

2023-03-01 Thread Jon Ribbens via Python-list
On 2023-03-02, Chris Angelico wrote: > On Thu, 2 Mar 2023 at 08:01, <2qdxy4rzwzuui...@potatochowder.com> wrote: >> On 2023-03-01 at 14:35:35 -0500, >> avi.e.gr...@gmail.com wrote: >> > What would have happened if all processors had been required to have >> > some low level instruction that

Re: Python 3.10 Fizzbuzz

2023-03-01 Thread Jon Ribbens via Python-list
On 2023-03-01, Simon Ward wrote: > On Tue, Feb 28, 2023 at 04:05:19PM -0500, avi.e.gr...@gmail.com wrote: >>Is it rude to name something "black" to make it hard for some of us to >>remind them of the rules or claim that our personal style is so often >>the opposite that it should be called

Re: How to escape strings for re.finditer?

2023-02-28 Thread Jon Ribbens via Python-list
On 2023-02-28, Thomas Passin wrote: > On 2/28/2023 10:05 AM, Roel Schroeven wrote: >> Op 28/02/2023 om 14:35 schreef Thomas Passin: >>> On 2/28/2023 4:33 AM, Roel Schroeven wrote: [...] (2) Searching for a string in another string, in a performant way, is not as simple as it first

Re: Is there a more efficient threading lock?

2023-02-26 Thread Jon Ribbens via Python-list
On 2023-02-26, Chris Angelico wrote: > On Sun, 26 Feb 2023 at 16:16, Jon Ribbens via Python-list > wrote: >> On 2023-02-25, Paul Rubin wrote: >> > The GIL is an evil thing, but it has been around for so long that most >> > of us have gotten used to it, and

Re: Is there a more efficient threading lock?

2023-02-26 Thread Jon Ribbens via Python-list
On 2023-02-26, Barry Scott wrote: > On 25/02/2023 23:45, Jon Ribbens via Python-list wrote: >> I think it is the case that x += 1 is atomic but foo.x += 1 is not. > > No that is not true, and has never been true. > >:>>> def x(a): >:...    a += 1 >:... >

Re: Is there a more efficient threading lock?

2023-02-25 Thread Jon Ribbens via Python-list
On 2023-02-25, Paul Rubin wrote: > Jon Ribbens writes: >>> 1) you generally want to use RLock rather than Lock >> Why? > > So that a thread that tries to acquire it twice doesn't block itself, > etc. Look at the threading lib docs for more info. Yes, I know what the docs say, I was asking why

Re: Is there a more efficient threading lock?

2023-02-25 Thread Jon Ribbens via Python-list
On 2023-02-25, Paul Rubin wrote: > Skip Montanaro writes: >> from threading import Lock > > 1) you generally want to use RLock rather than Lock Why? > 2) I have generally felt that using locks at the app level at all is an > antipattern. The main way I've stayed sane in multi-threaded Python

Re: Licensing?

2023-02-02 Thread Jon Ribbens via Python-list
On 2023-02-03, Greg Ewing wrote: > On 3/02/23 6:38 am, Jon Ribbens wrote: >> If you change someone else's code then you have created a derived >> work, which requires permission from both the original author and you >> to copy. (Unless you change it so much that nothing remains of the >> original

Re: Licensing?

2023-02-02 Thread Jon Ribbens via Python-list
On 2023-02-02, Stefan Ram wrote: > Many licenses in the Python world are like: "You can make > changes, but have to leave in my Copyright notice.". > > Would it be possible that the original author could not > claim a Copyright anymore when code has been changed? No. If you change

Re: Usenet vs. Mailing-list

2023-01-29 Thread Jon Ribbens via Python-list
On 2023-01-29, Peter J. Holzer wrote: > On 2023-01-29 02:09:28 -0000, Jon Ribbens via Python-list wrote: >> I'm not aware of any significant period in the last twenty-one years >> that > [the gateway] >> hasn't been working. Although sometimes it does feel like it i

Re: Usenet vs. Mailing-list

2023-01-28 Thread Jon Ribbens via Python-list
On 2023-01-29, Ben Bacarisse wrote: > "Peter J. Holzer" writes: > >> On 2023-01-27 21:04:58 +, Ben Bacarisse wrote: >>> mutt...@dastardlyhq.com writes: >>> >>> > Hi >>> >>> It looks like you posted this question via Usenet. comp.lang.python is >>> essentially dead as a Usenet group. It

Re: Usenet vs. Mailing-list (was: evaluation question)

2023-01-28 Thread Jon Ribbens via Python-list
On 2023-01-28, Peter J. Holzer wrote: > On 2023-01-27 21:04:58 +, Ben Bacarisse wrote: >> It looks like you posted this question via Usenet. comp.lang.python is >> essentially dead as a Usenet group. It exists, and gets NNTP versions >> of mail sent to the mailing list, but nothing posted

Re: ok, I feel stupid, but there must be a better way than this! (finding name of unique key in dict)

2023-01-20 Thread Jon Ribbens via Python-list
On 2023-01-20, Dino wrote: > > let's say I have this list of nested dicts: > > [ >{ "some_key": {'a':1, 'b':2}}, >{ "some_other_key": {'a':3, 'b':4}} > ] > > I need to turn this into: > > [ >{ "value": "some_key", 'a':1, 'b':2}, >{ "value": "some_other_key", 'a':3, 'b':4} > ]

Re: FTP without username and password

2022-12-06 Thread Jon Ribbens via Python-list
On 2022-12-06, ^Bart wrote: > Hi Guys, > > usually I use this code on my Debian Bullseye: > > # python3 -m pyftpdlib -i 192.168.0.71 -p 21 -d /home/my_user/ftp > > It works, it's simply easy and perfect but... a device in my lan needs a > ftp folder without username and password! > > I tried to

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

2022-11-14 Thread Jon Ribbens via Python-list
On 2022-11-14, Stefan Ram wrote: > Jon Ribbens writes: >>"""Create an array and print its length""" >>array = [1, 2, 3] >>array.clear > > BTW: Above, there are /two/ expression statements > with no effect; the other one is > > """Create an array and print its length""" > > . Apparently,

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

2022-11-13 Thread Jon Ribbens via Python-list
On 2022-11-14, Greg Ewing wrote: > On 14/11/22 1:31 pm, Jon Ribbens wrote: >> On 2022-11-13, DFS wrote: >>> But why is it allowed in the first place? >> >> Because it's an expression, and you're allowed to execute expressions. > > To put it a bit more clearly, you're allowed to evaluate > an

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

2022-11-13 Thread Jon Ribbens via Python-list
On 2022-11-13, DFS wrote: > On 11/13/2022 5:20 PM, Jon Ribbens wrote: >> On 2022-11-13, DFS wrote: >>> In code, list.clear is just ignored. >>> At the terminal, list.clear shows >>> >>> >>> >>> in code: >>> x = [1,2,3] >>> x.clear >>> print(len(x)) >>> 3 >>> >>> at terminal: >>> x = [1,2,3] >>>

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

2022-11-13 Thread Jon Ribbens via Python-list
On 2022-11-13, DFS wrote: > In code, list.clear is just ignored. > At the terminal, list.clear shows > > > > in code: > x = [1,2,3] > x.clear > print(len(x)) > 3 > > at terminal: > x = [1,2,3] > x.clear > > print(len(x)) > 3 > > > Caused me an hour of frustration before I noticed list.clear() was

Re: Beautiful Soup - close tags more promptly?

2022-10-24 Thread Jon Ribbens via Python-list
On 2022-10-24, Chris Angelico wrote: > On Tue, 25 Oct 2022 at 02:45, Jon Ribbens via Python-list > wrote: >> >> On 2022-10-24, Chris Angelico wrote: >> > On Mon, 24 Oct 2022 at 23:22, Peter J. Holzer wrote: >> >> Yes, I got that. What I want

Re: Beautiful Soup - close tags more promptly?

2022-10-24 Thread Jon Ribbens via Python-list
On 2022-10-24, Chris Angelico wrote: > On Mon, 24 Oct 2022 at 23:22, Peter J. Holzer wrote: >> Yes, I got that. What I wanted to say was that this is indeed a bug in >> html.parser and not an error (or sloppyness, as you called it) in the >> input or ambiguity in the HTML standard. > > I

Re: xml.etree and namespaces -- why?

2022-10-19 Thread Jon Ribbens via Python-list
On 2022-10-19, Robert Latest wrote: > If the XML input has namespaces, tags and attributes with prefixes > in the form prefix:sometag get expanded to {uri}sometag where the > prefix is replaced by the full URI. > > Which means that given an Element e, I cannot directly access its

Re: Find the path of a shell command

2022-10-13 Thread Jon Ribbens via Python-list
On 2022-10-12, Paulo da Silva wrote: > Às 22:38 de 12/10/22, Jon Ribbens escreveu: >> On 2022-10-12, Jon Ribbens wrote: >>> On 2022-10-12, Paulo da Silva wrote: Às 19:14 de 12/10/22, Jon Ribbens escreveu: > On 2022-10-12, Paulo da Silva > wrote: >> Às 05:00 de 12/10/22, Paulo

Re: Find the path of a shell command

2022-10-12 Thread Jon Ribbens via Python-list
On 2022-10-12, Jon Ribbens wrote: > On 2022-10-12, Paulo da Silva wrote: >> Às 19:14 de 12/10/22, Jon Ribbens escreveu: >>> On 2022-10-12, Paulo da Silva wrote: Às 05:00 de 12/10/22, Paulo da Silva escreveu: > Hi! > > The simple question: How do I find the full path of a shell

Re: Find the path of a shell command

2022-10-12 Thread Jon Ribbens via Python-list
On 2022-10-12, Paulo da Silva wrote: > Às 19:14 de 12/10/22, Jon Ribbens escreveu: >> On 2022-10-12, Paulo da Silva wrote: >>> Às 05:00 de 12/10/22, Paulo da Silva escreveu: Hi! The simple question: How do I find the full path of a shell command (linux), i.e. how do I obtain

Re: Find the path of a shell command

2022-10-12 Thread Jon Ribbens via Python-list
On 2022-10-12, Jon Ribbens wrote: > On 2022-10-12, Joe Pfeiffer wrote: >> Jon Ribbens writes: >> >>> On 2022-10-12, Michael F. Stemper wrote: On 12/10/2022 07.20, Chris Green wrote: > ... and rm will just about always be in /usr/bin. On two different versions of Ubuntu, it's

Re: Find the path of a shell command

2022-10-12 Thread Jon Ribbens via Python-list
On 2022-10-12, Paulo da Silva wrote: > Às 05:00 de 12/10/22, Paulo da Silva escreveu: >> Hi! >> >> The simple question: How do I find the full path of a shell command >> (linux), i.e. how do I obtain the corresponding of, for example, >> "type rm" in command line? >> >> The reason: >> I have

Re: Find the path of a shell command

2022-10-12 Thread Jon Ribbens via Python-list
On 2022-10-12, Joe Pfeiffer wrote: > Jon Ribbens writes: > >> On 2022-10-12, Michael F. Stemper wrote: >>> On 12/10/2022 07.20, Chris Green wrote: ... and rm will just about always be in /usr/bin. >>> >>> On two different versions of Ubuntu, it's in /bin. >> >> It will almost always be in

Re: Find the path of a shell command

2022-10-12 Thread Jon Ribbens via Python-list
On 2022-10-12, Michael F. Stemper wrote: > On 12/10/2022 07.20, Chris Green wrote: >> ... and rm will just about always be in /usr/bin. > > On two different versions of Ubuntu, it's in /bin. It will almost always be in /bin in any Unix or Unix-like system, because it's one of the fundamental

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

2022-10-10 Thread Jon Ribbens via Python-list
On 2022-10-10, Calvin Spealman wrote: > On Sat, Oct 8, 2022 at 5:35 PM rbowman wrote: >> On 10/7/22 21:32, Axy wrote: >> > So, seriously, why they needed else if the following pieces produce same >> > result? Does anyone know or remember their motivation? >> >> In real scenarios there would be

Re: Asynchronous execution of synchronous functions

2022-09-26 Thread Jon Ribbens via Python-list
On 2022-09-26, Stefan Ram wrote: > So, I wanted to try to download all pages in parallel with > processes to avoid any GIL effect, while I don't understand > what the GIL actuall is. But processes didn't work here, so > I tried threads. This worked and now the total run time is > down

Re: Mutating an HTML file with BeautifulSoup

2022-08-22 Thread Jon Ribbens via Python-list
On 2022-08-22, Peter J. Holzer wrote: > On 2022-08-22 00:45:56 -0000, Jon Ribbens via Python-list wrote: >> With the offset though, BeautifulSoup made an arbitrary decision to >> use ISO-8859-1 encoding and so when you chopped the bytestring at >> that offset it only worked

Re: Mutating an HTML file with BeautifulSoup

2022-08-22 Thread Jon Ribbens via Python-list
On 2022-08-21, Chris Angelico wrote: > On Mon, 22 Aug 2022 at 05:43, Jon Ribbens via Python-list > wrote: >> On 2022-08-21, Chris Angelico wrote: >> > On Sun, 21 Aug 2022 at 09:31, Jon Ribbens via Python-list >> > wrote: >> >> On 2022-08-20, Chris An

Re: Mutating an HTML file with BeautifulSoup

2022-08-22 Thread Jon Ribbens via Python-list
On 2022-08-21, Peter J. Holzer wrote: > On 2022-08-20 21:51:41 -0000, Jon Ribbens via Python-list wrote: >> On 2022-08-20, Stefan Ram wrote: >> > Jon Ribbens writes: >> >>... or you could avoid all that faff and just do re.sub()? > >> > source = '' &

Re: Mutating an HTML file with BeautifulSoup

2022-08-21 Thread Jon Ribbens via Python-list
On 2022-08-21, Chris Angelico wrote: > On Sun, 21 Aug 2022 at 09:31, Jon Ribbens via Python-list > wrote: >> On 2022-08-20, Chris Angelico wrote: >> > On Sun, 21 Aug 2022 at 03:27, Stefan Ram wrote: >> >> 2qdxy4rzwzuui...@potatochowder.com writes: >>

Re: Mutating an HTML file with BeautifulSoup

2022-08-20 Thread Jon Ribbens via Python-list
On 2022-08-20, Stefan Ram wrote: > Jon Ribbens writes: >>... or you could avoid all that faff and just do re.sub()? > > import bs4 > import re > > source = '' > > # Use Python to change the source, keeping the order of attributes. > > result = re.sub( r'href\s*=\s*"http"', r'href="https"',

Re: Mutating an HTML file with BeautifulSoup

2022-08-20 Thread Jon Ribbens via Python-list
On 2022-08-20, Chris Angelico wrote: > On Sun, 21 Aug 2022 at 03:27, Stefan Ram wrote: >> 2qdxy4rzwzuui...@potatochowder.com writes: >> >textual representations. That way, the following two elements are the >> >same (and similar with a collection of sub-elements in a different order >> >in

Re: Mutating an HTML file with BeautifulSoup

2022-08-20 Thread Jon Ribbens via Python-list
On 2022-08-19, Chris Angelico wrote: > What's the best way to precisely reconstruct an HTML file after > parsing it with BeautifulSoup? > > Using the Alice example from the BS4 docs: > html_doc = """The Dormouse's story > >The Dormouse's story > >Once upon a time there were three little

Re: UTF-8 and latin1

2022-08-18 Thread Jon Ribbens via Python-list
On 2022-08-18, Tobiah wrote: >> You configure the web server to send: >> >> Content-Type: text/html; charset=... >> >> in the HTTP header when it serves HTML files. > > So how does this break down? When a person enters > Montréal, Quebéc into a form field, what are they > doing on the

Re: UTF-8 and latin1

2022-08-18 Thread Jon Ribbens via Python-list
On 2022-08-18, Tobiah wrote: >> Generally speaking browser submisisons were/are supposed to be sent >> using the same encoding as the page, so if you're sending the page >> as "latin1" then you'll see that a fair amount I should think. If you >> send it as "utf-8" then you'll get 100% utf-8 back.

Re: UTF-8 and latin1

2022-08-18 Thread Jon Ribbens via Python-list
On 2022-08-17, Barry wrote: >> On 17 Aug 2022, at 18:30, Jon Ribbens via Python-list >> wrote: >> On 2022-08-17, Tobiah wrote: >>> I get data from various sources; client emails, spreadsheets, and >>> data from web applications. I find that I ca

Re: UTF-8 and latin1

2022-08-18 Thread Jon Ribbens via Python-list
On 2022-08-17, Tobiah wrote: >> That has already been decided, as much as it ever can be. UTF-8 is >> essentially always the correct encoding to use on output, and almost >> always the correct encoding to assume on input absent any explicit >> indication of another encoding. (e.g. the HTML

Re: UTF-8 and latin1

2022-08-17 Thread Jon Ribbens via Python-list
On 2022-08-17, Tobiah wrote: > I get data from various sources; client emails, spreadsheets, and > data from web applications. I find that I can do some_string.decode('latin1') > to get unicode that I can use with xlsxwriter, > or put in the header of a web page to display > European characters

Re: Fwd: timedelta object recursion bug

2022-07-28 Thread Jon Ribbens via Python-list
On 2022-07-28, Ben Hirsig wrote: > 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 > https://docs.python.org/3/library/datetime.html#examples-of-usage-timedelta >

Re: REPL with multiple function definitions

2022-06-27 Thread Jon Ribbens via Python-list
On 2022-06-26, Rob Cliffe wrote: > This 2-line program > > def f(): pass > def g(): pass > > runs silently (no Exception).  But: > > 23:07:02 c:\>python > Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 > bit (Intel)] on win32 > Type "help", "copyright", "credits" or

Re: How to replace characters in a string?

2022-06-08 Thread Jon Ribbens via Python-list
On 2022-06-08, Dave wrote: > I misunderstood how it worked, basically I’ve added this function: > > def filterCommonCharacters(theString): > myNewString = theString.replace("\u2019", "'") > return myNewString > Which returns a new string replacing the common characters. > > This can

Re: Python & nmap

2022-05-18 Thread Jon Ribbens via Python-list
On 2022-05-18, ^Bart wrote: > THE INPUT > - > import nmap > nm.scan(hosts='192.168.205.0/24', arguments='-n -sP -PE -PA21,23,80,3389') > hosts_list = [(x, nm[x]['status']['state']) for x in nm.all_hosts()] > for host, status

Re: Printing Unicode strings in a list

2022-04-28 Thread Jon Ribbens via Python-list
On 2022-04-28, Stephen Tucker wrote: > Hi PythonList Members, > > Consider the following log from a run of IDLE: > >== > > Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] > on win32 > Type "copyright", "credits" or "license()" for more information.

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-19 Thread Jon Ribbens via Python-list
On 2022-04-19, Barry wrote: >> On 19 Apr 2022, at 19:38, Dennis Lee Bieber wrote: >> *I /think/ this is the year used for leap-day calculations, and >> why some leap centuries are skipped as it is really less than a >> quarter day per year, so eventually one gets to over-correcting

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-19 Thread Jon Ribbens via Python-list
On 2022-04-19, Loris Bennett wrote: > If I am merely trying to represent part a very large number of seconds > as a number of years, 365 days per year does not seem that controversial > to me. Obviously there are issues if you expect all periods of an > integer number of years which start on a

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-19 Thread Jon Ribbens via Python-list
On 2022-04-19, Loris Bennett wrote: > Jon Ribbens writes: >> On 2022-04-19, Loris Bennett wrote: >>> I now realise that timedelta is not really what I need. I am interested >>> solely in pure periods, i.e. numbers of seconds, >> >> That's exactly what timedelta is. >> >>> that I can convert

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-19 Thread Jon Ribbens via Python-list
On 2022-04-19, Loris Bennett wrote: > I now realise that timedelta is not really what I need. I am interested > solely in pure periods, i.e. numbers of seconds, That's exactly what timedelta is. > that I can convert back and forth from a format such as > > 11-22::44:55 I don't recognise

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-16 Thread Jon Ribbens via Python-list
On 2022-04-16, Dennis Lee Bieber wrote: > On Sat, 16 Apr 2022 20:35:22 - (UTC), Jon Ribbens > declaimed the following: >>I can categorically guarantee you it is not. But let's put it a >>different way, if you like, if I want to add 24 hours, i.e. 86,400 >>seconds (or indeed any other fixed

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-16 Thread Jon Ribbens via Python-list
On 2022-04-16, Peter J. Holzer wrote: > On 2022-04-16 14:22:04 -0000, Jon Ribbens via Python-list wrote: >> On 2022-04-16, Jon Ribbens wrote: >> > On 2022-04-16, Peter J. Holzer wrote: >> >> Python missed the switch to DST here, the timezone is wrong. >> >

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-16 Thread Jon Ribbens via Python-list
On 2022-04-16, Peter J. Holzer wrote: > On 2022-04-16 13:47:32 -0000, Jon Ribbens via Python-list wrote: >> That's impossible unless you redefine 'timedelta' from being, as it is >> now, a fixed-length period of time, to instead being the difference >> between two spe

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-16 Thread Jon Ribbens via Python-list
On 2022-04-16, Jon Ribbens wrote: > On 2022-04-16, Peter J. Holzer wrote: >> Python missed the switch to DST here, the timezone is wrong. > > Because you didn't let it use any timezone information. You need to > either use the third-party 'pytz' module, or in Python 3.9 or above, > the built-in

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-16 Thread Jon Ribbens via Python-list
On 2022-04-16, Peter J. Holzer wrote: > On 2022-04-14 15:22:29 -0000, Jon Ribbens via Python-list wrote: >> On 2022-04-14, Paul Bryan wrote: >> > I think because minutes and hours can easily be composed by multiplying >> > seconds. days is separate because you canno

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-14 Thread Jon Ribbens via Python-list
On 2022-04-14, MRAB wrote: > On 2022-04-14 16:22, Jon Ribbens via Python-list wrote: >> On 2022-04-14, Paul Bryan wrote: >>> I think because minutes and hours can easily be composed by multiplying >>> seconds. days is separate because you cannot compose days fro

Re: Why does datetime.timedelta only have the attributes 'days' and 'seconds'?

2022-04-14 Thread Jon Ribbens via Python-list
On 2022-04-14, Paul Bryan wrote: > I think because minutes and hours can easily be composed by multiplying > seconds. days is separate because you cannot compose days from seconds; > leap seconds are applied to days at various times, due to > irregularities in the Earth's rotation. That's an

Re: Behavior of the for-else construct

2022-03-03 Thread Jon Ribbens via Python-list
On 2022-03-03, computermaster360 wrote: > Do you find the for-else construct useful? Have you used it in > practice? Yes, I use it frequently. > I have used it maybe once. My issue with this construct is that > calling the second block `else` doesn't make sense; a much more > sensible name

Re: keep getting a syntax error on the very first program I am running

2022-01-14 Thread Jon Ribbens via Python-list
On 2022-01-15, Bob Griffin wrote: >I am running this program and keep getting this error. Is this normal? > >Invalid syntax. Perhaps you forgot a comma? > >Also the t in tags is highlighted. > >I even tried different versions of Python also. > >Python 3.10.1

Re: Short, perfect program to read sentences of webpage

2021-12-08 Thread Jon Ribbens via Python-list
On 2021-12-08, Julius Hamilton wrote: > 1. The HTML extraction is not perfect. It doesn’t produce as clean text as > I would like. Sometimes random links or tags get left in there. And the > sentences are sometimes randomly broken by newlines. Oh. Leaving tags in suggests you are doing this very

Re: copy.copy

2021-11-22 Thread Jon Ribbens via Python-list
On 2021-11-22, ast wrote: > Hi, > > >>> a = 6 > >>> b = 6 > >>> a is b > True > > ok, we all know that Python creates a sole instance > with small integers, but: > > >>> import copy > >>> b = copy.copy(a) > >>> a is b > True > > I was expecting False Why did you expect False? For immutable

Re: Proliferation of Python packaging formats

2021-11-17 Thread Jon Ribbens via Python-list
On 2021-11-17, Skip Montanaro wrote: > Is the proliferation of packaging formats in Python as nutzo as this author > believes? > > https://drewdevault.com/2021/11/16/Python-stop-screwing-distros-over.html > > Asking because I've never been in the business of releasing "retail" Python >

Re: Avoid nested SIGINT handling

2021-11-10 Thread Jon Ribbens via Python-list
On 2021-11-10, Paulo da Silva wrote: > Hi! > > How do I handle a SIGINT (or any other signal) avoid nesting? I don't think you need to. Python will only call signal handlers in the main thread, so a handler can't be executed while another handler is running anyway. --

Re: Get a Joke in Python

2021-10-28 Thread Jon Ribbens via Python-list
On 2021-10-28, Greg Ewing wrote: > On 29/10/21 11:34 am, Chris Angelico wrote: >> On Fri, Oct 29, 2021 at 7:31 AM Mostowski Collapse >> wrote: >>> QA engineer walks into a bar. Orders a beer. Orders 0 beers. >>> Orders 9 beers. Orders a lizard. Orders -1 beers. >>> Orders a sfdeljknesv.

Re: New assignmens ...

2021-10-28 Thread Jon Ribbens via Python-list
On 2021-10-28, Paul Rubin wrote: > Chris Angelico writes: >> But it all depends on the exact process being done, which is why I've >> been asking for real examples. > > My most frequent use case for walrus is so common that I have sometimes > implemented a special class for it: > >if g :=

Re: New assignmens ...

2021-10-23 Thread Jon Ribbens via Python-list
On 2021-10-23, Chris Angelico wrote: > On Sun, Oct 24, 2021 at 4:39 AM Jon Ribbens via Python-list > wrote: >> On 2021-10-23, Chris Angelico wrote: >> > In what situations do you need to mutate an attribute and also test >> > it, and how much hassle is it to simp

Re: New assignmens ...

2021-10-23 Thread Jon Ribbens via Python-list
On 2021-10-23, Chris Angelico wrote: > I've never used ctr:=ctr-1 either, though, so I don't know the actual > use cases. Why is this being used in an assignment expression? Is it > an ersatz loop? > > Common use-cases include: > > if m := re.match(...): > > while data := thing.read(): > > etc.

  1   2   >