Re: Mutating an HTML file with BeautifulSoup

2022-08-19 Thread Chris Angelico
On Sat, 20 Aug 2022 at 05:12, Barry wrote: > > > > > On 19 Aug 2022, at 19:33, Chris Angelico wrote: > > > > What's the best way to precisely reconstruct an HTML file after > > parsing it with BeautifulSoup? > > I recall that in bs4 it parses i

Mutating an HTML file with BeautifulSoup

2022-08-19 Thread Chris Angelico
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 sisters; and their names were http://example.com/elsie;

Re: Problem using cx_Freeze > auto-py-to-exe

2022-08-18 Thread Chris Angelico
On Fri, 19 Aug 2022 at 10:07, Grant Edwards wrote: > > On 2022-08-18, Chris Angelico wrote: > > On Fri, 19 Aug 2022 at 05:05, Grant Edwards > > wrote: > >> On 2022-08-18, Chris Angelico wrote: > >> > >> > It's one of the frustrations w

Re: UTF-8 and latin1

2022-08-18 Thread Chris Angelico
On Fri, 19 Aug 2022 at 08:15, 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

Re: Problem using cx_Freeze > auto-py-to-exe

2022-08-18 Thread Chris Angelico
On Fri, 19 Aug 2022 at 05:05, Grant Edwards wrote: > > On 2022-08-18, Chris Angelico wrote: > > On Fri, 19 Aug 2022 at 04:19, David at Booomer wrote: > > > >> The trailing , does make commenting out arguments easier but > >> unexpected coming from ‘ol

Re: Problem using cx_Freeze > auto-py-to-exe

2022-08-18 Thread Chris Angelico
On Fri, 19 Aug 2022 at 04:19, David at Booomer wrote: > > This is really common in modern programming languages (read: programming > > languages younger than 30 years or so), because it makes it much more > > convenient to extend/shorten/reorder a list. Otherwise you alway have to > > remember

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

2022-08-16 Thread Chris Angelico
On Wed, 17 Aug 2022 at 07:05, Dan Stromberg wrote: > > Hi folks. > > I'm attempting to package up a python package that uses Cython. > > Rather than build binaries for everything under the sun, I've been focusing > on including the .pyx file and running cython on it at install time. This >

Re: Trying to understand nested loops

2022-08-06 Thread Chris Angelico
On Sat, 6 Aug 2022 at 22:39, Richard Damon wrote: > > On 8/6/22 8:12 AM, Chris Angelico wrote: > > On Sat, 6 Aug 2022 at 22:08, Richard Damon wrote: > >> On 8/6/22 12:01 AM, Chris Angelico wrote: > >>> On Sat, 6 Aug 2022 at 13:54, Dan Stromberg wrote: >

Re: Trying to understand nested loops

2022-08-06 Thread Chris Angelico
On Sat, 6 Aug 2022 at 22:08, Richard Damon wrote: > > On 8/6/22 12:01 AM, Chris Angelico wrote: > > On Sat, 6 Aug 2022 at 13:54, Dan Stromberg wrote: > >> On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards > >> wrote: > >> > >>> In C, thi

Re: Trying to understand nested loops

2022-08-05 Thread Chris Angelico
On Sat, 6 Aug 2022 at 13:54, Dan Stromberg wrote: > > On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards > wrote: > > > In C, this doesn't do what it looks like it's supposed to do. > > > >if (foo) > > do_this(); > > and_this(); > >then_do_this(); > > > It's been quite a while since

Re: Dictionary order?

