Re: What is this TEST BANK stuff ?
On 2023-06-21, Chris Angelico via Python-list wrote: > On Thu, 22 Jun 2023 at 02:54, Dan Kolis via Python-list > wrote: >> >> Why do we tolerate this spam ? >> >> this seems most likely a way to inject viruses into people's workflow. >> >> That wiped out usenet. Ahh without an explaination; ( and it woudl have to >> be a good one ); what is the purpsoe of this, why is it here ? >> >> Can it be eliminated ? >> > > Yes, follow the mailing list instead of the newsgroup. Most spam > doesn't reach us over here at the list. > > Sign up here: https://mail.python.org/mailman/listinfo/python-list If you want to stick with NNTP as your access protocol, you can follow the list on gmane: nntp://news.gmane.io/gmane.comp.python.general However, the list recently stopped accepting posts via gmane, so you'll need to configure your nntp client to e-mail posts to that group. -- https://mail.python.org/mailman/listinfo/python-list
Re: isinstance()
On 2023-08-04, Chris Angelico via Python-list wrote: > On Sat, 5 Aug 2023 at 09:36, dn via Python-list > wrote: > >> Faced with a situation where an argument may be a scalar-value or an >> iterable, I'll presume the latter, eg throw it straight into a for-loop. >> If that fails (because the argument is a scalar), use try-except to >> re-route the logic. > > That's great as long as you aren't expecting to handle strings. If you do that, you're obviously not expecting to handle strings. The problem happens when you're not expecting to handle strings, and you get passed one anyway. It's like the Spanish Inquisition... > The string "spam" is sometimes equivalent to the list ["s", "p", > "a", "m"] and sometimes not. And b"ABCD" is sometimes equivalent to the list [65,66,67,68] and sometimes not. Been there, fell in that hole. More than a few times. :/ Famous Last Words: "I wasn't expecting to handle strings -- but I should have been..." -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Question(s)
On 2023-10-24, o1bigtenor via Python-list wrote: > Is there a way to verify that a program is going to do what it is > supposed to do even before all the hardware has been assembled and > installed and tested? It depends on what you mean by "verify ...". If you want to prove a program correct (in the mathematical sense), then the practical answer is no. It's possible to prove _some_ programs correct, but they tend to be uselessly trivial. For real programs, the best you can do is choose a good set of test cases and test them. If you can simulate the various inputs and collect the outputs, then you can do testing before you have real target hardware. -- https://mail.python.org/mailman/listinfo/python-list
Re: Question(s)
On 2023-10-24, Dan Purgert via Python-list wrote: > On 2023-10-24, o1bigtenor wrote: >> Greetings >> >> (Sorry for a nebulous subject but dunno how to have a short title for >> a complex question.) >> [...] >> Is there a way to verify that a program is going to do what it is >> supposed to do even before all the hardware has been assembled and >> installed and tested? > > In short, no. > > Reality is a mess, and even if you've programmed/perfectly/ to the > datasheets (and passed our unit-tests that are also based on those > datasheets), a piece of hardware may not actually conform to what's > written. Maybe the sheet is wrong, maybe the hardware is faulty, etc. And the specified customer requirements are usually wrong too. Sure, the customer said it is supposed to do X, but what they actually needed was Y. And the protocol spec isn't quite right either. Sure, it says "when A is received reply with B", but what everybody really does is slighty different, and you need to do what everybody else does, or the widget you're talking to won't cooperate. And floating point doesn't really work the way you think it does. Sometimes it does, close-enough, for the test-cases you happened to choose... -- https://mail.python.org/mailman/listinfo/python-list
Re: Question(s)
On 2023-10-24, Thomas Passin via Python-list wrote: > Something less ambitious than a full proof of correctness of an > arbitrary program can sometimes be achieved. The programming team > for the Apollo moon mission developed a system which, if you would > write your requirements in a certain way, could generate correct C > code for them. Er, what? C didnt' exist until after the Apollo program was done. FORTRAN, perhaps? -- https://mail.python.org/mailman/listinfo/python-list
Re: Question(s)
On 2023-10-24, o1bigtenor via Python-list wrote: > So how does one test software then? That's what customers are for! [Actually, that's true more often than it should be.] -- https://mail.python.org/mailman/listinfo/python-list
Re: Question(s)
On 2023-10-25, o1bigtenor via Python-list wrote: > Haven't heard of a python IDE - - - doesn't mean that there isn't such - - > just that I haven't heard of such. Is there a python IDE? Seriously? Now you're just trolling. google.com/search?q=python+ide&oq=python+ide -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Checking if email is valid
On 2023-11-01, Simon Connah via Python-list wrote: > I'm building a simple project using smtplib and have a > question. I've been doing unit testing but I'm not sure how to check > if an email message is valid. Send an e-mail using it? If the right person gets the e-mail, then it's valid? > Using regex sounds like a bad idea to me and the other options I > found required paying for third party services. > > Could someone push me in the right direction please? I just want to > find out if a string is a valid email address. You'll have to define "valid". Valid syntactically according to ? Will be accepted by an SMTP server somewhere? Corresponds to a real person? Make sure it has an '@' in it. Possibly require at least one '.' after the '@'. Trying to do anything more than that is just wasting your time and annoying the mule. -- https://mail.python.org/mailman/listinfo/python-list
Re: Checking if email is valid
On 2023-11-01, 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 dot after the at. Ah, I forgot about defaulting to a local domain if one is omitted. Will MTAs do that these days? > (Technically there's no guarantee of an at sign either, but email > addresses without at signs are local-only, so in many contexts, you > can assume there needs to be an at.) > > So the regex to match all valid email addresses that aren't > local-only is... drumroll please... > > r"@" Unless you want to support UUCP or X400 addresses... :) -- https://mail.python.org/mailman/listinfo/python-list
Re: Checking if email is valid
On 2023-11-02, Michael Torrie via Python-list wrote: > On 11/2/23 00:42, Simon Connah via Python-list wrote: > >> Valid as in conforms to the standard. Although having looked at the >> standard that might be more difficult than originally planned. > > You'll have to read the relevant RFCs. Lots of corner cases! From what > I can see virtually no one on the internet gets it right, judging by the > number of times I have valid email addresses flagged as not valid by > poor algorithms. I've wondered if there are addresses that violate the RFC (and would therefore be "correctly" rejected), but but in practice will work just fine. I've never spent enough time looking at the RFC to even propose test cases for that... -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Checking if email is valid
On 2023-11-04, Michael Torrie via Python-list wrote: > On 11/4/23 02:51, Simon Connah via Python-list wrote: > >> Wow. I'm half tempted to make a weird email address to see how many >> websites get it wrong. In my experience, they don't have to be very weird at all. >> Thank you for the link. > > Nearly all websites seem to reject simple correct email addresses > such as myemail+sometext@example.domain. I like to use this kind of > email address when I can to help me filter out the inevitable spam > that comes from companies selling off my address even after claiming > they won't. I've always suspected that's intentional. They refuse those sorts of e-mail addresses because they know that's what they are used for. If they allowed "plus suffixed" e-mail addresses, then all the crap they want to send to you would go into /dev/null where it belongs -- and we can't have that! > So I suspect that nearly all websites are going to reject other > kinds of weird email addresses you can create that are actually > correct. 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 enter the same @-containing string twice) are deluding themselves. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Checking if email is valid
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 >> anything other than require an '@' (and optionally make you enter the >> same @-containing string twice) are deluding themselves. > > And don't get me started on phone number validation. I can see how the truley dim-witted might forget that other countries have phone numbers with differing lengths and formatting/punctuation, but there are tons of sites where it takes multiple tries when entering even a bog-standard USA 10-0digit phone nubmer because they are completely flummuxed by an area code in parens or hyphens in the usual places (or lack of hyhpens in the usual places). This stuff isn't that hard, people... > The most annoying thing to me, though, is sites that reject names > that have an apostrophe in them. I hate being told that my name, > that I have been using for over seventy years, is invalid. > > OK, now that I am started, what else? Oh yah. Look at your credit > card. The number has spaces in it. Why do I have to remove them. If > you don't like them then you are a computer, just remove them. Indeed. There is a tiny but brightly burning kernel of hate in my heart for web sites (and their developers) that refuse to accept credit card numbers entered with spaces _as_they_are_shown_on_the_card_! I've concluded that using PHP causes debilitating and irreversible brain damage. > When do we stop working for computers and have the computers start > working for us? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Checking if email is valid
On 2023-11-06, Greg Ewing via Python-list wrote: > On 7/11/23 7:45 am, Mats Wichmann wrote: >> Continuing with the example, if you have a single phone number field, or >> let a mobile number be entered in a field marked for landline, you will >> probably assume you can text to that number. > > But if the site can detect that you've entered a mobile number into > the landline field or vice versa and reject it, then it can figure out > whether it can text to a given numner or not without you having > to tell it! Maybe. I'm pretty sure the last time I was in Australia, you could send/recieve text messages from landalines. And I've had mobile number that didn't support text messaging. If you, as a web developer, want the user to enter a text-message capable phone number, then ASK FOR THAT! -- https://mail.python.org/mailman/listinfo/python-list
Re: xor operator
On 2023-11-13, Dom Grigonis via Python-list wrote: > Hi All, > > I think it could be useful to have `xor` builtin, which has API similar to > the one of `any` and `all`. > > * Also, it could have optional second argument `n=1`, which > * indicates how many positives indicates `True` return. For > * complete flexibility 3rd argument could indicate if `the number` > * is equal, greater, less, ... than `n` I would expect "xor" to return true if there are an odd number of trues, and false if there are an even number of trues. It's not clear to me what you're asking for. -- https://mail.python.org/mailman/listinfo/python-list
Re: xor operator
On 2023-11-13, Dom Grigonis via Python-list wrote: > I am not asking. Just inquiring if the function that I described > could be useful for more people. > > Which is: a function with API that of `all` and `any` and returns > `True` if specified number of elements is True. I've got no objection to a function that counts True objects returned by an iterator and returns True IFF count == . I've got no objection to a function that counts True objects returned by an iterator and returns True IFF count >= . I've got no objection if that latter function short-circuits by stopping the iteration and returning True when it has seen true objects. I don't recall ever having a need for such a function in the 25 years I've been writing Python code, but I'm not going to claim that nobody else has a need for such a function. I would object to that being called 'xor', and would fight to the death (yes, I'm being hyperbolic) the addition of a builtin with the name 'xor' that does what you describe. > It is not a generalised `xor` in strict programatic space. AFAICT, it's not nothing at all to do with 'xor' in any sense. > I.e. NOT bitwise xor applied to many bits. This is more in line > with cases that `any` and `all` builtins are used. Except the 'any' and 'all' builtins are _exactly_ the same as bitwise or and and applided to many bits. To do something "in line" with that using the 'xor' operator would return True for an odd number of True values and False for an even Number of True values. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: xor operator
On 2023-11-14, Dom Grigonis via Python-list wrote: > >> Except the 'any' and 'all' builtins are _exactly_ the same as bitwise >> or and and applided to many bits. To do something "in line" with that >> using the 'xor' operator would return True for an odd number of True >> values and False for an even Number of True values. > > Fair point. > > Have you ever encountered the need for xor for many bits (the one > that I am NOT referring to)? Would be interested in what sort of > case it could be useful. Yes, it's used all the time in low-level communications protocols, where it's often implemented in hardware. But, it is also not at all unusual to implement it in software. It's also not that unusual for the "count-ones" part of the function you're asking for to be implemented in hardware by a CPU having an instruction that counts the number of 1 bits in a register. GCC has a low-level builtins called __builtin_popcount() and __builtin-popcountl() that counts the number of 1's in an unsigned (long) int. -- https://mail.python.org/mailman/listinfo/python-list
Re: Context without manager
On 2023-11-26, Dieter Maurer via Python-list wrote: > If you do not have this case (e.g. usually if you open the file > in a class's `__init__`), you do not use a context manager. He knows that. The OP wrote that he wants to use that can _only_ be used by a context manager, but he wants that usage to be spread over various methods of a class he's writing. So he's asking how to fool that into working when he's not using a context manager. -- Grnat -- https://mail.python.org/mailman/listinfo/python-list
Re: Context without manager
On 2023-11-27, Grant Edwards via Python-list wrote: > On 2023-11-26, Dieter Maurer via Python-list wrote: > >> If you do not have this case (e.g. usually if you open the file >> in a class's `__init__`), you do not use a context manager. > > He knows that. The OP wrote that he wants to use that can > _only_ be used by a context manager, but he wants that usage to be > spread over various methods of a class he's writing. So he's asking > how to fool that into working when he's not using a > context manager. I should probably have written "how to fool that into working when he's not using a 'with' statement" -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: How to enter multiple, similar, dictionaries?
On 2023-12-11, Chris Green via Python-list 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', 'name':'Leisure Amps'} > sa = {'dev':'bbb', 'input':'3', 'name':'Starter Amps'} > bv = {'dev':'adc2', 'input':0, 'name':'BowProp Volts'} > > It's effectively a 'table' with columns named 'dev', 'input' and > 'name' and I want to access the values of the table using the variable > name. Named tuples stored in a dictionary or list? > I could, obviously, store the data in a database (sqlite), I have some > similar data in a database already but the above sort of format in > Python source is more human readable and accessible. I'm just looking > for a less laborious way of entering it really. -- https://mail.python.org/mailman/listinfo/python-list
Re: How/where to store calibration values - written by program A, read by program B
On 2023-12-28, Peter J. Holzer via Python-list wrote: > On 2023-12-28 05:20:07 +, rbowman via Python-list wrote: >> On Wed, 27 Dec 2023 03:53:42 -0600, Greg Walters wrote: >> > The biggest caveat is that the shared variable MUST exist before it can >> > be examined or used (not surprising). >> >> There are a few other questions. Let's say config.py contains a variable >> like 'font' that is a user set preference or a calibration value >> calculated by A to keep with the thread title. Assuming both scripts are >> running, how does the change get propagated to B after it is set in A > > It isn't. The variable is set purely in memory. This is a mechanism to > share a value between multiple modules used by the same process, not to > share between multiple processes (whether they run the same or different > scripts) > >> and written to the shared file? > > Nothing is ever written to a file. Then how does it help the OP to propogate clibration values from one program to another or from one program run to the next run? > You could of course write python files from a python script (in fact I > do this), but that's not what this pattern is about, AFAICS. -- https://mail.python.org/mailman/listinfo/python-list
Re: Extract lines from file, add to new files
On 2024-01-29, Rich Shepard via Python-list wrote: > On Mon, 29 Jan 2024, Rich Shepard via Python-list wrote: > >> No, I hadn't ... but I am reading it now. > > Perhaps I missed the answer to my question when reading the io module. It > explains how to open/write/read files of text and binary data, not passing > a variable's value from one file to a place-keeper in another file. It's not at all clear (to me) what you're asking about. When you talk about "files" are you referring to data files? Python modules within a single program? Seperate Python programs? Something else? The phrase "place-keeper in another file" sounds a bit like you're trying to do templating. There are many, many ways to do templating in Python -- ranging from literal 'f-strings' to powerful templating engines that are used to construct entire web sites: https://www.google.com/search?q=python+templating https://docs.python.org/3/tutorial/inputoutput.html#tut-f-strings https://en.wikipedia.org/wiki/Jinja_(template_engine) -- https://mail.python.org/mailman/listinfo/python-list
Re: Can one output something other than 'nan' for not a number values?
On 2024-02-16, Chris Green via Python-list wrote: > I'm looking for a simple way to make NaN values output as something > like '-' or even just a space instead of the string 'nan'. It would probably help if you told us how you're "outputting" them now (the Python feaatures/functions used, not the actual output format). Are you using f-strings, the % operator, str.format(), or ?? I would be tempted to try monkey-patching the float class to override the __format__ method. I have no idea what side effects that might have, or if it's even used by the various formatting mechanisms, so you might end up scraping bits off the walls... -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Can one output something other than 'nan' for not a number values?
On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. >>[...] >> >>Battery Voltages and Currents >>Leisure Battery - 12.42 volts -0.52 Amps >>Starter Battery - nan voltsnan Amps >> >>What I would like is for those 'nan' strings to be just a '-' or >>something similar. > The simplest thing is probably just a function writing it how you want > it: > > def float_s(f): > if isnan(f): > return "-" > return str(f) > > and then use eg: > > print(f'value is {float_s(value)}') > > or whatever fits your code. Except he's obviously using some sort of formatting to control the number of columns and decimal places, so 'str(f)' is not going to cut it. Is the basic floating point number formatting functionality seen when using f-strings or '%' operator part of the float type or is it part of the f-string and % operator? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Can one output something other than 'nan' for not a number values?
On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. [...] >> >>Battery Voltages and Currents >>Leisure Battery - 12.42 volts -0.52 Amps >>Starter Battery - nan voltsnan Amps >> >>What I would like is for those 'nan' strings to be just a '-' or >>something similar. > > The simplest thing is probably just a function writing it how you want > it: > > def float_s(f): > if isnan(f): > return "-" > return str(f) He's obviouisly using a formatting feature to control columns and decimal places, so I doubt that 'str(f)' is going to meet the need. I tried monkey-patching the __format__ method of the 'float' type, but it's immutable -- so that didn't work. Is float.__format__() what's used by f-strings, the % operator, etc.? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Can one output something other than 'nan' for not a number values?
On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. [...] >> >>Battery Voltages and Currents >>Leisure Battery - 12.42 volts -0.52 Amps >>Starter Battery - 12.34 volts -0.01 Amps > The simplest thing is probably just a function writing it how you > want it: > > def float_s(f): > if isnan(f): > return "-" > return str(f) Since he's obviously using one of the float formatting mechanisms to control the number of columsn and decimal places, I doubt str(f) will meet the need. I tried monkey-patching the float type's __format__ method, but it's immutable. Is float.__format__() what's used by f-strings, the '%' operator, etc.? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Can one output something other than 'nan' for not a number values?
On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. [...] >> >>Battery Voltages and Currents >>Leisure Battery - 12.42 volts -0.52 Amps >>Starter Battery - 12.34 volts -0.01 Amps > The simplest thing is probably just a function writing it how you > want it: > > def float_s(f): > if isnan(f): > return "-" > return str(f) Since he's obviously using one of the float formatting mechanisms to control the number of columsn and decimal places, I doubt str(f) will meet the need. I tried monkey-patching the float type's __format__ method, but it's immutable. Is float.__format__() what's used by f-strings, the '%' operator, etc.? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Can one output something other than 'nan' for not a number values?
[Posts via slrn and my GMail account aren't showing up, so I guess I'll try subscribing from a different e-mail address.] On 2024-02-17, Cameron Simpson via Python-list wrote: On 16Feb2024 22:12, Chris Green wrote: I'm looking for a simple way to make NaN values output as something like '-' or even just a space instead of the string 'nan'. [...] Battery Voltages and Currents Leisure Battery - 12.42 volts -0.52 Amps Starter Battery - 12.34 volts -0.01 Amps The simplest thing is probably just a function writing it how you want it: def float_s(f): if isnan(f): return "-" return str(f) Since he's obviously using one of the float formatting mechanisms to control the number of columsn and decimal places, I doubt str(f) will meet the need. I tried monkey-patching the float type's __format__ method, but it's immutable. Is float.__format__() what's used by f-strings, the '%' operator, etc.? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Can one output something other than 'nan' for not a number values?
[I've been trying all afternoon to post via slrn, but nothing is showing up on the list. Forgive me if multiple posts eventually show up.] On 2024-02-17, Cameron Simpson via Python-list wrote: > On 16Feb2024 22:12, Chris Green wrote: >>I'm looking for a simple way to make NaN values output as something >>like '-' or even just a space instead of the string 'nan'. [...] >> >>Battery Voltages and Currents >>Leisure Battery - 12.42 volts -0.52 Amps >>Starter Battery - 12.34 volts -0.01 Amps > The simplest thing is probably just a function writing it how you > want it: > > def float_s(f): > if isnan(f): > return "-" > return str(f) Since he's obviously using one of the float formatting mechanisms to control the number of columsn and decimal places, I doubt str(f) will meet the need. I tried monkey-patching the float type's __format__ method, but it's immutable. Is float.__format__() what's used by f-strings, the '%' operator, etc.? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Can one output something other than 'nan' for not a number values?
On 2024-02-16, Chris Green wrote: > I'm looking for a simple way to make NaN values output as something > like '-' or even just a space instead of the string 'nan'. I tried monkey-patching the __format__ method of float, but it's immutable, so that didnt' work. Is float.__format__ what's used by f-strings, the % operator, etc.? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Testing (sorry)
Today I noticed that nothing I've posted to python-list in past 3 weeks has shown up on the list. I don't know how to troubleshoot this other than sending test messages. Obviously, if this shows up on the list, then I've gotten it to work... -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Testing - 2 (sorry)
Today I noticed that nothing I've posted to python-list in past 3 weeks has shown up on the list. I don't know how to troubleshoot this other than sending test messages. Obviously, if this shows up on the list, then I've gotten it to work... -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Testing (sorry)
Today I noticed that nothing I've posted to python-list in past 3 weeks has shown up on the list. I don't know how to troubleshoot this other than sending test messages. Obviously, if this shows up on the list, then I'm making progress. [message 4] -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Testing (sorry)
Today I noticed that nothing I've posted to python-list in the past 3 weeks has shown up on the list. I don't know how to troubleshoot this other than by sending test messages. Obviously, if this shows up on the list, then I'm making progress... [message 3] -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Testing (sorry)
On 2024-02-18, Peter J. Holzer via Python-list wrote: > [Replying to the list *and* Grant] > > On 2024-02-17 19:38:04 -0500, Grant Edwards via Python-list wrote: >> Today I noticed that nothing I've posted to python-list in past 3 >> weeks has shown up on the list. > > January 29th, AFAICS. And end of december before that. > >> I don't know how to troubleshoot this other than sending test >> messages. Obviously, if this shows up on the list, then I've gotten >> it to work... > > This did show up and 3 other test messages with very similar text > as well. > > Also there was a whole flurry of almost but not quite identical messages > from you in the "nan" thread. Sorry about that. All of those were posted at various times throughout the day yesterday using two different accounts, two different mail servers, and three different methods for submitting the e-mails. I finally gave up and switched to using comp.lang.python via Usenet. Then, about 24 hours later, all those messages finally showed up. At one point about half way through that process yesterday, I unsusbscribed and then re-subscribed both e-mail addresses. I got confirmation and welcome messages on both accounts. Sending "help" requests to the list server produced the expected results. I enabled the sending of confirmation messages from the list server. But posts to the list still seemed to vanish into the ether while emails from both accounts reached other destinations without delay, During this process a number of posts from other users did appear in the list archive and at at _one_ of the two e-mail addresses which I had subscribed. But no sign of any of my posts. About 24 hours later, all of my posts (and the confirmation e-mails) all showed up in a burst at the same time on two different unrelated e-mail accounts. I still have no clue what was going on... -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Testing (sorry)
On 2024-02-19, Thomas Passin wrote: >> About 24 hours later, all of my posts (and the confirmation e-mails) >> all showed up in a burst at the same time on two different unrelated >> e-mail accounts. >> >> I still have no clue what was going on... > > Sometimes a post of mine will not show up for hours or even half a day. > They are all addressed directly to the list. Sometimes my email > provider sends me a notice that the message bounced. Those notices say > that the address wasn't available when the transmission was tried. I guess that in future I'll wait a couple days before I assume something is broken. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Can one output something other than 'nan' for not a number values?
On 2024-02-19, Chris Green via Python-list wrote: > It's using f'{...}' at the moment. Here's a demonstration of how to hook custom code into the f-string formatting engine. It's brilliantly depraved. https://stackoverflow.com/questions/55876683/hook-into-the-builtin-python-f-string-format-machinery >From the above: You can, but only if you write evil code that probably should never end up in production software. So let's get started! I'm not going to integrate it into your library, but I will show you how to hook into the behavior of f-strings. This is roughly how it'll work: 1. Write a function that manipulates the bytecode instructions of code objects to replace FORMAT_VALUE instructions with calls to a hook function; 2. Customize the import mechanism to make sure that the bytecode of every module and package (except standard library modules and site-packages) is modified with that function. Final code is here: https://github.com/mivdnber/formathack -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem resizing a window and button placement
On 2024-02-24, MRAB via Python-list wrote: > On 2024-02-24 01:14, Steve GS via Python-list wrote: > >> Python, Tkinter: How do I determine if a window has been resized? I >> want to locate buttons vertically along the right border and need >> to know the new width. The buttons are to move with the change of >> location of the right-side border. > > Bind an event handler for '': > > 8< > [...] > 8< > > Are you placing the buttons yourself? I always use layouts and they > handle such things automatically. Yes, definitely what he said: use a layout manager. I hope this doesn't sound rude, but if you're calculating button positions based on window size, you're doing it wrong and will end up wasting a lot of time to produce something that won't work right. Use a layout manager: https://tkinterpython.top/layout/#:~:text=Tkinter%20has%20three%20built%2Din,%2C%20grid%20%2C%20and%20place%20managers. https://www.pythonguis.com/tutorials/create-ui-with-tkinter-pack-layout-manager/ https://www.pythonguis.com/tutorials/use-tkinter-to-design-gui-layout/ You'll have to spend a little time learning how they work, but in the end you'll get done sooner and have better results. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference
On 2024-03-05, Cameron Simpson via Python-list wrote: > Because there are no variable definitions in Python, when you write > a function Python does a static analysis of it to decide which > variables are local and which are not. If there's an assignment to a > variable, it is a local variable. _Regardless_ of whether that > assignment has been executed, or gets executed at all (eg in an > if-statement branch which doesn't fire). Unfortunately, crap "information" sites like geeksforgeeks often describe this either incorrectly or so vaguely as to be worthless. >From the page https://www.geeksforgeeks.org/global-local-variables-python/ Python Global variables are those which are not defined inside any function and have a global scope whereas Python local variables are those which are defined inside a function and their scope is limited to that function only. Since "define" (in this context) isn't a term of art in Python, and it's never defined on the page in question, the quoted paragraph is not meaningful: it simply says that "global variables are global and local variables are local". That page goes on to say: In other words, we can say that local variables are accessible only inside the function in which it was initialized This is equally crap. It doesn't matter whether the variable is initialized or not. As Cameron correctly stated, if a function contains an assignment to a variable, and that variable is not declared global, then that variable is local. For example: def foo(): print(s) if 0: s = "there" print(s) In the function above s _is_not_ initialized in the function foo(). However, foo() does contain an assignment to s, therefore s is local unless declared global/nonlocal. [And the first print() will throw an exception even if there is a value bound to the global name 's'.] Unfortunately (presumably thanks to SEO) the enshittification of Google has reached the point where searching for info on things like Python name scope, the first page of links are to worthless sites like geeksforgeeks. -- https://mail.python.org/mailman/listinfo/python-list
Re: Can u help me?
On 2024-03-06, MRAB via Python-list wrote: > On 2024-03-06 01:44, Ethan Furman via Python-list wrote: >> On 3/5/24 16:49, MRAB via Python-list wrote: >> > On 2024-03-06 00:24, Ethan Furman via Python-list wrote: >> >> On 3/5/24 16:06, Chano Fucks via Python-list wrote: >> >> >> >>> [image: image.png] >> >> >> >> The image is of MS-Windows with the python installation window of >> "Repair Successful". Hopefully somebody better at >> >> explaining that problem can take it from here... >> >> >> > If the repair was successful, what's the problem? >> >> I imagine the issue is trying get Python to run (as I recall, the python >> icon on the MS-Windows desktop is the >> installer, not Python itself). > > There was an issue 3 years ago about renaming the installer for clarity: > > https://github.com/python/cpython/issues/87322 Yea, this problem comes up constantly (and has for many years). People have suggested renaming the installer so it has "setup" or "install" in the name. People have suggested adding text to the installer splash screen to explain that it's the installer and not python itself, that you already have python installed, and if you want to _run_ python instead of _install_ python, here's how. People have suggested having the installer remove itself by default when it's done installing. People have suggested lots of solutions. AFAICT, nobody has actually done anything. -- https://mail.python.org/mailman/listinfo/python-list
Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference
On 2024-03-06, Roel Schroeven via Python-list wrote: > Op 6/03/2024 om 17:40 schreef Jacob Kruger via Python-list: >> >>> from scoping2 import * > > [...] > > I would advice not to use 'import *', if at all possible, for multiple > reasons, one of which is to prevent problems like this. Unfortunately, many (most?) tutorials for particular modules (and even example code in the Python documentation itself) are all written assuming that you do "from import *". It saves the tutorial write a few keystrokes, but causes untold trouble for people who learn incorrectly that "from import *" is the proper way to do things. > I would also advice not to use global variables from other modules > directly, and in fact would advice to minimize the use of globals in > general as much as possible. If you need to keep state between > methods, it might be better to use a class. -- https://mail.python.org/mailman/listinfo/python-list
Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference
On 2024-03-07, dn via Python-list wrote: > The idea of importing a module into the REPL and then (repeatedly) > manually entering the code to set-up and execute is unusual (surely type > such into a script (once), and run that (repeatedly). As you say, most > of us would be working from an IDE and hitting 'Run'. Am wondering why > you weren't - but it's not important. Unless the code is intended to be used as a module, 'import'ing it into the REPL doesn't make sense. A simple example: ---testit.py-- x = 'x' y = 'y' def foo(): global y print("hi") x = 'X' y = 'Y' print(x) print(y) -- The usual method to play with that interactively is $ python -i testit.py >>> x 'x' >>> y 'y' >>> foo() hi X Y >>> x 'x' >>> y 'Y' >>> As we've seen, doing a 'from testit.py import *' doesn't let you test what the OP was trying to test. Doing 'import testit.py' gets you closer, but it's a hassle to test code that way. The right thing to do is 'python -i ' (or the equivalent button/option in an IDE). https://docs.python.org/3/tutorial/interpreter.html If you intended to use testit.py as a module, and wanted to experiment with its behavior as a module, then go ahead and import it. But, don't do 'from testit.py import *' until 1. you know how that differs from 'import testit.py' and 2. you want to use that difference -- https://mail.python.org/mailman/listinfo/python-list
Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference
On 2024-03-07, Cameron Simpson via Python-list wrote: > Yes. Note that the "global" namespace is the module in which the > function is defined. One might argue that "global" isn't a good choice for what to call the scope in question, since it's not global. It's limited to that source file. It doesn't make sense to me to call a binding "global", when there can be multile different "global" bindings of the same name. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference
On 2024-03-08, Chris Angelico via Python-list wrote: > On Sat, 9 Mar 2024 at 00:51, Grant Edwards via Python-list > wrote: > >> One might argue that "global" isn't a good choice for what to call the >> scope in question, since it's not global. It's limited to that source >> file. It doesn't make sense to me to call a binding "global", when >> there can be multile different "global" bindings of the same name. > > Most "globals" aren't global either, since you can have different > globals in different running applications. To me, "global" has always been limited to within a single process/address space, but that's probably just bias left over from C/Pascal/FORTRAN/assembly/etc. It never occurred to me that a global called "X" in one program on one computer would be the same as a global called "X" in a different program on a different computer somewhere else on the "globe". -- https://mail.python.org/mailman/listinfo/python-list
Re: pathlib.Path.is_file vs os.path.isfile difference
On 2024-03-08, Thomas Passin via Python-list wrote: > On 3/8/2024 1:03 PM, Albert-Jan Roskam via Python-list wrote: >> Hi, >> I was replacing some os.path stuff with Pathlib and I discovered this: >> Path(256 * "x").is_file() # OSError >> os.path.isfile(256 * "x") # bool >> Is this intended? Does pathlib try to resemble os.path as closely as >> possible? > > You must have an very old version of Python. I'm running 3.12.2 and it > returns False. It throws OSError with Python 3.11.8 on Linux. $ python Python 3.11.8 (main, Feb 23 2024, 16:11:29) [GCC 13.2.1 20240113] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pathlib >>> pathlib.Path(256 * "x").is_file() Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.11/pathlib.py", line 1267, in is_file return S_ISREG(self.stat().st_mode) ^^^ File "/usr/lib/python3.11/pathlib.py", line 1013, in stat return os.stat(self, follow_symlinks=follow_symlinks) ^^ OSError: [Errno 36] File name too long: '' >>> >>> import os >>> os.path.isfile(256 * "x") False -- https://mail.python.org/mailman/listinfo/python-list
Re: pathlib.Path.is_file vs os.path.isfile difference
On 2024-03-08, Grant Edwards via Python-list wrote: > On 2024-03-08, Thomas Passin via Python-list wrote: >> On 3/8/2024 1:03 PM, Albert-Jan Roskam via Python-list wrote: >>> Hi, >>> I was replacing some os.path stuff with Pathlib and I discovered this: >>> Path(256 * "x").is_file() # OSError >>> os.path.isfile(256 * "x") # bool >>> Is this intended? Does pathlib try to resemble os.path as closely as >>> possible? >> >> You must have an very old version of Python. I'm running 3.12.2 and it >> returns False. > > It throws OSError with Python 3.11.8 on Linux. > OSError: [Errno 36] File name too long: > '' On all of the Linux filesystems I know about, the max length for a filename is 255 bytes, so the OSError is too surprising, and it does seem to follow the documentation. >>>> import os >>>> os.path.isfile(256 * "x") > False However, os.path.isfile() apprently masks that error somehow and returns False instead. I notice that the os.path.isfile() documentation does not specify what happens if the path is not a file or is illegal. It only specifies that True is returned if the path is a regular file. Presumably something other than "return True" is supposed to happen, but exactly what is not specified. -- https://mail.python.org/mailman/listinfo/python-list
Re: pathlib.Path.is_file vs os.path.isfile difference
On 2024-03-08, Grant Edwards via Python-list wrote: >> OSError: [Errno 36] File name too long: >> '' > > On all of the Linux filesystems I know about, the max length for a > filename is 255 bytes, so the OSError is too surprising, and it does > seem to follow the documentation. Doh. I meant "is not too surprising". -- https://mail.python.org/mailman/listinfo/python-list
Re: pathlib.Path.is_file vs os.path.isfile difference
On 2024-03-08, Thomas Passin via Python-list wrote: > >> Hi, I tested this with Python 3.8. Good to know that this was fixed! > > We just learned a few posts back that it might be specific to Linux; I > ran it on Windows. On Linux, the limit is imposed by the filesystem. Most of the "real" filesystems on Linux have a 255 character limit, a few support 256, and some of the legacy filesystems have lower limits. Reiser4 is the only one that's even remotely common which supports more than 256 -- according to https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits it supports filenames up to 3976 bytes long. NB: The behavior when the limit is exceeded might also vary from one filesystem to another. In any case, the pathlib docs for is_file() are explicit: any errors from the underlying OS and libraries will be propogated. There is nothing to fix. https://docs.python.org/3/library/pathlib.html#pathlib.Path.is_file Path.is_file() Return True if the path points to a regular file (or a symbolic link pointing to a regular file), False if it points to another kind of file. False is also returned if the path doesn’t exist or is a broken symlink; other errors (such as permission errors) are propagated. -- https://mail.python.org/mailman/listinfo/python-list
Re: Configuring an object via a dictionary
On 2024-03-15, Thomas Passin via Python-list wrote: > On 3/15/2024 5:30 AM, Loris Bennett via Python-list wrote: >> Hi, >> >> I am initialising an object via the following: >> >> def __init__(self, config): >> >> self.connection = None >> >> self.source_name = config['source_name'] >> self.server_host = config['server_host'] >> self.server_port = config['server_port'] >> self.user_base = config['user_base'] >> self.user_identifier = config['user_identifier'] >> self.group_base = config['group_base'] >> self.group_identifier = config['group_identifier'] >> self.owner_base = config['owner_base'] >> >> However, some entries in the configuration might be missing. What is >> the best way of dealing with this? >> >> I could of course simply test each element of the dictionary before >> trying to use. I could also just write >> >> self.config = config >> >> but then addressing the elements will add more clutter to the code. >> >> However, with a view to asking forgiveness rather than >> permission, is there some simple way just to assign the dictionary >> elements which do in fact exist to self-variables? >> >> Or should I be doing this completely differently? > > self.source_name = config.get('source_name', default_value) > > Or, if you like this kind of expression better, > > self.source_name = config.get('source_name') or default_value Won't the latter version misbehave if the value of config['source_name'] has a "false" boolean value (e.g. "", 0, 0.0, None, [], (), {}, ...) >>> config = {} >>> config['source_name'] = "" >>> config.get('source_name') or 'default' 'default' -- https://mail.python.org/mailman/listinfo/python-list
Re: the name ``wheel''
On 2024-03-21, MRAB via Python-list wrote: > As it's recommended to use the Python Launcher py on Windows, I use > that instead: > > py -m pip install something > > because it gives better support if you have multiple versions of > Python installed. I adopted that practice years ago on Linux as well after wasting what seemed like most of a day trying to figure out problems which turned out to be caused by the fact that "pip" and "python" invoked different versions of Python. -- https://mail.python.org/mailman/listinfo/python-list
Re: Popping key causes dict derived from object to revert to object
On 2024-03-22, Loris Bennett via Python-list wrote: > Yes, I was mistakenly thinking that the popping the element would > leave me with the dict minus the popped key-value pair. It does. > Seem like there is no such function. Yes, there is. You can do that with either pop or del: >>> d = {'a':1, 'b':2, 'c':3} >>> d {'a': 1, 'b': 2, 'c': 3} >>> d.pop('b') 2 >>> d {'a': 1, 'c': 3} >>> d = {'a':1, 'b':2, 'c':3} >>> del d['b'] >>> d {'a': 1, 'c': 3} In both cases, you're left with the dict minus the key/value pair. In the first case, the deleted value printed by the REPL because it was returned by the expression "d.pop('b')" (a method call). In the second case is no value shown by the REPL because "del d['b']" is a statement not an expression. -- https://mail.python.org/mailman/listinfo/python-list
Re: Popping key causes dict derived from object to revert to object
On 2024-03-25, Loris Bennett via Python-list 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 >>> leave me with the dict minus the popped key-value pair. >> >> It does. > > Indeed, but I was thinking in the context of > > dict_list = [d.pop('a') for d in dict_list] > > and incorrectly expecting to get a list of 'd' without key 'a', instead > of a list of the 'd['a]'. So when you say "leave me with", you mean "return the same dictionary with"? There's an important difference between what a function returns and what global/local state it "leaves you with". > Thanks for pointing out 'del'. My main problem, however, was > failing to realise that the list comprehension is populated by the > return value of the 'pop', not the popped dict. OK, so perhaps you weren't execting the original dict objects to be mutated, but rather that the pop method would return a new dict object without the "popped" element. The whole point of the 'pop method is to return the popped value, otherwise it wouldn't be needed. The 'del' statement would suffice. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to Add ANSI Color to User Response
On 2024-04-10, WordWeaver Evangelist via Python-list wrote: > I have a simple question. I use the following textPrompt in some of my Jython > modules: > '\n[1;33mYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, > forceUppercase=True) > Is there a way to add an ANSI color code to the end where the > conditions are, so that the color of the user’s input is of a color > of my choosing, instead of just white? I'm not sure what is meant by "the end where the conditions are", nor do I know what "textPrompt" refers to. Are you asking how to put a second escape sequence at the end of the string literal after the colon? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: How to Add ANSI Color to User Response
On 2024-04-10, Alan Gauld via Python-list wrote: > On 10/04/2024 19:50, WordWeaver Evangelist via Python-list wrote: > >> I have a simple question. I use the following textPrompt in some of my >> Jython modules: >> '\n[1;33mYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, >> forceUppercase=True) >> Is there a way to add an ANSI color code to the end > > Normally, for any kind of fancy terminal work, I'd say use curses. If you want to use the terminal escape sequences provided by terminfo and ncurses, but don't want to use the ncurses windowing functions, here are some notes on how to do that: https://github.com/GrantEdwards/Python-curses-and-terminfo That too is C-Python oriented, and I don't really know how to do the same things using Jython. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator
On 2024-05-14, Alan Gauld via Python-list wrote: > On 14/05/2024 18:44, Gordinator via Python-list wrote: > >> I wish to write a terminal emulator in Python. I am a fairly >> competent Python user, and I wish to try a new project idea. What >> references can I use when writing my terminal emulator? I wish for >> it to be a true terminal emulator as well, not just a Tk text >> widget or something like that. > > The first thing is to decide which terminal. You also need to decide if you're going to support real serial ports or just ptys. -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator
On 2024-05-14, Alan Gauld via Python-list wrote: > On 14/05/2024 18:44, Gordinator via Python-list wrote: > >> I wish to write a terminal emulator in Python. I am a fairly >> competent Python user, and I wish to try a new project idea. What >> references can I use when writing my terminal emulator? I wish for >> it to be a true terminal emulator as well, not just a Tk text >> widget or something like that. > > The first thing is to decide which terminal. If you want to make life easier, make it a superset of a terminal that already exists in the terminfo database. Going with some sort of ANSI terminal will probably provide operability even with dumb apps which ignore $TERM and just spit out basic ANSI escape sequences. If you really want to break trail, you could invent your own control sequences, which means you'll have to write terminfo and/or termcap entries as well as the terminal emulator. > A VT100 is very different from a 3270. And even a VT330 is quite > different from a VT100 although sharing a common subset of control > codes. And if you start looking at graphical terminals things get > even more interesting! "Intersting" is putting it mildly... -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-18, Peter J. Holzer via Python-list wrote: > On 2024-05-16 19:46:07 +0100, Gordinator via Python-list wrote: > >> To be fair, the problem is the fact that they use Windows (but I >> guess Linux users have to deal with venvs, so we're even. > > I don't think Linux users have to deal with venvs any more than > Windows users. Maybe even less because many distributions come with > a decent set of Python packages. I've been using Python on Linux almost daily for 25 years, and I've yet to use a venv... -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-18, Mats Wichmann via Python-list wrote: > Distros have do offer a good selection of packaged Python bits, yes, but > only for the version of Python that's "native" to that distro release. > If you need to test other versions of Python, you're mostly on your own. For a few years I needed both 2.x and 3.x installed, but my distro (Gentoo) handled that fine (I think most others do also). Gentoo also allows multiple minor versions to be installed (currently I have 3.11 and 3.12 on this machine). But, since Gentoo is a source-based meta-distro, when I install a Python package, the package manager knows how to install it for all installed Python versions that are supported by the package. I can't think of why I would need a venv unless I needed to test something with a Python version that isn't available for Gentoo. That said, there are currently 7 versions available (2.7.18, 3.8.19, 3.9.19, 3.10.14, 3.11.9, 3.12.3, 3.13.0). 3.13 isn't marked stable yet in the Gentoo package database, and I apparently have some Python app/package installed that doesn't yet support 3.12, so I've currently got both 3.12 and 3.11. -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-19, Alan Gauld via Python-list wrote: >> The dependency nightmare created by python, pip >> and all the rest cannot be resolved otherwise. > > I've honestly never experienced this "nightmare". > I install stuff and it just works. Same here. I occasonlly use pip to install something that isn't packaged for Gentoo, but it doesn't seem to cause problems — let alone nightmares. I also occasionally package something myself. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-19, Gilmeh Serda via Python-list wrote: > On Sun, 19 May 2024 08:32:46 +0100, Alan Gauld wrote: > >> I've honestly never experienced this "nightmare". >> I install stuff and it just works. > > Hear! Hear! Me too! And all that. > > I'm on Manjaro, which is a tad finicky about other people touching its > Python since it's used for lots of things. I install things for myself > only. > > Was there a reason they chose the name Pip? I always assumed it was in honor of the PIP (Peripheral Interchange Program?) utility that was used to copy files around on CP/M and DEC's PDP-11 OSes. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-19, Barry via Python-list wrote: > > >> On 18 May 2024, at 16:27, Peter J. Holzer via Python-list >> wrote: >> >> I don't think Linux users have to deal with venvs > > Modern debian (ubuntu) and fedora block users installing using pip. You can't even use pip to do "user" installs? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Weird Stuff (Markdown, syntax highlighting and Python)
On 2024-05-26, Gilmeh Serda via Python-list wrote: > The web claims (I think on all pages I've read about Markdown and Python) > that this code should work, with some very minor variants on the topic: > > ```python > > import os > > with open(os.path.join('/home/user/apath', 'somefile')) as f: > print(f.read()) > ``` > > However, that is not the case. For me, that block formats as expected using Python markdown. What do you mean by "this code should work [...] that is not the case"? What markdown rendering engine are you using? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Flubbed it in the second interation through the string: range error... HOW?
On 2024-05-29, Chris Angelico via Python-list wrote: > print(f"if block {name[index]=} {index=}") Holy cow! How did I not know about the f-string {=} thing? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Flubbed it in the second interation through the string: range error... HOW?
On 2024-05-29, Mats Wichmann via Python-list wrote: > On 5/29/24 08:02, Grant Edwards via Python-list wrote: >> On 2024-05-29, Chris Angelico via Python-list wrote: >> >>> print(f"if block {name[index]=} {index=}") >> >> Holy cow! How did I not know about the f-string {=} thing? > > It's more recent than f-strings in general, so it's not that hard to miss. I really should make a habit of reading through the "what's new" pages when new releases come out... -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: From JoyceUlysses.txt -- words occurring exactly once
On 2024-05-31, Pieter van Oostrum via Python-list wrote: > HenHanna writes: > >> Given a text file of a novel (JoyceUlysses.txt) ... >> >> could someone give me a pretty fast (and simple) Python program that'd >> give me a list of all words occurring exactly once? >> >> -- Also, a list of words occurring once, twice or 3 times >> >> re: hyphenated words(you can treat it anyway you like) >> >>but ideally, i'd treat [editor-in-chief] >>[go-ahead] [pen-knife] >>[know-how] [far-fetched] ... >>as one unit. >> > > That is a famous Unix task : (Sorry, no Python) > > grep -o '\w*' JoyceUlysses.txt | sort | uniq -c | sort -n Yep, that's what came to my mind (though I couldn't remember the exact grep option without looking it up). However, I assume that doesn't get you very many points on a homework assignemnt from an "Intruction to Python" class. -- https://mail.python.org/mailman/listinfo/python-list
Re: From JoyceUlysses.txt -- words occurring exactly once
On 2024-06-03, Edward Teach via Python-list wrote: > The Gutenburg Project publishes "plain text". That's another > problem, because "plain text" means UTF-8and that means > unicode...and that means running some sort of unicode-to-ascii > conversion in order to get something like "words". A couple of > hoursa couple of hundred lines of Cproblem solved! I'm curious. Why does it need to be converted frum Unicode to ASCII? When you read it into Python, it gets converted right back to Unicode... -- https://mail.python.org/mailman/listinfo/python-list
Re: From JoyceUlysses.txt -- words occurring exactly once
On 2024-06-04, Edward Teach via Python-list wrote: > On Mon, 03 Jun 2024 14:58:26 -0400 (EDT) > Grant Edwards wrote: > >> On 2024-06-03, Edward Teach via Python-list >> wrote: >> >> > The Gutenburg Project publishes "plain text". That's another >> > problem, because "plain text" means UTF-8and that means >> > unicode...and that means running some sort of unicode-to-ascii >> > conversion in order to get something like "words". A couple of >> > hoursa couple of hundred lines of Cproblem solved! >> >> I'm curious. Why does it need to be converted frum Unicode to ASCII? >> >> When you read it into Python, it gets converted right back to >> Unicode... > Well.when using the file linux.words as a useful master list of > "words".linux.words is strict ASCII I guess I missed the part of the problem description where it said to use linux.words to decide what a word is. :) -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: From JoyceUlysses.txt -- words occurring exactly once
On 2024-06-05, dn via Python-list wrote: > If you/your teacher can't define a "word", the code, any code, will > almost-certainly be wrong! Back when I was a student... When there was a homework/project assignemnt with a vague requirement (and it wasn't practical to get the requirement refined), what always worked for me was to put in the project report or program comments or somewhere a statement that the requirement could be interpreted in different ways and here is the precise interpretation of the requirement that is being implemented. -- https://mail.python.org/mailman/listinfo/python-list
Re: From JoyceUlysses.txt -- words occurring exactly once
On 2024-06-08, Larry Martell via Python-list wrote: > The original question struck me as homework or an interview question for a > junior position. But having no clear requirements or specifications is good > training for the real world where that is often the case. When you question > that, you are told to just do something, and then you’re told it’s not what > is wanted. That frustrates people but it’s often part of the process. > People need to see something to help them know what they really want. Too true. You can spend all sorts of time getting people to pin down and sign off on the initial requirements, but it all goes right out the window when they get the first prototype. "This isn't what we want, we want it to do ." "It does what you specified." "But, this isn't what we want." ... If you're on salary, it's all part of the job. If you're a contractor, you either figure it in to the bid or charge for change orders. -- https://mail.python.org/mailman/listinfo/python-list
Re: Anonymous email users
On 2024-06-17, Roel Schroeven via Python-list wrote: > FWIW, personally I (mostly) don't see the point of replying to people > personally. To me a public mailing list is much like any public forum, > where my expectation is that conversations happen in public. To me it > always feels weird when I get a personal reply when I make a public post > in a mailing list. I mostly ignore those, unless there's really > something in it that's best kept out of the public. My sentiments exactly. I generally don't even read replies that get mailed to me. They almost always seem to be copies of replies that were also posted to the mailing list (which I read using an NNTP client pointed at news.gmane.io). -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Anonymous email users
On 2024-06-18, Mats Wichmann via Python-list wrote: > On 6/17/24 17:51, dn via Python-list wrote: > >> +1 >> >> The "public" part is not to embarrass posters, but recognition that >> there are likely other people 'out there' (or arriving in-future if they >> care to read the archives) experiencing a similar problem. (hence need >> for descriptive Subject lines - isn't the most difficult task in >> programming 'choosing names'?) > > well, one of two, along with cache invalidation and off-by-one errors > (according to the wags). > > I do agree with this, but mailman (2) archives aren't particularly > useful for searching, as they're organized in monthly chunks and you > have to keep clicking around - this list doesn't have a search engine as > it's not converted to be one of the mailman 3 lists. Gmane used to have a usable search feature (along with a decent threaded web UI to read the arhives), but that got lost during the great gmane server/domain upheaval of 2016 (or whenever that was). I still miss it. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Anonymous email users
On 2024-06-24, Barry Scott via Python-list wrote: >> On 23 Jun 2024, at 06:58, Sebastian Wells via Python-list >> wrote: >> >> The spammers won the spam wars, so even if you have someone's real >> e-mail address, that's no guarantee that you can contact them. [...] > > My email address is well known and yes I get spam emails. I've been puzzled by this for a long time. Many people talk about how they get so much spam e-mail that there's little chance they'll notice if I send them an e-mail. I've been using the same e-mail address for about 20 years. I've use that e-mail address with probably close to 100 retailers, charities, open-source projects, media sites, and various other organizations. I get at most a few spam emails per week [I just checked my spam folder: 8 in the past 30 days]. And Gmail is very, very close to 100% accurate at filtering them out. I can't remember the last time I actually got a spam message in my inbox. > A few years ago the spam count was greater than a 1,000 a month. I'm baffled. Is Gmail silently rejecting that much junk before it even gets to the filter that puts stuff into my "spam" folder? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Predicting an object over an pretrained model is not working
On 2024-07-31, marc nicole via Python-list wrote: > I suppose the meaning of those numbers comes from this line > predicts_dict[class_name].append([int(xmin), int(ymin), int(xmax), > int(ymax), P[index]]) as well as the yolo inference call. But i was > expecting zeros for all classes except smallball. That's not how machine learning and object recognition works. > Because the image only shows that, You know that. The machine doesn't. > and that a train and a sheep wont have any target position or any > probability whatsoever in the image weirdobject.jpg That depends on the training data and how the model works. You should probably do some reading on neural networks, machine learning, and pattern/object recognition. You appear to be trying to use tools without understanding what they do or how they work. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: python C-api and thread
On 2024-08-05, aotto1968 via Python-list wrote: > Is it possible to run two completely independent Python interpreters > in one process, each using a thread? > > By independent, I mean that no data is shared between the > interpreters and thus the C API can be used without any other > "lock/GIL" etc. No, not using any OS I've ever seen. The usual definition of "threads" is that they share data, and the definition of "processes" is that processes don't share data. How exactly does what you're trying to do differ from runnig two Python interpreters in two processes? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Formatting a str as a number
On 2024-08-27, Gilmeh Serda via Python-list wrote: > On 25 Aug 2024 15:46:25 GMT, Stefan Ram wrote: > >> f"{int(number):>20,}" > > Great. Thanks. Do you have a link to where that's documented? > > I did web search, found nothing. https://docs.python.org/3/library/string.html#formatspec https://docs.python.org/3/reference/lexical_analysis.html#f-strings -- https://mail.python.org/mailman/listinfo/python-list
Re: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API
On 2024-09-30, Left Right via Python-list wrote: > Whether and to what degree you can stream JSON depends on JSON > structure. In general, however, JSON cannot be streamed (but commonly > it can be). > > Imagine a pathological case of this shape: 1... <60GB of digits>. This > is still a valid JSON (it doesn't have any limits on how many digits a > number can have). And you cannot parse this number in a streaming way > because in order to do that, you need to start with the least > significant digit. Which is how arabic numbers were originally parsed, but when westerners adopted them from a R->L written language, thet didn't flip them around to match the L->R written language into which they were being adopted. So now long numbers can't be parsed as a stream in software. They should have anticipated this problem back in the 13th century and flipped the numbers around. -- https://mail.python.org/mailman/listinfo/python-list
Re: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API
On 2024-09-30, Dan Sommers via Python-list wrote: > On 2024-09-30 at 11:44:50 -0400, > Grant Edwards via Python-list wrote: > >> On 2024-09-30, Left Right via Python-list wrote: >> > [...] >> > Imagine a pathological case of this shape: 1... <60GB of digits>. This >> > is still a valid JSON (it doesn't have any limits on how many digits a >> > number can have). And you cannot parse this number in a streaming way >> > because in order to do that, you need to start with the least >> > significant digit. >> >> Which is how arabic numbers were originally parsed, but when >> westerners adopted them from a R->L written language, thet didn't >> flip them around to match the L->R written language into which they >> were being adopted. > > Interesting. > >> So now long numbers can't be parsed as a stream in software. They >> should have anticipated this problem back in the 13th century and >> flipped the numbers around. > > What am I missing? Handwavingly, start with the first digit, and as > long as the next character is a digit, multipliy the accumulated > result by 10 (or the appropriate base) and add the next value. > [...] But why do I need to start with the least significant digit? Excellent question. That's actully a pretty standard way to parse numeric literals. I accepted the claim at face value that in JSON there is something that requires parsing numeric literals from the least significant end -- but I can't think of why the usual algorithms used by other languages' lexers for yonks wouldn't work for JSON. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API
On 2024-09-30, Dan Sommers via Python-list wrote: > In Common Lisp, integers can be written in any integer base from two > to thirty six, inclusive. So knowing the last digit doesn't tell > you whether an integer is even or odd until you know the base > anyway. I had to think about that for an embarassingly long time before it clicked. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python List is Not Dead
On 2024-12-27, Chris Green via Python-list wrote: > Cameron Simpson wrote: >> On 25Dec2024 14:52, Abdur-Rahmaan Janhangeer wrote: >> >I have been following discussions on Discourse (discuss.python.org) >> >these last times. >> > >> >I think that it definitely lacks some of the joys of the mailing list: >> >> FYI, it has a very good "mailing list" mode. I use it that was >90% of >> the time, and file both posts from Discourse and posts from python-list >> into my "python" mail folder. > > Yes, it's the one saving grace of a Discourse forum, you can use it by > E-Mail and it behaves quite nicely with a text mode E-Mail client such > as mutt so you can keep threads separate, follow sub-threads, etc. > > Not quite as good as this list gatewayed to usenet though, there's > really nothing so good as usenet for proper discourse (!). Don't forget you can also read this list (and thousands of others) via the NNTP server at news.gmane.io. There really is no better way to read lists that with a good news client. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Version of OpenSSl ?
On 2025-02-09, Left Right via Python-list wrote: > You need the sources of the OpenSSL library, not the compiled library. > On Ubuntu, the packages with sources are typically named xxx-dev where > xxx is the package that provides the library. I don't have a Ubuntu > currently, but try looking for something like openssl-dev or > libopenssl-dev etc. Do the -dev packages on Ubuntu really contain the sources for the libraries? I knew they contained the static libraries and the include files required to build against the libraries, but I didn't think they contained the library sources. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Version of OpenSSl ?
On 2025-02-10, Chris Angelico via Python-list wrote: > On Tue, 11 Feb 2025 at 04:04, Grant Edwards via Python-list > wrote: >> On 2025-02-09, Left Right via Python-list wrote: >> >>> You need the sources of the OpenSSL library, not the compiled library. >>> On Ubuntu, the packages with sources are typically named xxx-dev [...] >> >> Do the -dev packages on Ubuntu really contain the sources for >> the libraries? > > No they don't, and Mr "Left Right" is talking out his, uhh, "Back". :) > >> I knew they contained the static libraries and the include files >> required to build against the libraries, but I didn't think they >> contained the library sources. > > They contain everything you need to link to the library. That > usually means headers and libraries, and also pkgconfig files to > point to their locations, plus anything else you might need. But no > sources. That's the job of source archives. Yep, I got curious and ssh'ed into one of the Ubuntu server machines I maintain and looked at the files installed by some of the -dev packages. [Those machines aren't used for development so didn't have many of them.] The -dev packages also contain the man pages for the libraries. It surprised me at first that the man pages weren't installed by the "normal" lib packages. But, if you're not writing/building apps that link with library X, you don't need the man pages for library X. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: it's a shame... python error over error
On 2024-12-16, aotto1968 via Python-list wrote: > If I read the answers I come to the conclusion that the "supporters" > at python doesn't ever understand the problem. You should definitely demand to speak to the manager and request your money back. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Tools to help with text mode (i.e. non-GUI) input
On 2025-01-17, Alan Gauld via Python-list wrote: > On 15/01/2025 00:41, Keith Thompson via Python-list wrote: >> Alan Gauld writes: >>> On 11/01/2025 14:28, Chris Green via Python-list wrote: I'm looking for Python packages that can help with text mode input, >>> >>> The standard package for this is curses which comes as part >>> of the standard library on *nix distros. >> >> The thing about curses (which may or may not be a problem) is that, by >> design, it takes over the whole screen. If you want to do simpler text >> manipulations (showing a dismissible message, showing bold text, etc.) >> without interfering with existing text, curses can't do it, at least not >> easily. > > It's not that difficult to use the terminfo codes directly. It's easy to do, but it's tricky to do it right. https://github.com/GrantEdwards/Python-curses-and-terminfo > [...] > > Here is "hello world" in bold... > > import curses > curses.setupterm() > bold = curses.tigetstr('bold').decode('ascii') > normal = curses.tigetstr('sgr0').decode('ascii') > > print(bold, 'Hello world', normal) Don't forget to use tparm() to parameterize strings for things like "move curser". Once you've parameterized the string (if needed), you've _might_ need to worry about the stuff in the string that's meant to be interpreted by tputs/putp: Quoting man tparm(3) All terminfo strings [including the output of tparm] should be printed with tputs or putp. That's becuase terminfo strings can contain escape sequences that are filterd out and interpreted by tputs/putp. The approach above only works if you only care about certain terminals, and you know that none of the terminfo strings you're using have those interal terminfo escape sequences in them [AFAIK, that's true for the linux console, xterm and the like, but not for many serial terminals.] -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Tools to help with text mode (i.e. non-GUI) input
On 2025-01-13, Alan Gauld via Python-list wrote: > All of that is possible in curses, you just have to code it. All of that is easy with curses in C. Unfortunately, the high level "panel" and "menu" curses subystems that make it easy aren't included in the Python curses API, so doing it in Pyhton is a _lot_ more work than doing it in C. I always like the Python API for the newt library (yonks ago it was used for the Redhat installer), but haven't used it for years. -- https://mail.python.org/mailman/listinfo/python-list
Re: Tools to help with text mode (i.e. non-GUI) input
On 2025-01-14, Alan Gauld via Python-list wrote: > On 14/01/2025 00:20, Grant Edwards via Python-list wrote: >> On 2025-01-13, Alan Gauld via Python-list wrote: >> >>> All of that is possible in curses, you just have to code it. >> >> All of that is easy with curses in C. Unfortunately, the high level >> "panel" and "menu" curses subystems that make it easy aren't included >> in the Python curses API, > > panel is included. Just import curses.panel. Ah my bad, I meant "forms" and "menu" support was missing. > menu unfortunately isn't but it's not difficult to roll your own by > creating a window with a list of options, provided you don't try to > get too fancy(submenus etc). Yea, it was "menu" and "forms" that I really wanted. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Tools to help with text mode (i.e. non-GUI) input
On 2025-01-14, Chris Green via Python-list wrote: > Yes, thanks all, maybe just straightforward curses is the way to go. > Looking at some of the 'cleverer' ones they end up looking remarkably > like GUI code, in which case I might as well use a GUI. The source code to configure and handle a UI with a certain set of input widgets is going to be pretty much the same regardless of the low-level screen bashing details involved in rendering the widgets. You choose a TUI toolkit like curses panel/menu/forms instead of a GUI toolkit like gtk because you need your app to run on a terminal instead of on a X11/wayland screen, not because you want your app to be simpler than the code for a GUI app (as you've seen, it isn't). > I have written a (fairly simple) Gtk based python program, I was > just trying to avoid all the GUI overheads for a little new project. If you want to avoid the [TG]UI overhead, then command line options are your friend. If that's not sophisticated enough the gnu "readline" library with a simple command processor is a common next step. Or you can use curses to print some help stuff at the top of the terminal window and then do everything based on single-stroke "command keys" that print output in the lower part of the terminal window. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Pip installs to unexpected place
On 2025-04-17, Left Right via Python-list wrote: >> Also... when installing stuff with pip --user, it is always a package >> that is not installed for the system (usually not even available for >> the system). How can that "break system packages"? > > pip installs dependencies. Dependencies may disagree on the version > with the system packages. Good point. I don't generally allow pip to install dependencies, so I forgot about that source of conflict. But as far as I can see, it still can only break stuff for the user, not for the system. The system is never going to look in my ~/.local/lib/python* directories. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Pip installs to unexpected place
On 2025-04-16, Mats Wichmann via Python-list wrote: > On 4/15/25 16:07, Grant Edwards via Python-list wrote: >> On 2025-04-15, Thomas Passin via Python-list wrote: >> >>> On Linux, at least, it's standard for pip to install into the user's >>> site-packages location if it's not invoked with admin privileges - even >>> without --user. Pip will emit a message saying so. Well, that used to be >>> true but nowadays Pip wants you to use the --break-system-packages flag >>> if you want to insist on installing into the system's Python install, >>> even if it's going to go into --user. >> >> I've always been a little baffled by that message when installing with >> --user. How can that possibly break system stuff? > > Your user install dir is in your python path, so when you go to run an > installed Python program which imports other packages, it might pick up > the version you have in your user space rather than the system one it > was tested with. Yes, I understand that. But that's breaking stuff for the user not for the system. Of course installing stuff for the user can break stuff for the user. I don't need a warning to tell me that. Also... when installing stuff with pip --user, it is always a package that is not installed for the system (usually not even available for the system). How can that "break system packages"? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Pip installs to unexpected place
On 2025-04-15, Thomas Passin via Python-list wrote: > On Linux, at least, it's standard for pip to install into the user's > site-packages location if it's not invoked with admin privileges - even > without --user. Pip will emit a message saying so. Well, that used to be > true but nowadays Pip wants you to use the --break-system-packages flag > if you want to insist on installing into the system's Python install, > even if it's going to go into --user. I've always been a little baffled by that message when installing with --user. How can that possibly break system stuff? -- https://mail.python.org/mailman/listinfo/python-list