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

2022-11-23 Thread Chris Angelico
On Thu, 24 Nov 2022 at 06:26, Stefan Ram wrote: > > Jon Ribbens writes: > >If you want to catch this sort of mistake automatically then you need > >a linter such as pylint: > > output > > , line 1 > list.clear > Warning: Attribute used as statement. > > , line 5 > list.clear > Warning:

Re: Passing information between modules

2022-11-20 Thread Chris Angelico
On Mon, 21 Nov 2022 at 16:26, dn wrote: > Am put-off by the 'smell' of subverting/adapting names like print() = > surprise/confusion factor - but I think I understand where you're going. To be fair, redefining the "print" function IS one of the reasons that it's no longer a statement. Though I

Re: Passing information between modules

2022-11-20 Thread Chris Angelico
On Mon, 21 Nov 2022 at 09:37, Dan Kolis wrote: > > Using sys.stdout / is simply nonsense. The more I think about it, the more I > realise how bad it is. > > Going on about it endlessly seems pointless. > > If the even mini threading thing is turned on, now what ? some other module > eats the

Re: Logging

2022-11-19 Thread Chris Angelico
On Sun, 20 Nov 2022 at 12:27, Cameron Simpson wrote: > > On 19Nov2022 18:26, Thomas Passin wrote: > >>The alternative is to just replace every calling function which uses > >>my_ugly_debug() to directly call a logging.whatever() call. > > > >Maybe a place for a decorator... > > Indeed, though I

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

2022-11-15 Thread Chris Angelico
On Wed, 16 Nov 2022 at 10:11, wrote: > > That is clear, Cameron, but on my python interpreter values evaluated on the > command line ARE saved: > > >>> numb = 5 > >>> 5 + numb > 10 > >>> numb > 5 > >>> _ + _ + 1 > 11 That's a REPL feature. ChrisA --

Re: Are these good ideas?

2022-11-14 Thread Chris Angelico
On Tue, 15 Nov 2022 at 09:38, Barry wrote: > > > > > On 14 Nov 2022, at 22:06, Thomas Passin wrote: > > > > For parameter passing like your #2, I have packaged them into a dictionary > > and passed that around. It was easy enough, and worked well. > > > I used to use a dict but having been

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

2022-11-14 Thread Chris Angelico
On Tue, 15 Nov 2022 at 05:57, Stefan Ram wrote: > > Michael Speer writes: > >Python doesn't care what an expression returns. > > In my English, functions return values, > expression are being evaluated to a value. > The evaluation of a function yields or > produces a value. Expressions

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

2022-11-13 Thread Chris Angelico
On Mon, 14 Nov 2022 at 18:00, Greg Ewing wrote: > > On 14/11/22 3:13 pm, MRAB wrote: > > But if it's an expression where it's expecting a statement and it's not > > a call, then it's probably a bug. > > The key word there is "probably". If there's any chance it > could be not a bug, it can't be

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

2022-11-13 Thread Chris Angelico
On Mon, 14 Nov 2022 at 13:18, MRAB wrote: > > On 2022-11-14 00:55, 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. > > > >

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

2022-11-13 Thread Chris Angelico
On Mon, 14 Nov 2022 at 11:53, 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

Re: Persisting functions typed into the shell

2022-11-12 Thread Chris Angelico
On Sun, 13 Nov 2022 at 05:48, Stefan Ram wrote: > So much for the topic of "In Python, /everything/ is an > object"! There seem to be first and second-class objects: > Shelveable and non-shelveable objects. > That's a bit unfair. Everything IS an object, but not all objects can be treated

Re: Argument name should be lowercase

2022-11-11 Thread Chris Angelico
On Sat, 12 Nov 2022 at 06:42, Stefan Ram wrote: > > "Weatherby,Gerard" writes: > >I'd personally find it weird to see an all-cap parameter > > In the source code of the standard library, all-caps > notation is used for a parameter name sometimes > if that parameter name is "URL" or

Re: What's tkinter doing in \Lib\site-packages\future\moves ?

2022-11-07 Thread Chris Angelico
On Tue, 8 Nov 2022 at 15:12, DFS wrote: > > 3.9.13 > My guess? Because you can "import tkinter" in Py3 but "import Tkinter" in Py2. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Chris Angelico
On Tue, 8 Nov 2022 at 08:44, Chris Green wrote: > > Barry Scott wrote: > > > > > > > On 7 Nov 2022, at 09:28, Chris Green wrote: > > > > > > Chris Green wrote: > > >>> 3: with your pseudo "python3" script in place, make all the scripts use > > >>> the "#!/usr/bin/env python3" shebang suggested

Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Chris Angelico
On Tue, 8 Nov 2022 at 06:12, Thomas Passin wrote: > > The problem is that some Linux systems - I think - still use Python2 to > perform various system-related tasks. When they call "python", they > need it to be Python2. If someone has a system like that, they can't > have the "python" command