2022-08-01 Thread Chris Angelico
On Tue, 2 Aug 2022 at 07:48, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2022-08-01 at 13:41:11 -0700, > Dan Stromberg wrote: > > > keys = [5, 10, 15, 14, 9, 4, 1, 2, 8, 6, 7, 12, 11] > > > > dict_ = {} > > for key in keys: > > dict_[key] = 1 > > $ python > Python 3.10.5 (main, Jun 6

Re: Dictionary order?

2022-08-01 Thread Chris Angelico
On Tue, 2 Aug 2022 at 06:50, Skip Montanaro wrote: > > > > > So I decided to write a little test program to run on a variety of > > CPythons, to confirm what I was thinking. > > > > And instead I got a surprise. > > > > On 1.4 through 2.1 I got descending key order. I expected the keys to be > >

Re: PEP about recommended project folder layout

2022-07-31 Thread Chris Angelico
On Sun, 31 Jul 2022 at 20:27, Weatherby,Gerard wrote: > > I’m not aware of any standard convention for laying out packages. > > PEP 8 (https://peps.python.org/pep-0008/) specifies conventions for how to > write Python, so a standard layout PEP would not be inconsistent. > PEP 8 species rules

Re: Simple TCP proxy

2022-07-29 Thread Chris Angelico
On Sat, 30 Jul 2022 at 04:54, Morten W. Petersen wrote: > > OK. > > Well, I've worked with web hosting in the past, and proxies like squid were > used to lessen the load on dynamic backends. There was also a website > opensourcearticles.com that we had with Firefox, Thunderbird articles etc.

Re: Simple TCP proxy

2022-07-28 Thread Chris Angelico
On Fri, 29 Jul 2022 at 11:42, Andrew MacIntyre wrote: > > On 29/07/2022 8:08 am, Chris Angelico wrote: > > It takes a bit of time to start ten thousand threads, but after that, > > the system is completely idle again until I notify them all and they > > shut down. > >

Re: Simple TCP proxy

2022-07-28 Thread Chris Angelico
On Fri, 29 Jul 2022 at 07:24, Morten W. Petersen wrote: > > Forwarding to the list as well. > > -- Forwarded message - > From: Morten W. Petersen > Date: Thu, Jul 28, 2022 at 11:22 PM > Subject: Re: Simple TCP proxy > To: Chris Angelico > > > W

Re: Simple TCP proxy

2022-07-28 Thread Chris Angelico
On Thu, 28 Jul 2022 at 21:01, Morten W. Petersen wrote: > > Well, I was thinking of following the socketserver / handle layout of code > and execution, for now anyway. > > It wouldn't be a big deal to make them block, but another option is to > increase the sleep period 100% for every 200

Re: Simple TCP proxy

2022-07-28 Thread Chris Angelico
On Thu, 28 Jul 2022 at 19:41, Morten W. Petersen wrote: > > Hi Martin. > > I was thinking of doing something with the handle function, but just this > little tweak: > > https://github.com/morphex/stp/commit/9910ca8c80e9d150222b680a4967e53f0457b465 > > made a huge difference in CPU usage.

Re: random.SystemRandom().randint() inefficient

2022-07-27 Thread Chris Angelico
On Thu, 28 Jul 2022 at 05:36, Cecil Westerhof via Python-list wrote: > > Roel Schroeven writes: > > > Cecil Westerhof via Python-list schreef op 27/07/2022 om 17:43: > >> "Michael F. Stemper" writes: > >> > >> > This is orthogonal to your question, but might be of some use to you: > >> > > >> >

Re: Simple TCP proxy

2022-07-27 Thread Chris Angelico
On Thu, 28 Jul 2022 at 04:32, Morten W. Petersen wrote: > > Hi Chris. > > You're thinking of the backlog argument of listen? Yes, precisely. > Well, STP will accept all connections, but can limit how many of the accepted > connections that are active at any given time. > > So when I bombed it

Re: Simple TCP proxy

2022-07-27 Thread Chris Angelico
On Thu, 28 Jul 2022 at 02:15, Morten W. Petersen wrote: > > Hi. > > I'd like to share with you a recent project, which is a simple TCP proxy > that can stand in front of a TCP server of some sort, queueing requests and > then allowing n number of connections to pass through at a time: How's this

Re: random.SystemRandom().randint() inefficient

2022-07-26 Thread Chris Angelico
On Wed, 27 Jul 2022 at 09:28, Dennis Lee Bieber wrote: > > On Tue, 26 Jul 2022 16:38:38 +0200, Cecil Westerhof > declaimed the following: > > >I need to get a random integer. At first I tried it with: > >from secrets import randbelow > >index = randbelow(len(to_try)) > > > >This works

Re: random.SystemRandom().randint() inefficient

2022-07-26 Thread Chris Angelico
On Wed, 27 Jul 2022 at 08:18, Cecil Westerhof via Python-list wrote: > > Chris Angelico writes: > > > On Wed, 27 Jul 2022 at 06:06, Cecil Westerhof via Python-list > > wrote: > >> > >> Chris Angelico writes: > >> > >> > O

Re: random.SystemRandom().randint() inefficient

2022-07-26 Thread Chris Angelico
On Wed, 27 Jul 2022 at 06:06, Cecil Westerhof via Python-list wrote: > > Chris Angelico writes: > > > On Wed, 27 Jul 2022 at 01:06, Cecil Westerhof via Python-list > > wrote: > >> > >> I need to get a random integer. At first I tried it with:

Re: random.SystemRandom().randint() inefficient

2022-07-26 Thread Chris Angelico
On Wed, 27 Jul 2022 at 01:06, Cecil Westerhof via Python-list wrote: > > I need to get a random integer. At first I tried it with: > from secrets import randbelow > index = randbelow(len(to_try)) > > This works perfectly, but it took some time. So I thought I try: > from random

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

2022-07-20 Thread Chris Angelico
On Wed, 20 Jul 2022 at 23:50, Peter Otten <__pete...@web.de> wrote: > > I found > > https://peps.python.org/pep-3101/ > > """ > PEP 3101 – Advanced String Formatting > ... > An example of the ‘getitem’ syntax: > > "My name is {0[name]}".format(dict(name='Fred')) > > It should be noted that the use

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

2022-07-20 Thread Chris Angelico
On Wed, 20 Jul 2022 at 21:06, Frank Millman wrote: > I saw this from Paul Rubin - for some reason his posts appear in google > groups, but not python-list. > > "It seems to only want integer constants. x[2+2] and x[k] where k=2 > don't work either. Yes, that's for the same reason that x[spam]

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

2022-07-20 Thread Chris Angelico
On Wed, 20 Jul 2022 at 20:55, Frank Millman wrote: > > On 2022-07-20 11:37 AM, Chris Angelico wrote: > > On Wed, 20 Jul 2022 at 18:34, Frank Millman wrote: > >> > >> Hi all > >> > >> C:\Users\E7280>python > >> Python 3.9.7 (tags/v3

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

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

Re: NILEARN - WHY THIS CODE THROWS AN ERROR?????

2022-07-08 Thread Chris Angelico
On Sat, 9 Jul 2022 at 10:57, MRAB wrote: > > On 08/07/2022 23:20, Avi Gross via Python-list wrote: > > Nati Stern has asked several questions here, often about relatively > > technical uses of python code that many of us have never used and still is > > not providing more exact info that tends

Re: Creating lambdas inside generator expression

2022-06-29 Thread Chris Angelico
On Thu, 30 Jun 2022 at 02:49, Johannes Bauer wrote: > But now consider what happens when we create the lambdas inside a list > comprehension (in my original I used a generator expresison, but the > result is the same). Can you guess what happens when we create conds > like this? > > conds = [

Re: REPL with multiple function definitions

2022-06-28 Thread Chris Angelico
On Wed, 29 Jun 2022 at 11:00, Rob Cliffe via Python-list wrote: > > On 26/06/2022 23:22, Jon Ribbens via Python-list wrote: > > 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

Re: WHAT THE ERROR ON MY CODE???

2022-06-28 Thread Chris Angelico
‪On Wed, 29 Jun 2022 at 01:37, ‫נתי שטרן‬‎ wrote:‬ > headers["Authorization"] = "Basic > YjMwMzcwODY3NTUzNDMwNTg5NzA2MjkyNDFmMDE1YWY6VjNKYTk2Y1F4RTFzeTdYbzRnbkt0a2k1djhscXUyU01oSE5VWUwwRg==" > The error is that you just revealed your credentials to the whole world. This is a public mailing list.

Re: REPL with multiple function definitions

2022-06-26 Thread Chris Angelico
On Mon, 27 Jun 2022 at 08:15, Rob Cliffe via Python-list 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

Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread Chris Angelico
‪On Fri, 24 Jun 2022 at 22:16, ‫נתי שטרן‬‎ wrote:‬ > > My TARGET is to bind many code libraries to one Huge code file that works > optimally and do optimizations if needed. > In this file have code of huge part of falconpy, ALL code of re, argparse, > are and many other code libraries > > This

Re: sre_constants MODIFIED CLASS - ERROR

2022-06-24 Thread Chris Angelico
‪On Fri, 24 Jun 2022 at 18:43, ‫נתי שטרן‬‎ wrote:‬ > > class _NamedIntConstant(int): > def __new__(cls, value, name): > self = super(_NamedIntConstant, cls).__new__(cls, value) > self.name = name > return self > > def __repr__(self): > return self.name > >

Re: argparse modify

2022-06-23 Thread Chris Angelico
On Fri, 24 Jun 2022 at 09:03, Mats Wichmann wrote: > Also note that while it's claimed to be fine These Days, inheriting from > a base type like this is sometimes tricky, sometimes broken... be > somewhat aware. Depends on your definition of "broken". If you want to make a custom integer type,

Re: "CPython"

2022-06-20 Thread Chris Angelico
On Tue, 21 Jun 2022 at 13:12, Paulo da Silva wrote: > > Às 03:20 de 21/06/22, MRAB escreveu: > > On 2022-06-21 02:33, Chris Angelico wrote: > >> On Tue, 21 Jun 2022 at 11:13, Paulo da Silva > >> wrote: > >>> > >>> Às 20:01 de 20/06/22,

Re: "CPython"

2022-06-20 Thread Chris Angelico
On Tue, 21 Jun 2022 at 12:53, Avi Gross via Python-list wrote: > > I don't even want to think fo what sound a C# Python would make. Probably about 277 Hz... ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: "CPython"

2022-06-20 Thread Chris Angelico
On Tue, 21 Jun 2022 at 11:13, Paulo da Silva wrote: > > Às 20:01 de 20/06/22, Paulo da Silva escreveu: > > Às 18:19 de 20/06/22, Stefan Ram escreveu: > >>The same personality traits that make people react > >>to troll postings might make them spread unconfirmed > >>ideas about the

Re: "CPython"

2022-06-20 Thread Chris Angelico
On Tue, 21 Jun 2022 at 08:01, dn wrote: > > On 21/06/2022 09.47, Roel Schroeven wrote: > ... > > > So we have an untrustworthy site that's the only one to claim that > > CPython is short for Core Python, and we have an official site that says > > CPython is so named because it's written in C. Hm,

Re: "CPython"

2022-06-20 Thread Chris Angelico
On Tue, 21 Jun 2022 at 07:48, Roel Schroeven wrote: > > Paulo da Silva schreef op 20/06/2022 om 21:01: > > Às 18:19 de 20/06/22, Stefan Ram escreveu: > > >The same personality traits that make people react > > >to troll postings might make them spread unconfirmed > > >ideas about the

Re: "CPython"

2022-06-20 Thread Chris Angelico
On Tue, 21 Jun 2022 at 06:31, Stefan Ram wrote: > > Paulo da Silva writes: > >Do you have any credible reference to your assertion "The "C" in > >"CPython" stands for C."? > > Whether a source is considered "credible" is something > everyone must decide for themselves. > > I can say that

Re: mapLast, mapFirst, and just general iterator questions

2022-06-20 Thread Chris Angelico
On Tue, 21 Jun 2022 at 06:16, Leo wrote: > > On Wed, 15 Jun 2022 04:47:31 +1000, Chris Angelico wrote: > > > Don't bother with a main() function unless you actually need to be > > able to use it as a function. Most of the time, it's simplest to > > just ha

PEP 401 origin and authorship

2022-06-17 Thread Chris Angelico
Somewhere around the place, I remember reading something about how PEP 401 (the retirement of the BDFL and the accession of the FLUFL) came to be. It involved a joke being turned on its originator, I think. But I can't find it back. Anyone have a reference handy? ChrisA --

Re: ModuleNotFoundError

2022-06-15 Thread Chris Angelico
On Thu, 16 Jun 2022 at 05:00, Zoltan Szenderak wrote: > > > > Only on my Windows 10, on my Windows 11 works perfectly. I uninstalled and > reinstalled python, it did not help, I tried everything I found online, > Stackoverflow, python.org, did not help. Not just this module, others too. > They

Re: mapLast, mapFirst, and just general iterator questions

2022-06-14 Thread Chris Angelico
On Wed, 15 Jun 2022 at 05:45, Roel Schroeven wrote: > > Chris Angelico schreef op 14/06/2022 om 20:47: > > > def main(): > > > for each in (iterEmpty, iter1, iter2, iterMany): > > > baseIterator = each() > > > chopFirst

Re: mapLast, mapFirst, and just general iterator questions

2022-06-14 Thread Chris Angelico
On Wed, 15 Jun 2022 at 04:07, Travis Griggs wrote: > def mapFirst(stream, transform): > try: > first = next(stream) > except StopIteration: > return > yield transform(first) > yield from stream Small suggestion: Begin with this: stream = iter(stream) That way,

Re: Suggestion. Replace Any with *

2022-06-13 Thread Chris Angelico
On Tue, 14 Jun 2022 at 01:59, h3ck phy wrote: > > It would be nice if we could write something like this > data: dict[str, *] = {} > instead of > data: dict[str, Any] = {} > > In import statement asterisk means "all names" in a module. > But in type closure it should mean "all types". Type hints

Re: Function to Print a nicely formatted Dictionary or List?

2022-06-09 Thread Chris Angelico
On Fri, 10 Jun 2022 at 03:44, Dave wrote: > > Hi, > > Before I write my own I wondering if anyone knows of a function that will > print a nicely formatted dictionary? > > By nicely formatted I mean not all on one line! > https://docs.python.org/3/library/pprint.html from pprint import pprint

Re: How to test characters of a string

2022-06-08 Thread Chris Angelico
On Thu, 9 Jun 2022 at 04:14, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2022-06-09 at 03:18:56 +1000, > Chris Angelico wrote: > > > On Thu, 9 Jun 2022 at 03:15, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > > > > > On 2022-06-08

Re: How to test characters of a string

2022-06-08 Thread Chris Angelico
On Thu, 9 Jun 2022 at 03:15, <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2022-06-08 at 08:07:40 -, > De ongekruisigde wrote: > > > Depending on the problem a regular expression may be the much simpler > > solution. I love them for e.g. text parsing and use them all the time. > >

Re: How to replace characters in a string?

2022-06-08 Thread Chris Angelico
On Wed, 8 Jun 2022 at 19:13, Dave wrote: > > Hi, > > Thanks for this! > > So, is there a copy function/method that returns a MutableString like in > objective-C? I’ve solved this problems before in a number of languages like > Objective-C and AppleScript. > > Basically there is a set of common

Re: How to replace characters in a string?

2022-06-08 Thread Chris Angelico
On Wed, 8 Jun 2022 at 18:20, Dave wrote: > > PS > > I’ve also tried: > myCompareFile1 = myTitleName > myCompareFile1.replace("\u2019", "'") > myCompareFile2 = myCompareFileName > myCompareFile2.replace("\u2019", "'") > Which also doesn’t work, the replace itself work but it still fails the >

Re: How to replace characters in a string?

2022-06-08 Thread Chris Angelico
On Wed, 8 Jun 2022 at 18:12, Dave wrote: > I tried the but it doesn’t seem to work? > myCompareFile1 = ascii(myTitleName) > myCompareFile1.replace("\u2019", "'") Strings in Python are immutable. When you call ascii(), you get back a new string, but it's one that has actual backslashes and such

Re: How to test characters of a string

2022-06-07 Thread Chris Angelico
On Wed, 8 Jun 2022 at 07:24, Barry wrote: > > > > > On 7 Jun 2022, at 22:04, Dave wrote: > > > > It depends on the language I’m using, in Objective C, I’d use isNumeric, > > just wanted to know what the equivalent is in Python. > > > > If you know the answer why don’t you just tell me and if

Re: min, max with position

2022-06-04 Thread Chris Angelico
On Sun, 5 Jun 2022 at 08:09, dn wrote: > > On 05/06/2022 09.50, Chris Angelico wrote: > > No, but it shouldn't be too hard to make it if you want it. The > > obvious option of calling max/min on the enumerated list won't work on > > its own, since the index comes before t

Re: min, max with position

2022-06-04 Thread Chris Angelico
On Sun, 5 Jun 2022 at 08:00, dn wrote: > > On 05/06/2022 06.56, Dennis Lee Bieber wrote: > > On Sat, 4 Jun 2022 13:36:26 -0500, "Michael F. Stemper" > > declaimed the following: > > > >> > >> Are there similar functions that return not only the minimum > >> or maximum value, but also its

Re: min, max with position

2022-06-04 Thread Chris Angelico
On Sun, 5 Jun 2022 at 07:46, Michael F. Stemper wrote: > > Python contains built-in functions that return the minimum or > maximum items in a list. > > >>> l = [1.618033,3.141593,2.718282] > >>> min(l) > 1.618033 > >>> max(l) > 3.141593 > >>> > > Are there similar functions that

Re: Automatic Gain Control in Python?

2022-05-31 Thread Chris Angelico
On Wed, 1 Jun 2022 at 11:05, Steve GS wrote: > > > >Even easier, the few NPR podcasts I just checked now have RSS feeds of > their episodes (as expected). It seems it would be much easier to just > download the latest episode based on the XML file, normalize, send it to > play, done. > > How

Re: .0 in name

2022-05-28 Thread Chris Angelico
On Sun, 29 May 2022 at 08:26, Eryk Sun wrote: > > On 5/28/22, Chris Angelico wrote: > > > > be extremely confusing; so to keep everything safe, the interpreter > > generates a name you couldn't possibly want - same as for the function > > itself, which is

Re: .0 in name

2022-05-28 Thread Chris Angelico
On Sun, 29 May 2022 at 06:41, Ralf M. wrote: > > Am 13.05.2022 um 23:23 schrieb Paul Bryan: > > On Sat, 2022-05-14 at 00:47 +0800, bryangan41 wrote: > > > >> May I know (1) why can the name start with a number? > > > > The name of an attribute must be an identifier. An identifier cannot > > begin

Re: Now for something completely different...

2022-05-22 Thread Chris Angelico
On Mon, 23 May 2022 at 09:19, Skip Montanaro wrote: > That's not too informative (other than its relationship to moi), and I have > room for probably four or five more characters. (I have a graphic artist in > mind, so the space need not strictly be text either.) Aww, not enough room to say

Re: how to distinguish return from print()

2022-05-22 Thread Chris Angelico
On Mon, 23 May 2022 at 09:23, Stefan Ram wrote: > You are making it extra hard by wording the question in this > way. "What's the difference between the moon and liberty?". Uh ... > > It's much easier to explain the moon and liberty separately. "You can't tell the difference between a lump

Re: "py" command for Linux and Mac?

2022-05-20 Thread Chris Angelico
On Sat, 21 May 2022 at 11:22, Michael Torrie wrote: > And of course the answer given by the grandparent is that Dan should use > a normal linux shebang line in his scripts and on Windows the py > launcher will read that shebang and guestimate the proper python > interpreter to use and execute the

Re: Discerning "Run Environment"

2022-05-18 Thread Chris Angelico
On Wed, 18 May 2022 at 19:40, Stephen Tucker wrote: > > Hi, > > I am a Windows 10 user still using Python 2.x (for good reasons, I assure > you.) > > I have a Python 2.x module that I would like to be able to use in a variety > of Python 2.x programs. The module outputs characters to the user

Re: Request for assistance (hopefully not OT)

2022-05-17 Thread Chris Angelico
On Wed, 18 May 2022 at 04:05, Loris Bennett wrote: > > [snip (26 lines)] > > > I think you had a problem before that. Debian testing is not an > > operating system you should be using if you have a fairly good > > understanding of how Debian (or Linux in general) works. > > Should be > > I

Re: Request for assistance (hopefully not OT)

2022-05-17 Thread Chris Angelico
On Wed, 18 May 2022 at 04:05, Loris Bennett wrote: > > So now I have problems. > > I think you had a problem before that. Debian testing is not an > operating system you should be using if you have a fairly good > understanding of how Debian (or Linux in general) works. I take issue with that!

Re: Request for assistance (hopefully not OT)

2022-05-17 Thread Chris Angelico
On Tue, 17 May 2022 at 21:22, o1bigtenor wrote: > > Greetings > > I was having space issues in my /usr directory so I deleted some > programs thinking that the space taken was more an issue than having > older versions of the program. > > So one of the programs I deleted (using rm -r) was

Re: Changing calling sequence

2022-05-14 Thread Chris Angelico
On Sun, 15 May 2022 at 14:27, dn wrote: > > On 15/05/2022 11.34, 2qdxy4rzwzuui...@potatochowder.com wrote: > > On 2022-05-15 at 10:22:15 +1200, > > dn wrote: > > > >> That said, a function which starts with a list of ifs-buts-and-maybes* > >> which are only there to ascertain which set of

Re: tail

2022-05-11 Thread Chris Angelico
On Thu, 12 May 2022 at 07:27, Marco Sulla wrote: > > On Wed, 11 May 2022 at 22:09, Chris Angelico wrote: > > > > Have you actually checked those three, or do you merely suppose them to be > > true? > > I only suppose, as I said. I should do some benchmark and some

Re: tail

2022-05-11 Thread Chris Angelico
On Thu, 12 May 2022 at 06:03, Marco Sulla wrote: > I suppose this function is fast. It reads the bytes from the file in chunks > and stores them in a bytearray, prepending them to it. The final result is > read from the bytearray and converted to bytes (to be consistent with the > read method). >

Re: [Python-ideas] Re: New Tool Proposal

2022-05-10 Thread Chris Angelico
On Tue, 10 May 2022 at 19:57, anthony.flury wrote: > > > On 10/05/2022 09:20, Chris Angelico wrote: > > On Tue, 10 May 2022 at 18:06, anthony.flury via Python-ideas > wrote: > > A proposal for a new tool to be implemented - > > It is often the case that

Re: tail

2022-05-09 Thread Chris Angelico
On Tue, 10 May 2022 at 07:07, Barry wrote: > POSIX tail just prints the bytes to the output that it finds between \n bytes. > At no time does it need to care about encodings as that is a problem solved > by the terminal software. I would not expect utf-16 to work with tail on > linux systems.

Re: tail

2022-05-09 Thread Chris Angelico
On Tue, 10 May 2022 at 05:12, Marco Sulla wrote: > > On Mon, 9 May 2022 at 19:53, Chris Angelico wrote: > > > > On Tue, 10 May 2022 at 03:47, Marco Sulla > > wrote: > > > > > > On Mon, 9 May 2022 at 07:56, Cameron Simpson wrote: > > > > &

Re: tail

2022-05-09 Thread Chris Angelico
On Tue, 10 May 2022 at 03:47, Marco Sulla wrote: > > On Mon, 9 May 2022 at 07:56, Cameron Simpson wrote: > > > > The point here is that text is a very different thing. Because you > > cannot seek to an absolute number of characters in an encoding with > > variable sized characters. _If_ you did

Re: tail

2022-05-08 Thread Chris Angelico
On Mon, 9 May 2022 at 05:49, Marco Sulla wrote: > Anyway, apart from my implementation, I'm curious if you think a tail > method is worth it to be a method of the builtin file objects in > CPython. Absolutely not. As has been stated multiple times in this thread, a fully general approach is

Re: tail

2022-05-08 Thread Chris Angelico
On Mon, 9 May 2022 at 04:15, Barry Scott wrote: > > > > > On 7 May 2022, at 22:31, Chris Angelico wrote: > > > > On Sun, 8 May 2022 at 07:19, Stefan Ram wrote: > >> > >> MRAB writes: > >>> On 2022-05-07 19:47, Stefan Ram wrote: > >

Re: tail

2022-05-07 Thread Chris Angelico
On Sun, 8 May 2022 at 07:19, Stefan Ram wrote: > > MRAB writes: > >On 2022-05-07 19:47, Stefan Ram wrote: > ... > >>def encoding( name ): > >>path = pathlib.Path( name ) > >>for encoding in( "utf_8", "latin_1", "cp1252" ): > >>try: > >>with path.open(

Re: tail

2022-05-07 Thread Chris Angelico
On Sun, 8 May 2022 at 04:37, Marco Sulla wrote: > > On Sat, 7 May 2022 at 19:02, MRAB wrote: > > > > On 2022-05-07 17:28, Marco Sulla wrote: > > > On Sat, 7 May 2022 at 16:08, Barry wrote: > > >> You need to handle the file in bin mode and do the handling of line > > >> endings and encodings

Re: Python/New/Learn

2022-05-05 Thread Chris Angelico
On Fri, 6 May 2022 at 09:53, Grant Edwards wrote: > > On 2022-05-05, Mats Wichmann wrote: > > > Without having any data at all on it, just my impressions, more > > people these days learn from in-person or video experiences. > > I've always been utterly baffled by video tutorials for >

Re: Python/New/Learn

2022-05-04 Thread Chris Angelico
On Thu, 5 May 2022 at 13:14, Avi Gross wrote: > > Chris, > > It was an extremely open-ended question to a forum where > most of the readers are more advanced, at least I think. > > > My library has oodles of Python Books for free to borrow on paper and > return and I have read many of them. There

Re: Python/New/Learn

2022-05-04 Thread Chris Angelico
On Thu, 5 May 2022 at 12:57, Avi Gross via Python-list wrote: > > https://wiki.python.org/moin/PythonBooks > That's an incredibly daunting list, and not something I'd overly strongly recommend, but yes, if you want to get a dead-tree or e-book to read, there are quite a lot of options available.

Re: Python/New/Learn

2022-05-04 Thread Chris Angelico
On Thu, 5 May 2022 at 12:49, Patrick 0511 wrote: > > Hello, I'm completely new here and don't know anything about python. Can > someone tell me how best to start? So what things should I learn first? > I'd start right here with the tutorial! https://docs.python.org/3/tutorial/ Most important

Re: tail

2022-05-02 Thread Chris Angelico
On Tue, 3 May 2022 at 04:38, Marco Sulla wrote: > > On Mon, 2 May 2022 at 18:31, Stefan Ram wrote: > > > > |The Unicode standard defines a number of characters that > > |conforming applications should recognize as line terminators:[7] > > | > > |LF:Line Feed, U+000A > > |VT:Vertical Tab,

Re: tail

2022-05-01 Thread Chris Angelico
On Mon, 2 May 2022 at 11:54, Cameron Simpson wrote: > > On 01May2022 23:30, Stefan Ram wrote: > >Dan Stromberg writes: > >>But what about Unicode? Are all 10 bytes newlines in Unicode encodings? > > It seems in UTF-8, when a value is above U+007F, it will be > > encoded with bytes that

Re: new sorting algorithm

2022-05-01 Thread Chris Angelico
On Mon, 2 May 2022 at 09:20, Dan Stromberg wrote: > > > On Sun, May 1, 2022 at 1:44 PM Chris Angelico wrote: >> >> On Mon, 2 May 2022 at 06:43, Dan Stromberg wrote: >> > On Sun, May 1, 2022 at 11:10 AM Chris Angelico wrote: >> >> >> &g

Re: tail

2022-05-01 Thread Chris Angelico
On Mon, 2 May 2022 at 09:19, Dan Stromberg wrote: > > On Sun, May 1, 2022 at 3:19 PM Cameron Simpson wrote: > > > On 01May2022 18:55, Marco Sulla wrote: > > >Something like this is OK? > > > > Scanning backward for a byte == 10 in ASCII or ISO-8859 seems fine. > > But what about Unicode? Are

Re: new sorting algorithm

2022-05-01 Thread Chris Angelico
On Mon, 2 May 2022 at 01:53, Nas Bayedil wrote: > We believe that using this method to develop completely new, fast > algorithms, approaching the speed of the famous *QuickSort*, the speed of > which cannot be surpassed, but its drawback can be circumvented, in the > sense of stack overflow, on

Re: Printing Unicode strings in a list

2022-04-30 Thread Chris Angelico
On Sun, 1 May 2022 at 00:03, Vlastimil Brom wrote: > (Even the redundant u prefix from your python2 sample is apparently > accepted, maybe for compatibility reasons.) Yes, for compatibility reasons. It wasn't accepted in Python 3.0, but 3.3 re-added it to make porting easier. It doesn't do

Re: tail

2022-04-24 Thread Chris Angelico
On Mon, 25 Apr 2022 at 01:47, Marco Sulla wrote: > > > > On Sat, 23 Apr 2022 at 23:18, Chris Angelico wrote: >> >> Ah. Well, then, THAT is why it's inefficient: you're seeking back one >> single byte at a time, then reading forwards. That is NOT going to &g

Re: tail

2022-04-24 Thread Chris Angelico
On Sun, 24 Apr 2022 at 21:11, Antoon Pardon wrote: > > > > Op 23/04/2022 om 20:57 schreef Chris Angelico: > > On Sun, 24 Apr 2022 at 04:37, Marco Sulla > > wrote: > >> What about introducing a method for text streams that reads the lines &g

Re: tail

2022-04-23 Thread Chris Angelico
On Sun, 24 Apr 2022 at 10:04, Cameron Simpson wrote: > > On 24Apr2022 08:21, Chris Angelico wrote: > >On Sun, 24 Apr 2022 at 08:18, Cameron Simpson wrote: > >> An approach I think you both may have missed: mmap the file and use > >> mmap.rfind(b'\n') to loca

Re: tail

2022-04-23 Thread Chris Angelico
On Sun, 24 Apr 2022 at 08:18, Cameron Simpson wrote: > > On 24Apr2022 07:15, Chris Angelico wrote: > >On Sun, 24 Apr 2022 at 07:13, Marco Sulla > >wrote: > >> Emh, why chunks? My function simply reads byte per byte and compares > >> it to b"\n"

Re: tail

2022-04-23 Thread Chris Angelico
On Sun, 24 Apr 2022 at 08:06, dn wrote: > > On 24/04/2022 09.15, Chris Angelico wrote: > > On Sun, 24 Apr 2022 at 07:13, Marco Sulla > > wrote: > >> > >> On Sat, 23 Apr 2022 at 23:00, Chris Angelico wrote: > >>>>> This is quite ineffici

Re: tail

2022-04-23 Thread Chris Angelico
On Sun, 24 Apr 2022 at 08:03, Peter J. Holzer wrote: > > On 2022-04-24 04:57:20 +1000, Chris Angelico wrote: > > On Sun, 24 Apr 2022 at 04:37, Marco Sulla > > wrote: > > > What about introducing a method for text streams that reads the lines > >

Re: tail

2022-04-23 Thread Chris Angelico
On Sun, 24 Apr 2022 at 07:13, Marco Sulla wrote: > > On Sat, 23 Apr 2022 at 23:00, Chris Angelico wrote: > > > > This is quite inefficient in general. > > > > > > Why inefficient? I think that readlines() will be much slower, not > > > only mor

Re: tail

2022-04-23 Thread Chris Angelico
On Sun, 24 Apr 2022 at 06:41, Marco Sulla wrote: > > On Sat, 23 Apr 2022 at 20:59, Chris Angelico wrote: > > > > On Sun, 24 Apr 2022 at 04:37, Marco Sulla > > wrote: > > > > > > What about introducing a method for text streams that reads the

Re: tail

2022-04-23 Thread Chris Angelico
On Sun, 24 Apr 2022 at 04:37, Marco Sulla wrote: > > What about introducing a method for text streams that reads the lines > from the bottom? Java has also a ReversedLinesFileReader with Apache > Commons IO. It's fundamentally difficult to get precise. In general, there are three steps to

Re: Style for docstring

2022-04-22 Thread Chris Angelico
On Sat, 23 Apr 2022 at 09:31, Rob Cliffe via Python-list wrote: > > I don't use docstrings much; instead I put a line or two of comments > after the `def ` line. > But my practice in such situations is as per the OP's 3rd suggestion, e.g. > # Returns True if . The point of docstrings is

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