Re: Operator: inappropriate wording?

2022-11-04 Thread Chris Angelico
On Thu, 3 Nov 2022 at 10:17, elas tica wrote: > > Le lundi 31 octobre 2022 à 22:18:57 UTC+1, Chris Angelico a ecrit : > > Wording is hard. Just ask the SQL standard whether NULL is a value. > > > > Indeed, but I think our problem here is simpler ;) > > One could

Re: an oop question

2022-11-04 Thread Chris Angelico
On Sat, 5 Nov 2022 at 02:18, Greg Ewing wrote: > > On 4/11/22 12:50 am, Chris Angelico wrote: > > In Python, everything is an object. Doesn't that equally mean that > > Python is purely OOP? > > Depends on what you mean by "purely oop". To me it suggests

Re: an oop question

2022-11-04 Thread Chris Angelico
On Sat, 5 Nov 2022 at 02:21, Greg Ewing wrote: > > > r...@zedat.fu-berlin.de (Stefan Ram) writes [that Barbara Liskov said]: > > > >> |If for each object o1 of type S there is an object o2 of > >> |type T such that for all programs P defined in terms of T, > >> |the behavior of P is unchanged

Re: typing: property/setter and lists? [RESOLVED ERRATA]

2022-11-03 Thread Chris Angelico
On Fri, 4 Nov 2022 at 05:48, Paulo da Silva wrote: > > Às 05:32 de 03/11/22, Paulo da Silva escreveu: > > Às 03:24 de 03/11/22, Paulo da Silva escreveu: > >> Hi! > >> > >> And a typing problem again!!! > >> ___ > >> class C: > >> def __init__(self): > >>

Re: an oop question

2022-11-03 Thread Chris Angelico
On Fri, 4 Nov 2022 at 05:21, Julieta Shem wrote: > > Chris Angelico writes: > > > On Thu, 3 Nov 2022 at 21:44, Alan Gauld wrote: > >> Also Python is not a purely OOP language, in that you can write > >> functional and procedural code in Python if you wish. I

Re: typing: property/setter and lists? [RESOLVED]

2022-11-03 Thread Chris Angelico
On Fri, 4 Nov 2022 at 05:03, Paulo da Silva wrote: > Changing def foos(self) -> list[int]: to > def foos(self) -> Union[list[int]]: > fixes the problem. > Not so elegant, however! Wait, what?! Union[X, Y] means "X or Y" Union[X] means "X, but don't complain if it's a @property". Is that how

Re: an oop question

2022-11-03 Thread Chris Angelico
On Thu, 3 Nov 2022 at 21:44, Alan Gauld wrote: > Also Python is not a purely OOP language, in that you can write > functional and procedural code in Python if you wish. In > Smalltalk thats notionally impossible because everything > is an object. And all programming statements are messages > to

Re: Operator: inappropriate wording?

2022-10-31 Thread Chris Angelico
On Tue, 1 Nov 2022 at 08:15, elas tica wrote: > > Le mercredi 26 octobre 2022 à 22:12:59 UTC+2, Weatherby,Gerard a ecrit : > > No. If the docs say in one place a comma is not an operator, they shouldn’t > > call it an operator in another place. > > > > I’ve submitted a pull request

Re: an oop question

2022-10-30 Thread Chris Angelico
On Mon, 31 Oct 2022 at 14:38, Julieta Shem wrote: > > Chris Angelico writes: > > > The most straight-forward way to represent this concept in an > > object-oriented way is subclassing. > > > > class Stack: > > ... # put whatever code i

Re: Fwd: A typing question

2022-10-30 Thread Chris Angelico
On Mon, 31 Oct 2022 at 09:39, dn wrote: > > On 31/10/2022 06.06, Stefan Ram wrote: > > Paulo da Silva writes: > >> Is there anything to do without loosing my script structure and usual > >> practice? > > > >to lose (losing): to stop having something > >to loose (loosing): to let or make

Re: an oop question

2022-10-30 Thread Chris Angelico
On Mon, 31 Oct 2022 at 09:05, Julieta Shem wrote: > > Julieta Shem writes: > > [...] > > >> . If you should, however, be talking about the new "type hints": > >> These are static and have "Union", for example, "Union[int, str]" > >> or "int | str". > > > > I ended up locating such features

Re: UTF-8 and latin1

2022-10-25 Thread Chris Angelico
On Wed, 26 Oct 2022 at 05:09, Barry Scott wrote: > > > > > On 25 Oct 2022, at 11:16, Stefan Ram wrote: > > > > r...@zedat.fu-berlin.de (Stefan Ram) writes: > >> You can let Python guess the encoding of a file. > >> def encoding_of( name ): > >> path = pathlib.Path( name ) > >> for encoding in(

Re: Beautiful Soup - close tags more promptly?

2022-10-25 Thread Chris Angelico
On Wed, 26 Oct 2022 at 04:59, Tim Delaney wrote: > > On Mon, 24 Oct 2022 at 19:03, Chris Angelico wrote: >> >> >> Ah, cool. Thanks. I'm not entirely sure of the various advantages and >> disadvantages of the different parsers; is there a tabulation &

Re: Beautiful Soup - close tags more promptly?

2022-10-24 Thread Chris Angelico
On Tue, 25 Oct 2022 at 09:34, Peter J. Holzer wrote: > > One thing I find quite interesting, though, is the way that browsers > > *differ* in the face of bad nesting of tags. Recently I was struggling > > to figure out a problem with an HTML form, and eventually found that > > there was a

Re: Beautiful Soup - close tags more promptly?

2022-10-24 Thread Chris Angelico
On Tue, 25 Oct 2022 at 04:22, Peter J. Holzer wrote: > There may be several reasons: > > * Historically, some browsers differed in which end tags were actually > optional. Since (AFAIK) no mainstream browser ever implemented a real > SGML parser (they were always "tag soup" parsers with lots

Re: Beautiful Soup - close tags more promptly?

2022-10-24 Thread Chris Angelico
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 wanted to say was that this is indeed a bug in > >> html.parser and not a

Re: Beautiful Soup - close tags more promptly?

2022-10-24 Thread Chris Angelico
On Mon, 24 Oct 2022 at 23:22, Peter J. Holzer wrote: > > On 2022-10-24 21:56:13 +1100, Chris Angelico wrote: > > On Mon, 24 Oct 2022 at 21:33, Peter J. Holzer wrote: > > > Ron has already noted that the lxml and html5 parser do the right thing, > > > so just for th

Re: Beautiful Soup - close tags more promptly?

2022-10-24 Thread Chris Angelico
On Mon, 24 Oct 2022 at 21:33, Peter J. Holzer wrote: > Ron has already noted that the lxml and html5 parser do the right thing, > so just for the record: > > The HTML fragment above is well-formed and contains a number of li > elements at the same level directly below the ol element, not lots of

Re: Beautiful Soup - close tags more promptly?

2022-10-24 Thread Chris Angelico
On Mon, 24 Oct 2022 at 18:43, Roel Schroeven wrote: > > Op 24/10/2022 om 4:29 schreef Chris Angelico: > > Parsing ancient HTML files is something Beautiful Soup is normally > > great at. But I've run into a small problem, caused by this sort of > > sloppy HTML:

Re: Typing: Is there a "cast operator"?

2022-10-23 Thread Chris Angelico
On Mon, 24 Oct 2022 at 14:15, Dan Stromberg wrote: > I've found that mypy understands simple assert statements. > > So if you: > if f is not None: > assert f is not None > os.write(f, ...) > > You might be in good shape. Why can't it simply understand the if statement? I'm not a

Beautiful Soup - close tags more promptly?

2022-10-23 Thread Chris Angelico
Parsing ancient HTML files is something Beautiful Soup is normally great at. But I've run into a small problem, caused by this sort of sloppy HTML: from bs4 import BeautifulSoup # See: https://gsarchive.net/gilbert/plays/princess/tennyson/tenniv.htm blob = b""" 'THERE sinks the nebulous star we

Re: Portable executable on OSX

2022-10-20 Thread Chris Angelico
On Fri, 21 Oct 2022 at 08:50, Thomas Passin wrote: > > "Portable executable" usually means that the program resides on > removable media, like a USB stick. You can go to a computer, plug the > stick in, and run the program. If it's Python, then the installation on > the removable medium needs

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

2022-10-18 Thread Chris Angelico
On Wed, 19 Oct 2022 at 12:01, Peter J. Holzer wrote: > > On 2022-10-17 09:25:00 +0200, Karsten Hilbert wrote: > > > which had special combinations for all the BASIC keywords). And if you > > > go this way, why not go a step further and dissociate the program from > > > its linear text

Re: Quick question about CPython interpreter

2022-10-17 Thread Chris Angelico
On Tue, 18 Oct 2022 at 03:51, Stefan Ram wrote: > > MRAB writes: > >It can't optimise that because, say, 'print' could've been bound to a > >function that rebinds 'str'. > > It would be possible to find out whether a call of a function > named "print" is to the standard function, but the

Re: Optional arguments in a class behave like class attributes.

2022-10-17 Thread Chris Angelico
On Tue, 18 Oct 2022 at 01:39, Abderrahim Adrabi wrote: > So, these default values behave like class attributes, here is a demo: > > # Using a list - > class GameOne: > def __init__(self, games = []) -> None: > self.games = games > This makes the default be a

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

2022-10-17 Thread Chris Angelico
On Mon, 17 Oct 2022 at 16:36, Antoon Pardon wrote: > > > > Op 17/10/2022 om 04:01 schreef Chris Angelico: > > On Mon, 17 Oct 2022 at 10:46, wrote: > >> My point Chris was that you can have a conversation where you are exploring > >> and not proposing. Brai

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

2022-10-16 Thread Chris Angelico
On Mon, 17 Oct 2022 at 10:46, wrote: > > My point Chris was that you can have a conversation where you are exploring > and not proposing. Brainstorming, perhaps. And my point is that either a proposal is a serious one that can expect serious discussion, or it isn't. Yes, I'm aware that it wasn't

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

2022-10-16 Thread Chris Angelico
On Mon, 17 Oct 2022 at 08:22, wrote: > I had another crazy thought that I AM NOT ASKING anyone to do. OK? > Here's another proposal: Let's ban you from this mailing list. Don't worry, I AM NOT ASKING anyone to do it. OK? Do you see how ridiculous and pointless it is to have proposals with that

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

2022-10-16 Thread Chris Angelico
On Mon, 17 Oct 2022 at 03:57, Antoon Pardon wrote: > > > Op 16/10/2022 om 17:05 schreef Chris Angelico: > > On Sun, 16 Oct 2022 at 22:47, Antoon Pardon wrote: > >> Why would I need good luck? I expressed an idea and you didn't like it. > >> That won't affect my l

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

2022-10-16 Thread Chris Angelico
On Sun, 16 Oct 2022 at 22:47, Antoon Pardon wrote: > > > > Op 16/10/2022 om 13:03 schreef Chris Angelico: > > On Sun, 16 Oct 2022 at 21:19, Antoon Pardon wrote: > > > >> My idea would be to reserve different unicode blocks for the keywords > >>

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

2022-10-16 Thread Chris Angelico
On Sun, 16 Oct 2022 at 21:19, Antoon Pardon wrote: > > Op 16/10/2022 om 00:50 schreef avi.e.gr...@gmail.com: > > This has been discussed so often precisely because I swear NO CHOICE of > > keyword would satisfy everybody! Most languages start with designated > > keywords and some reserve a few

Re: What to use for finding as many syntax errors as possible.

2022-10-12 Thread Chris Angelico
On Thu, 13 Oct 2022 at 11:23, dn wrote: > # add an extra character within identifier, as if 'new' identifier > 28 assert expected_value == fyibonacci_number > UUU > > # these all trivial SYNTAX errors - could have tried leaving-out a > keyword,

Re: What to use for finding as many syntax errors as possible.

2022-10-12 Thread Chris Angelico
On Thu, 13 Oct 2022 at 11:19, Peter J. Holzer wrote: > > On 2022-10-11 09:47:52 +1100, Chris Angelico wrote: > > On Tue, 11 Oct 2022 at 09:18, Cameron Simpson wrote: > > > > > Consider: > > > > if condition # no colon > > code > > else: >

Re: What to use for finding as many syntax errors as possible.

2022-10-11 Thread Chris Angelico
On Wed, 12 Oct 2022 at 05:23, Thomas Passin wrote: > > On 10/11/2022 3:10 AM, avi.e.gr...@gmail.com wrote: > > I see resemblances to something like how a web page is loaded and operated. > > I mean very different but at some level not so much. > > > > I mean a typical web page is read in as HTML

Re: What to use for finding as many syntax errors as possible.

2022-10-11 Thread Chris Angelico
On Tue, 11 Oct 2022 at 18:12, wrote: > > Thanks for a rather detailed explanation of some of what we have been > discussing, Chris. The overall outline is about what I assumed was there but > some of the details were, to put it politely, fuzzy. > > I see resemblances to something like how a web

Re: What to use for finding as many syntax errors as possible.

2022-10-10 Thread Chris Angelico
On Tue, 11 Oct 2022 at 14:26, wrote: > > I stand corrected Chris, and others, as I pay the sin tax. > > Yes, there are many kinds of errors that logically fall into different > categories or phases of evaluation of a program and some can be determined > by a more static analysis almost on a line

Re: What to use for finding as many syntax errors as possible.

2022-10-10 Thread Chris Angelico
On Tue, 11 Oct 2022 at 14:13, wrote: > With the internet today, we are used to expecting error correction to come > for free. Do you really need one of every 8 bits to be a parity bit, which > only catches may half of the errors... Fortunately, we have WAY better schemes than simple parity,

Re: What to use for finding as many syntax errors as possible.

2022-10-10 Thread Chris Angelico
On Tue, 11 Oct 2022 at 13:10, wrote: > If the above is: > > Import grumpy as np > > Then what happens if the code tries to find a file named "grumpy" somewhere > and cannot locate it and this is considered a syntax error rather than a > run-time error for whatever reason? Can you continue when

Re: What to use for finding as many syntax errors as possible.

2022-10-10 Thread Chris Angelico
On Tue, 11 Oct 2022 at 09:18, Cameron Simpson wrote: > > On 11Oct2022 08:02, Chris Angelico wrote: > >There's a huge difference between non-fatal errors and syntactic > >errors. The OP wants the parser to magically skip over a fundamental > >syntactic error and sti

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

2022-10-10 Thread Chris Angelico
On Tue, 11 Oct 2022 at 08:55, Robert Latest via Python-list wrote: > > Chris Angelico wrote: > > Yes, I'm aware that code readability becomes irrelevant for > > short-duration projects. Beside the point. I'm wondering how important > > it really is to have the shortest bl

Re: What to use for finding as many syntax errors as possible.

2022-10-10 Thread Chris Angelico
On Tue, 11 Oct 2022 at 06:34, Peter J. Holzer wrote: > > On 2022-10-10 09:23:27 +1100, Chris Angelico wrote: > > On Mon, 10 Oct 2022 at 06:50, Antoon Pardon wrote: > > > I just want a parser that doesn't give up on encoutering the first syntax > > > error. Maybe

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

2022-10-10 Thread Chris Angelico
On Mon, 10 Oct 2022 at 22:37, Axy via Python-list wrote: > > > On 10/10/2022 12:24, Chris Angelico wrote: > > On Mon, 10 Oct 2022 at 21:57, Axy via Python-list > > wrote: > >> > >>> Not sure what you mean, but a for-else without a break is quite > &

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

2022-10-10 Thread Chris Angelico
On Mon, 10 Oct 2022 at 21:57, Axy via Python-list wrote: > > > > Not sure what you mean, but a for-else without a break is quite > > useless. What exactly ARE you arguing here? > > > > The else is associated with the break to the exact extent that one is > > essential to the other's value. > >

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

2022-10-10 Thread Chris Angelico
On Mon, 10 Oct 2022 at 20:56, Axy via Python-list wrote: > > > The else is always coming with the break, not the for. > However, the compiler does not complain. > > There are [for ...], [for...break...], and[for...break...else], > > That's implied and contradicts Zen of Python, I think. If

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

2022-10-10 Thread Chris Angelico
On Mon, 10 Oct 2022 at 20:46, Karsten Hilbert wrote: > > Am Sun, Oct 09, 2022 at 09:58:14AM + schrieb Stefan Ram: > > > I often follow this rule. For me, it's about readability. Compare: > > > > if not open( disk ): > > error( "Can't open disk" ) > > else: > > printf( "now imagine

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

2022-10-09 Thread Chris Angelico
On Mon, 10 Oct 2022 at 14:59, wrote: > > >>>Which is more disparaging: "I couldn't find anyone suggesting this" or > "The only place I could find it was a PHP style guide"? > >>>ChrisA > > Chris, > > If someone says they heard something from their own personal guru, people > often do not feel

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

2022-10-09 Thread Chris Angelico
On Mon, 10 Oct 2022 at 11:52, MRAB wrote: > > On 2022-10-10 00:40, dn wrote: > > On Sun, 9 Oct 2022 at 15:39, Axy via Python-list > > wrote: > > > >> "shortest block first" > > > > Have never heard this advice before. Kind-of rankled with me, as it did > > for others. > > > > Enquiring minds

Re: What to use for finding as many syntax errors as possible.

2022-10-09 Thread Chris Angelico
On Mon, 10 Oct 2022 at 06:50, Antoon Pardon wrote: > I just want a parser that doesn't give up on encoutering the first syntax > error. Maybe do some semantic checking like checking the number of parameters. That doesn't make sense though. It's one thing to keep going after finding a

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

2022-10-09 Thread Chris Angelico
On Mon, 10 Oct 2022 at 03:46, Avi Gross wrote: > > Chris, I was not arguing that at all. Maybe not intentionally, but you did lend a lot of weight to that argument :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list

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

2022-10-09 Thread Chris Angelico
On Mon, 10 Oct 2022 at 03:22, Avi Gross wrote: > > Smallest code blocks first may be a more modern invention. > > Some would argue for a rule related to efficiency of execution. When you > have multiple blocks as in an if-else or case statement with multiple > choices, that you order the most

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

2022-10-08 Thread Chris Angelico
On Sun, 9 Oct 2022 at 16:05, Axy via Python-list wrote: > > > On 09/10/2022 05:47, Chris Angelico wrote: > > On Sun, 9 Oct 2022 at 15:39, Axy via Python-list > > wrote: > >> Got it, thanks! > >> > >> Actually the reason I never used "else&qu

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

2022-10-08 Thread Chris Angelico
On Sun, 9 Oct 2022 at 15:39, Axy via Python-list wrote: > > Got it, thanks! > > Actually the reason I never used "else" was the violation of the rule of > beauty "shortest block first". With if--else you can easily follow this > rule by inverting "if" expression, but with for--else you can't. The

Re: Debugging automatic quotation in subprocess.Popen()

2022-10-07 Thread Chris Angelico
On Sat, 8 Oct 2022 at 08:24, wrote: > > Hello, > > I need to improve my understanding about how subprocess.Popen() does > quote arguments. I have special case here. > > Simple example: > Popen(['ls', '-l']) results on a shell in "ls -l" without quotation. > > Quotes are added if they are needed:

Re: Implementation of an lru_cache() decorator that ignores the first argument

2022-09-28 Thread Chris Angelico
On Thu, 29 Sept 2022 at 05:36, Robert Latest via Python-list wrote: > in a (Flask) web application I often find that many equal (SQLAlchemy) queries > are executed across subsequent requests. So I tried to cache the results of > those queries on the module level like this: > > @lru_cache() >

Re: on implementing a toy oop-system

2022-09-23 Thread Chris Angelico
On Sat, 24 Sept 2022 at 07:52, Meredith Montgomery wrote: > > def Counter(name = None): > o = {"name": name if name else "untitled", "n": 0} > def inc(o): > o["n"] += 1 > return o > o["inc"] = inc > def get(o): > return o["n"] > o["get"] = get > return o > Want a neat

Re: How to get the current set LOG_MASK in Python's syslog module?

2022-09-22 Thread Chris Angelico
On Thu, 22 Sept 2022 at 23:46, Richard Moseley wrote: > > According to documentation syslog.setlogmask returns the current mask so > save the value to reset later on. > > Oldval = syslog.setlogmask(newmask) > > This sets oldval to original mask. This on its own suggests an odd technique that

Re: How to replace an instance method?

2022-09-17 Thread Chris Angelico
On Sun, 18 Sept 2022 at 10:29, wrote: > > > From your description, Chris, it sounds like the functional programming > technique often called currying. A factory function is created where one (or > more) parameters are sort of frozen in so the user never sees or cares about > them, and a modified

Re: How to replace an instance method?

2022-09-17 Thread Chris Angelico
On Sun, 18 Sept 2022 at 09:37, Eryk Sun wrote: > > On 9/17/22, Chris Angelico wrote: > > > > The two are basically equivalent. Using functools.partial emphasizes > > the fact that all you're doing is "locking in" the first parameter; > > usin

Re: How to replace an instance method?

2022-09-17 Thread Chris Angelico
On Sun, 18 Sept 2022 at 07:20, Ralf M. wrote: > > Am 16.09.2022 um 23:34 schrieb Eryk Sun: > > On 9/16/22, Ralf M. wrote: > >> I would like to replace a method of an instance, but don't know how to > >> do it properly. > > > > A function is a descriptor that binds to any object as a method. For

Re: How to replace an instance method?

2022-09-16 Thread Chris Angelico
On Sat, 17 Sept 2022 at 07:07, Ralf M. wrote: > > I would like to replace a method of an instance, but don't know how to > do it properly. > > My first naive idea was > > inst = SomeClass() > def new_method(self, param): > # do something > return whatever > inst.method = new_method > >

Re: Question about learning Python

2022-09-09 Thread Chris Angelico
On Sat, 10 Sept 2022 at 06:45, Dennis Lee Bieber wrote: > > On Thu, 8 Sep 2022 07:42:19 +1200, dn > declaimed the following: > > >TSRs? Now that was an ugly period of history! (trying to make a > >single-process operating system do multi-processing - only to find that > >many program[me]s

Re: Question about learning Python

2022-09-09 Thread Chris Angelico
On Sat, 10 Sept 2022 at 06:38, Greg Ewing wrote: > > On 8/09/22 6:57 am, Chris Angelico wrote: > > Not as detrimental as starting with BASIC, and then moving on to x86 > > assembly language, and trying to massage the two together using CALL > > ABSOLUTE in order to ge

Re: Question about learning Python

2022-09-07 Thread Chris Angelico
On Thu, 8 Sept 2022 at 05:09, Grant Edwards wrote: > > On 2022-09-07, Chris Angelico wrote: > > On Thu, 8 Sept 2022 at 04:54, Grant Edwards > > wrote: > > > >> If you're a beginning programmer, then IMO learning C first is > >> probably detrimental. [.

Re: Question about learning Python

2022-09-07 Thread Chris Angelico
On Thu, 8 Sept 2022 at 04:54, Grant Edwards wrote: > > On 2022-09-07, Chris Angelico wrote: > > On Thu, 8 Sept 2022 at 01:50, Maruful Islam wrote: > >> > >> I want to start learning python. I have a question about learning python. > >> > >> Is

Re: Question about learning Python

2022-09-07 Thread Chris Angelico
On Thu, 8 Sept 2022 at 01:50, Maruful Islam wrote: > > I want to start learning python. I have a question about learning python. > > Is learning C essential or not for learning python? Absolutely not essential. In fact, I would strongly recommend learning Python before ever picking up C, as it's

Re: on str.format and f-strings

2022-09-06 Thread Chris Angelico
On Wed, 7 Sept 2022 at 03:52, Meredith Montgomery wrote: > > It seems to me that str.format is not completely made obsolete by the > f-strings that appeared in Python 3.6. But I'm not thinking that this > was the objective of the introduction of f-strings: the PEP at > >

Re: Local variable definition in Python list comprehension

2022-09-01 Thread Chris Angelico
On Fri, 2 Sept 2022 at 06:55, James Tsai wrote: > > 在 2022年9月1日星期四 UTC+2 18:34:36, 写道: > > On 9/1/22, James Tsai wrote: > > > > > > I find it very useful if I am allowed to define new local variables in a > > > list comprehension. For example, I wish to have something like > > > [(x, y) for x in

Re: Local variable definition in Python list comprehension

2022-09-01 Thread Chris Angelico
On Fri, 2 Sept 2022 at 02:10, James Tsai wrote: > > Hello, > > I find it very useful if I am allowed to define new local variables in a list > comprehension. For example, I wish to have something like > [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or > [(x, y) for x in range(10)

Re: Running two separate servers (was Re: venv questions)

2022-08-30 Thread Chris Angelico
On Tue, 30 Aug 2022 at 19:51, gene heskett wrote: > So I'm thinking of venv's named rock64prusa, and rock64ender5+, each with > "port#" on my local net. So chromium could have two tabs open, one to > localhost:5000 and one to localhost:5001, totally independent of each other. > As I said, that

Running two separate servers (was Re: venv questions)

2022-08-29 Thread Chris Angelico
On Tue, 30 Aug 2022 at 12:59, gene heskett wrote: > > But that might create another problem. how to differentiate the servers, > both of which > will want to use localhost:5000 to serve up their web pages we run > things with. > > Suggested solutions? This is nothing to do with venvs, so I'm

Re: venv questions

2022-08-29 Thread Chris Angelico
On Tue, 30 Aug 2022 at 12:59, gene heskett wrote: > > Greetings all; > > The command to setup a venv, "python -m venv venv" has no man page that > I have > found. > $ python3 -m venv --help usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade]

Re: How to make a variable's late binding crosses the module boundary?

2022-08-29 Thread Chris Angelico
On Tue, 30 Aug 2022 at 02:38, Jach Feng wrote: > > Chris Angelico 在 2022年8月29日 星期一下午1:58:58 [UTC+8] 的信中寫道: > > On Mon, 29 Aug 2022 at 15:54, Jach Feng wrote: > > > > > > Richard Damon 在 2022年8月29日 星期一上午10:47:08 [UTC+8] 的信中寫道: > > > > On 8/27/22 7:42

Re: How to make a variable's late binding crosses the module boundary?

2022-08-29 Thread Chris Angelico
On Mon, 29 Aug 2022 at 15:54, Jach Feng wrote: > > Richard Damon 在 2022年8月29日 星期一上午10:47:08 [UTC+8] 的信中寫道: > > On 8/27/22 7:42 AM, Mark Bourne wrote: > > > Jach Feng wrote: > > >> I have two files: test.py and test2.py > > >> --test.py-- > > >> x = 2 > > >> def foo(): > > >> print(x) > > >>

Re: What can I do about this?

2022-08-28 Thread Chris Angelico
On Mon, 29 Aug 2022 at 08:41, gene heskett wrote: > > Greatings all; > > Persuant to my claim the py3.10 is busted, here is a sample. This is me, > trying to make > pronterface, inside a venv: When the package manager version will only > run the gui-less "pronsole" > but nothing else from that

Re: subprocess.popen how wait complete open process

2022-08-21 Thread Chris Angelico
On Mon, 22 Aug 2022 at 13:41, Dan Stromberg wrote: > > > > On Sun, Aug 21, 2022 at 2:05 PM Chris Angelico wrote: >> >> On Mon, 22 Aug 2022 at 05:39, simone zambonardi >> wrote: >> > >> > Hi, I am running a program with the punishment subroc

Re: Mutating an HTML file with BeautifulSoup

2022-08-21 Thread Chris Angelico
On Mon, 22 Aug 2022 at 10:04, Buck Evan wrote: > > I've had much success doing round trips through the lxml.html parser. > > https://lxml.de/lxmlhtml.html > > I ditched bs for lxml long ago and never regretted it. > > If you find that you have a bunch of invalid html that lxml inadvertently >

Re: Mutating an HTML file with BeautifulSoup

2022-08-21 Thread Chris Angelico
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 Angelico wrote: > >> > On Sun,

Re: subprocess.popen how wait complete open process

2022-08-21 Thread Chris Angelico
On Mon, 22 Aug 2022 at 05:39, simone zambonardi wrote: > > Hi, I am running a program with the punishment subrocess.Popen(...) what I > should do is to stop the script until the launched program is fully open. How > can I do this? I used a time.sleep() function but I think there are other >

Re: Mutating an HTML file with BeautifulSoup

2022-08-21 Thread Chris Angelico
On Sun, 21 Aug 2022 at 17:26, Barry wrote: > > > > > On 19 Aug 2022, at 22:04, Chris Angelico wrote: > > > > On Sat, 20 Aug 2022 at 05:12, Barry wrote: > >> > >> > >> > >>>> On 19 Aug 2022, at 19:33, Chris Angelico wrote: &

Re: Mutating an HTML file with BeautifulSoup

2022-08-20 Thread Chris Angelico
On Sun, 21 Aug 2022 at 13:41, dn wrote: > > On 21/08/2022 13.00, Chris Angelico wrote: > > Well, I don't like headaches, but I do appreciate what the G Archive > > has given me over the years, so I'm taking this on as a means of > > giving back to the community. > >

Re: Mutating an HTML file with BeautifulSoup

2022-08-20 Thread Chris Angelico
On Sun, 21 Aug 2022 at 09:48, dn wrote: > > On 20/08/2022 12.38, Chris Angelico wrote: > > On Sat, 20 Aug 2022 at 10:19, dn wrote: > >> On 20/08/2022 09.01, Chris Angelico wrote: > >>> On Sat, 20 Aug 2022 at 05:12, Barry wrote: > >>>>&

Re: Mutating an HTML file with BeautifulSoup

2022-08-20 Thread Chris Angelico
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: > >> >textual representations. That way, the followin

Re: Mutating an HTML file with BeautifulSoup

2022-08-20 Thread Chris Angelico
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 another document): > > The /elements/

Re: Mutating an HTML file with BeautifulSoup

2022-08-19 Thread Chris Angelico
On Sat, 20 Aug 2022 at 10:19, dn wrote: > > On 20/08/2022 09.01, Chris Angelico wrote: > > On Sat, 20 Aug 2022 at 05:12, Barry wrote: > >> > >> > >> > >>> On 19 Aug 2022, at 19:33, Chris Angelico wrote: > >>> > >>> Wh

Re: Mutating an HTML file with BeautifulSoup

2022-08-19 Thread Chris Angelico
On Sat, 20 Aug 2022 at 10:04, David wrote: > > On Sat, 20 Aug 2022 at 04:31, Chris Angelico wrote: > > > What's the best way to precisely reconstruct an HTML file after > > parsing it with BeautifulSoup? > > > Note two distinct changes: firstly, whitespace has

<    1   2   3   4   5   6   7   8   9   10   >