From mentificium at gmail.com Wed Jul 1 08:44:35 2020 From: mentificium at gmail.com (mentificium at gmail.com) Date: Wed, 1 Jul 2020 05:44:35 -0700 (PDT) Subject: Preliminary Design for Teaching Latin and Artificial Intelligence Message-ID: <5e7313fc-e752-4108-beb3-1821bb63cef9o@googlegroups.com> 1. Stage One: Linguistics and Neuroscience Teach the students the idea of a sentence and also the idea of a neuronal structure that generates a sentence. 2. Stage Two: Introduce a Particular Programming Language Use PYTHON as a major AI language, or possibly use tutorial JavaScript as a teaching language, since the Mens Latina AI already exists in JavaScript for Microsoft Internet Explorer. Possibly poll the students to see if significant numbers of students already know a particular coding language or are learning such a language. If the host institution uses a particular programming language like Python to introduce computer programming to students in general, then perhaps use the same coding language for teaching Latin AI. 3. Stage Three: Teach Vocabulary as an Array of Concepts 4. Stage Four: Teach Pronunciation as an Array of Phonemic Words 5. Stage Five: Teach Noun-Declension and the Noun-Phrase Mind-Module 6. Stage Six: Teach Verb-Conjugation and the Verb-Phrase Mind-Module 7. Stage Seven: Teach Moods Indicative, Imperative, Interrogative, Subjunctive 8. Stage Eight: Teach Volition Mind-Module as Invoker of Imperative Mood Divide free will or volition into its thinking component and its emotional component. 9. Stage Nine: Teach Thinking as Divisible into Statements and Inferences 10. Stage Ten: Teach Conjunctions as Vocabulary for ConJoin Module 11. Stage Eleven: Teach Prepositions as Vocabulary for LaPrep Module 12. Stage Twelve: Publish a Joint Latin and AI Textbook Embed the AI material in such a way that a teacher wishing to teach only the Latin may skip the AI material about neuroscience and programming and natural language processing (NLP). http://ai.neocities.org/LaThink.html -- Latin AI Thinking Module. #LatinAI #AI4U #AiGuarantee #AiHasBeenSolved #Python From dieter at handshake.de Wed Jul 1 13:35:20 2020 From: dieter at handshake.de (Dieter Maurer) Date: Wed, 1 Jul 2020 19:35:20 +0200 Subject: How to handle async and inheritance? In-Reply-To: References: Message-ID: <24316.51544.523410.252724@ixdm.fritz.box> Stephen Rosen wrote at 2020-6-30 11:59 -0400: >Hi all, > >I'm looking at a conflict between code sharing via inheritance and async >usage. I would greatly appreciate any guidance, ideas, or best practices >which might help. > >I'll speak here in terms of a toy example, but, if anyone wants to look at >the real code, I'm working on webargs. [1] Specifically, we have a `Parser` >class and an `AsyncParser` subclass, and the two have a lot of code >duplication to handle async/await. [2] > > >I've got an inheritance structure like this: > >class MyAbstractType: ... >class ConcreteType(MyAbstractType): ... >class AsyncConcreteType(MyAbstractType): ... > >One of my goals, of course, is to share code between ConcreteType and >AsyncConcreteType via their parent. >But the trouble is that there are functions defined like this: > >class MyAbstractType: > def foo(self): > x = self.bar() > y = self.baz(x) > ... # some code here, let's say 20 lines > >class AsyncConcreteType(MyAbstractType): > async def foo(self): > x = await self.bar() > y = self.baz(x) > ... # the same 20 lines as above, but with an `await` added >every-other line > > >I'm aware that I'm looking at "function color" and that my scenario is >pitting two language features -- inheritance and async -- against one >another. But I don't see a clean way out if we want to support an >"async-aware" version of a class with synchronous methods. > >What I tried already, which I couldn't get to work, was to either fiddle >with things like `inspect` to see if the current function is async or to >use a class variable to indicate that the current class is the async >version. The idea was to write something like > >class MyAbstractType: > _use_async_calls = False > def foo(self): > x = self._await_if_i_am_async(self.bar) > y = self.baz(x) > ... > >and that way, the async subclass just needs to change signatures to be >async with little stubs and set the flag, > >class AsyncConcreteType(MyAbstractType): > _use_async_calls = True > async def foo(self): > return super().foo() > async def bar(self): > return super().bar() As far as I understand (I am far from an `async` expert), `async` functions need to be specially compiled. This implies that there cannot be a runtime switch which makes a given function asynchronous or synchronous at runtime. You would need to have 2 functions, one asynchronous and one synchronous. Then a runtime switch may select the appropriate function. You likely can generate one of those function kinds from the other one by an `ast` (= "Abstract Syntax Tree") transformation. From hunter.hammond.dev at gmail.com Wed Jul 1 14:21:58 2020 From: hunter.hammond.dev at gmail.com (hunter.hammond.dev at gmail.com) Date: Wed, 1 Jul 2020 11:21:58 -0700 (PDT) Subject: trying to improve my knn algorithm Message-ID: <9942d247-89bc-4847-abed-499ed0c85e92o@googlegroups.com> This is a knn algorithm for articles that I have gotten. Then determines which category it belongs to. I am not getting very good results :/ k = 23 training_folder = './data/training/' minn_folder = training_folder + 'Minnesota/' health_folder = training_folder + 'Health/' def remove_punctuation(text): return regex.sub(r'\p{P}+', "", text) def file_list(folder): return [f for f in listdir(folder) if isfile(join(folder, f))] def all_file_list(): minn_files = file_list(minn_folder) for i in range(len(minn_files)): minn_files[i] = minn_folder + minn_files[i] health_files = file_list(health_folder) for i in range(len(health_files)): health_files[i] = health_folder + health_files[i] return minn_files + health_files def file_to_word_list(f): fr = open(f, 'r') text_read = fr.read() text = remove_punctuation(text_read) return text.split() def get_vocabularies(all_files): voc = {} for f in all_files: words = file_to_word_list(f) for w in words: voc[w] = 0 return voc def load_training_data(): all_files = all_file_list() voc = get_vocabularies(all_files) training_data = [] for f in all_files: tag = f.split('/')[3] point = copy.deepcopy(voc) words = file_to_word_list(f) for w in words: point[w] += 1 d = {'tag': tag, 'point': point} training_data.append(d) return training_data def get_distance(p1, p2): sq_sum = 0 for w in p1: if w in p2: sq_sum += pow(p1[w] - p2[w], 2) return math.sqrt(sq_sum) # This function is implemented for seeing insights of training data def show_distances(training_data): for i in range(len(training_data)): for j in range(i + 1, len(training_data)): print('d(' + str(i) + ',' + str(j) + ')=') print(get_distance(training_data[i]['point'], training_data[j]['point'])) print() for i in range(len(training_data)): print(training_data[i]['tag']) def test(training_data, txt_file): dist_list = [] txt = {} item = {} max_i = 0 words = file_to_word_list(txt_file) for w in words: if w in txt: txt[w] += 1 else: txt[w] = 1 for pt in training_data: item['tag'] = pt['tag'] item['distance'] = get_distance(pt['point'], txt) if len(dist_list) < k: dist_list.append(copy.deepcopy(item)) else: for i in range(1, k): if dist_list[i]['distance'] > dist_list[max_i]['distance']: max_i = i if dist_list[max_i]['distance'] > item['distance']: dist_list[max_i] = item vote_result = {} for d in dist_list: if d['tag'] in vote_result: vote_result[d['tag']] += 1 else: vote_result[d['tag']] = 1 # print(vote_result) # for testing result = dist_list[0]['tag'] for vote in vote_result: if vote_result[vote] > vote_result[result]: result = vote return result def main(txt): td = load_training_data() print(show_distances(td)) # show_distances(td) # for test usage only print('Category: ' + test(td, txt)) if __name__ == '__main__': main(sys.argv[1]) From __peter__ at web.de Wed Jul 1 16:57:29 2020 From: __peter__ at web.de (Peter Otten) Date: Wed, 01 Jul 2020 22:57:29 +0200 Subject: trying to improve my knn algorithm References: <9942d247-89bc-4847-abed-499ed0c85e92o@googlegroups.com> Message-ID: hunter.hammond.dev at gmail.com wrote: > This is a knn algorithm for articles that I have gotten. Then determines > which category it belongs to. I am not getting very good results :/ [snip too much code;)] - Shouldn't the word frequency vectors be normalized? I don't see that in your code. Without that the length of the text may overshade its contents. - There are probably words that are completely irrelevant. Getting rid of these should improve the signal-to-noise ratio. From kyrohammy at gmail.com Wed Jul 1 18:23:55 2020 From: kyrohammy at gmail.com (kyrohammy at gmail.com) Date: Wed, 1 Jul 2020 15:23:55 -0700 (PDT) Subject: trying to improve my knn algorithm In-Reply-To: References: <9942d247-89bc-4847-abed-499ed0c85e92o@googlegroups.com> Message-ID: <6024a7a7-4de0-4f6a-9179-3d1f239121bfo@googlegroups.com> This is another account but I am the op. Why do you mean normalize? Sorry I?m new at this. From mal at europython.eu Thu Jul 2 05:05:53 2020 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 2 Jul 2020 11:05:53 +0200 Subject: EuroPython 2020: Our Keynotes Message-ID: We?re happy to announce our keynote lineup for EuroPython 2020. * EuroPython 2020 Keynotes * https://ep2020.europython.eu/events/keynotes/ Guido van Rossum - Q&A ---------------------- In this session, you?ll get a chance to get your questions answered by Guido van Rossum, our retired BDFL. In order to submit a question, please use the following Google form: Guido van Rossum Q&A: Question Submission: https://forms.gle/cAaBgUeVEBgjaDrH7 Siddha Ganju - 30 Golden Rules of Deep Learning Performance ----------------------------------------------------------- ?Watching paint dry is faster than training my deep learning model.? ?If only I had ten more GPUs, I could train my model in time.? ?I want to run my model on a cheap smartphone, but it?s probably too heavy and slow.? If this sounds like you, then you might like this talk. Exploring the landscape of training and inference, we cover a myriad of tricks that step-by-step improve the efficiency of most deep learning pipelines, reduce wasted hardware cycles, and make them cost-effective. We identify and fix inefficiencies across different parts of the pipeline, including data preparation, reading and augmentation, training, and inference. With a data-driven approach and easy-to-replicate TensorFlow examples, finely tune the knobs of your deep learning pipeline to get the best out of your hardware. And with the money you save, demand a raise! Naomi Ceder - Staying for the Community: Building Community in the face of Covid-19 ------------------------------------------ Python communities around the world, large and small are facing loss - from the loss of in person meetups and conferences to the loss of employment and even the potential loss of health and life. As communities we are all confronting uncertainty and unanswered questions. In this talk I would like to reflect on some of those questions. What are communities doing now to preserve a sense of community in the face of this crisis? What might we do and what options will we have for coming events? How can we build and foster community and still keep everyone safe? What challenges might we all face in the future? What sources of support can we find? What are our sources of optimism and hope? Alejandro Saucedo - Meditations on First Deployment: A Practical Guide to Responsible Development ---------------------------------------------------- As the impact of software increasingly reaches farther and wider, our professional responsibility as developers becomes more critical to society. The production systems we design, build and maintain often bring inherent adversities with complex technical, societal and even ethical challenges. The skillsets required to tackle these challenges require us to go beyond the algorithms, and require cross-functional collaboration that often goes beyond a single developer. In this talk we introduce intuitive and practical insights from a few of the core ethics themes in software including Privacy, Equity, Trust and Transparency. We cover their importance, the growing societal challenges, and how organisations such as The Institute for Ethical AI, The Linux Foundation, the Association for Computer Machinery, NumFocus, the IEEE and the Python Software Foundation are contributing to these critical themes through standards, policy advise and open source software initiatives. We finally will wrap up the talk with practical steps that any individual can take to get involved and contribute to some of these great open initiatives, and contribute to these critical ongoing discussions. EuroPython 2020 is waiting for you ---------------------------------- We?ve compiled a full program for the event: - more than 120 sessions, - more than 120 speakers from around the world, - 4 brilliant keynotes, - 2 exciting lightning talk blocks, - 4 all-day tracks, with a whole track dedicated to data science topics, - a poster track, - a virtual social event, - an after party, - and lots of socializing on our conference platform. Conference tickets are available on our registration page. We hope to see lots of you at the conference from July 23-26. Rest assured that we?ll make this a great event again ? even within the limitations of running the conference online. https://ep2020.europython.eu/registration/buy-tickets/ Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/post/622517324925321216/europython-2020-our-keynotes Tweet: https://twitter.com/europython/status/1278608198870749184 Thanks, -- EuroPython 2020 Team https://ep2020.europython.eu/ https://www.europython-society.org/ From __peter__ at web.de Thu Jul 2 05:06:23 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Jul 2020 11:06:23 +0200 Subject: trying to improve my knn algorithm References: <9942d247-89bc-4847-abed-499ed0c85e92o@googlegroups.com> <6024a7a7-4de0-4f6a-9179-3d1f239121bfo@googlegroups.com> Message-ID: kyrohammy at gmail.com wrote: > This is another account but I am the op. Why do you mean normalize? Sorry > I?m new at this. Take three texts containing the words covid, vaccine, program, python Some preparatory imports because I'm using numpy: >>> from numpy import array >>> from numpy.linalg import norm The texts as vectors, the first entry representing "covid" etc.: >>> text1 = array([1, 1, 0, 0]) # a short text about health >>> text2 = array([5, 5, 0, 0]) # a longer text about health >>> text3 = array([0, 0, 1, 1]) # a short text about programming in Python Using your distance algorithm you get >>> norm(text1-text2) 5.6568542494923806 >>> norm(text1-text3) 2.0 The two short texts have greater similarity than the texts about the same topic! You get a better result if you divide by the total number of words, i. e. replace absolute word count with relative word frequency >>> text1/text1.sum() array([ 0.5, 0.5, 0. , 0. ]) >>> norm(text1/text1.sum() - text2/text2.sum()) 0.0 >>> norm(text1/text1.sum() - text3/text3.sum()) 1.0 or normalize the vector length: >>> norm(text1/norm(text1) - text2/norm(text2)) 0.0 >>> norm(text1/norm(text1) - text3/norm(text3)) 1.4142135623730949 From raine.pretorius at pretoriusse.net Thu Jul 2 05:25:27 2020 From: raine.pretorius at pretoriusse.net (Raine Pretorius) Date: Thu, 2 Jul 2020 09:25:27 +0000 Subject: trying to improve my knn algorithm In-Reply-To: References: <9942d247-89bc-4847-abed-499ed0c85e92o@googlegroups.com> <6024a7a7-4de0-4f6a-9179-3d1f239121bfo@googlegroups.com>, Message-ID: Hi, I think you sent this to the wrong person. [cid:storage_emulated_0__EmailTempImage_5_TempSignature_signature_20200630_205218_jpg_1593543161247] [cid:storage_emulated_0__EmailTempImage_5_TempSignature_signature_20200630_205334_jpg_1593543223538] [cid:storage_emulated_0__EmailTempImage_5_TempSignature_signature_20200630_205420_jpg_1593543265258][cid:storage_emulated_0__EmailTempImage_5_TempSignature_signature_20200630_205456_jpg_1593543303538] Kind Regards, Raine Pretorius [cid:storage_emulated_0__EmailTempImage_5_TempSignature_signature_20200630_205658_jpg_1593543438262] -------- Original message -------- From: Peter Otten <__peter__ at web.de> Date: 2020/07/02 11:09 (GMT+02:00) To: python-list at python.org Subject: Re: trying to improve my knn algorithm kyrohammy at gmail.com wrote: > This is another account but I am the op. Why do you mean normalize? Sorry > I?m new at this. Take three texts containing the words covid, vaccine, program, python Some preparatory imports because I'm using numpy: >>> from numpy import array >>> from numpy.linalg import norm The texts as vectors, the first entry representing "covid" etc.: >>> text1 = array([1, 1, 0, 0]) # a short text about health >>> text2 = array([5, 5, 0, 0]) # a longer text about health >>> text3 = array([0, 0, 1, 1]) # a short text about programming in Python Using your distance algorithm you get >>> norm(text1-text2) 5.6568542494923806 >>> norm(text1-text3) 2.0 The two short texts have greater similarity than the texts about the same topic! You get a better result if you divide by the total number of words, i. e. replace absolute word count with relative word frequency >>> text1/text1.sum() array([ 0.5, 0.5, 0. , 0. ]) >>> norm(text1/text1.sum() - text2/text2.sum()) 0.0 >>> norm(text1/text1.sum() - text3/text3.sum()) 1.0 or normalize the vector length: >>> norm(text1/norm(text1) - text2/norm(text2)) 0.0 >>> norm(text1/norm(text1) - text3/norm(text3)) 1.4142135623730949 -- https://mail.python.org/mailman/listinfo/python-list From rhodri at kynesim.co.uk Thu Jul 2 09:39:24 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 2 Jul 2020 14:39:24 +0100 Subject: Formal Question to Steering Council (re recent PEP8 changes) Message-ID: We've had the requested 24 hour cooling off, and I don't imagine anyone is surprised that the situation remains unchanged. The commit message that caused the controversy is still in the PEP repository, and is still controversial. Whether you think it's the best thing since the last best thing or the biggest load of bollocks since the last biggest load of bollocks is irrelevant. It's there, it espouses a political stance, and by implication the Steering Council support it. Since explicit is better than implicit :-), I would like to formally ask the Steering Council to answer the following questions. 1. Does the Steering Council think political statements have any place in the Python repositories? 2. If so, for the avoidance of doubt does the Steering Council support the statements in commit 0c6427d? (https://github.com/python/peps/commit/0c6427dcec1e98ca0bd46a876a7219ee4a9347f4) 3. If not, what do they intend to do about the above commit? If the answer to question 1 is a qualified yes or no, both follow-up questions apply. If the answer to question 1 is a prevarication, non-answer or silence, people will still draw their own conclusions. I mention this merely to reinforce the idea that these things are still answers as well as hostages to fortune. -- Rhodri James *-* Kynesim Ltd From ethan at stoneleaf.us Thu Jul 2 13:06:28 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 2 Jul 2020 10:06:28 -0700 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: References: Message-ID: <60e6c057-9f93-2f76-e5de-815afd824bf3@stoneleaf.us> On 07/02/2020 06:39 AM, Rhodri James wrote: > We've had the requested 24 hour cooling off, and I don't imagine anyone is surprised that the situation remains unchanged.? The commit message that caused the controversy is still in the PEP repository, and is still controversial.? Whether you think it's the best thing since the last best thing or the biggest load of bollocks since the last biggest load of bollocks is irrelevant.? It's there, it espouses a political stance, and by implication the Steering Council support it. > > Since explicit is better than implicit :-), I would like to formally ask the Steering Council to answer the following questions. An issue asking basically the same thing has been created: https://github.com/python/steering-council/issues/31 -- ~Ethan~ From dieter at handshake.de Thu Jul 2 13:11:24 2020 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 2 Jul 2020 19:11:24 +0200 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: References: Message-ID: <24318.5436.60768.176967@ixdm.fritz.box> Rhodri James wrote at 2020-7-2 14:39 +0100: >We've had the requested 24 hour cooling off, and I don't imagine anyone >is surprised that the situation remains unchanged. The commit message >that caused the controversy is still in the PEP repository, and is still >controversial. Whether you think it's the best thing since the last >best thing or the biggest load of bollocks since the last biggest load >of bollocks is irrelevant. It's there, it espouses a political stance, >and by implication the Steering Council support it. > >Since explicit is better than implicit :-), I would like to formally ask >the Steering Council to answer the following questions. I am no member of the Council. Thus, your questions are not directed to me. **BUT** you made your questions public and thus you are likely prepared to receive public comments. The commit message tries to provide the motivation for the change. In my view, it is good to document change motivations and a commit message is not a bad place for that. In the replaced sentence `When writing English, follow Strunk and White` I interpret "Strunk and White" as a reference to some document containing rules for readable English and "Strunk and White" are likely the authors of this document. I do not associate "White" with "white" in contrast to "black" (or some other colour). However, I do not know this document nor "Strunk and White". Thus, the PEP text should get improved. If it is refers to a standard, it should be be an online standard and the PEP should include its URL. Otherwise, non-english people are indeed at a disadvantage. In contrast, The replacement is well understandable and applicable to all languages. Thus, in my view, the change is really an improvement. One could motivate it differently, however. From rhodri at kynesim.co.uk Thu Jul 2 14:04:24 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 2 Jul 2020 19:04:24 +0100 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <24318.5436.60768.176967@ixdm.fritz.box> References: <24318.5436.60768.176967@ixdm.fritz.box> Message-ID: <8b8818b6-3129-213a-aa2b-85b520474d61@kynesim.co.uk> On 02/07/2020 18:11, Dieter Maurer wrote: > I am no member of the Council. Thus, your questions are not directed > to me. **BUT** you made your questions public and thus you are > likely prepared to receive public comments. Fortunately you don't answer any of the questions, so I don't need to have an opinion on that :-) > The commit message tries to provide the motivation for > the change. In my view, it is good to document change motivations > and a commit message is not a bad place for that. True. However, the motivation as appeared in the discussions was (approximately) that many people, especially those whose first language is not English, find being given a list of writing guidelines like Strunk and White's "The Elements of Style" intimidating. That's fair enough, though a bit more consideration suggests that many people have exactly the opposite problem. The wording could be amended to reassure both, and I've been contemplating doing so. The political diatribe about the linguistic contribution to white supremacy of standardized English appeared nowhere in the discussion. Had it done so, I suspect Keala would have realised quite quickly that using it would be (and has been) controversial and divisive, the exact opposite of her stated intentions. All of which is quite beside the point for the questions I raised. As I said, it doesn't matter whether you agree with that political opinion raised, disagree with it, or do not give a monkey's, should _any_ political opinion be in the repo? -- Rhodri James *-* Kynesim Ltd From mats at python.org Thu Jul 2 14:42:31 2020 From: mats at python.org (Mats Wichmann) Date: Thu, 2 Jul 2020 12:42:31 -0600 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <8b8818b6-3129-213a-aa2b-85b520474d61@kynesim.co.uk> References: <24318.5436.60768.176967@ixdm.fritz.box> <8b8818b6-3129-213a-aa2b-85b520474d61@kynesim.co.uk> Message-ID: On 7/2/20 12:04 PM, Rhodri James wrote: > On 02/07/2020 18:11, Dieter Maurer wrote: >> I am no member of the Council. Thus, your questions are not directed >> to me. **BUT** you made your questions public and thus you are >> likely prepared to receive public comments. > > Fortunately you don't answer any of the questions, so I don't need to > have an opinion on that :-) > >> The commit message tries to provide the motivation for >> the change. In my view, it is good to document change motivations >> and a commit message is not a bad place for that. > > True.? However, the motivation as appeared in the discussions was > (approximately) that many people, especially those whose first language > is not English, find being given a list of writing guidelines like > Strunk and White's "The Elements of Style" intimidating.? That's fair > enough, though a bit more consideration suggests that many people have > exactly the opposite problem.? The wording could be amended to reassure > both, and I've been contemplating doing so. Indeed, without weighing in on this case itself, the purpose of calling out a "standard langauge" for formal documents is to remove sources of ambiguity, not to promote one viewpoint or another: not sure how to express something? Let's see if the style manual has anything to guide me. Not to intimidate someone about having set an impossible bar for writing. So if there's a way to express that, I'm sure everybody would be happier! From torriem at gmail.com Thu Jul 2 15:14:30 2020 From: torriem at gmail.com (Michael Torrie) Date: Thu, 2 Jul 2020 13:14:30 -0600 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <24318.5436.60768.176967@ixdm.fritz.box> References: <24318.5436.60768.176967@ixdm.fritz.box> Message-ID: <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> On 7/2/20 11:11 AM, Dieter Maurer wrote: > In the replaced sentence > `When writing English, follow Strunk and White` > I interpret "Strunk and White" as a reference to some > document containing rules for readable English and "Strunk and White" > are likely the authors of this document. I do not associate "White" > with "white" in contrast to "black" (or some other colour). > However, I do not know this document nor "Strunk and White". Thus, > the PEP text should get improved. If it is refers to a standard, > it should be be an online standard and the PEP should include its URL. > Otherwise, non-english people are indeed at a disadvantage. Yes Strunk and White is a well-known book on writing style. That's the names of the authors. William Strunk and EB White. https://en.wikipedia.org/wiki/The_Elements_of_Style > In contrast, The replacement is well understandable and applicable > to all languages. Agreed. She just needs to fix her commit message to remove the sentence about the relics of white supremacy. The fact she would conflate an author's name with some kind of race-related thing is a bit embarrassing, frankly. > Thus, in my view, the change is really an improvement. > One could motivate it differently, however. From daniloco at acm.org Thu Jul 2 16:55:04 2020 From: daniloco at acm.org (Danilo Coccia) Date: Thu, 2 Jul 2020 22:55:04 +0200 Subject: FW: Pycharm Won't Do Long Underscore In-Reply-To: <1bpn9g5irj.fsf@pfeifferfamily.net> References: <1ba5e69e-f916-f96d-a67b-44a3df638228@mrabarnett.plus.com> <1ba70sdu8z.fsf@pfeifferfamily.net> <20200630200000.GB13992@hjp.at> <1bpn9g5irj.fsf@pfeifferfamily.net> Message-ID: Il 30/06/2020 23:46, Joe Pfeiffer ha scritto: > "Peter J. Holzer" writes: > >> On 2020-06-24 15:33:16 -0600, Joe Pfeiffer wrote: >>> One other note -- while you may want various good-looking fonts with >>> ligatures in other domains, for writing code a monospace font with no >>> ligatures lets you see exactly what's there and saves a host of >>> problems. My personal favorite for these purposes is called "Terminus >>> Regular", but which specific one you pick is much less important than >>> that you use one. >> >> I agree. Although there are some fonts with special ligatures for >> programming. I have never used one, but that seems like an interesting >> concept. > > I've never heard of that before. I'd be curious to try one. > I've been using this one, and I like it: https://github.com/tonsky/FiraCode https://www.fontsquirrel.com/fonts/fira-code Works well with PyCharm. From stephen.entropy at gmail.com Thu Jul 2 14:59:52 2020 From: stephen.entropy at gmail.com (Stephen Carboni) Date: Thu, 2 Jul 2020 19:59:52 +0100 Subject: PEP 622 Message-ID: Why are OR patterns going to use the bitwise operator instead of logical or operator? https://www.python.org/dev/peps/pep-0622/#combining-multiple-patterns-or-patterns -Steve From jon+usenet at unequivocal.eu Thu Jul 2 15:26:30 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 2 Jul 2020 19:26:30 -0000 (UTC) Subject: Formal Question to Steering Council (re recent PEP8 changes) References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> Message-ID: On 2020-07-02, Michael Torrie wrote: > Agreed. She just needs to fix her commit message to remove the sentence > about the relics of white supremacy. The fact she would conflate an > author's name with some kind of race-related thing is a bit > embarrassing, frankly. She didn't - you did. From rosuav at gmail.com Thu Jul 2 17:51:42 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jul 2020 07:51:42 +1000 Subject: PEP 622 In-Reply-To: References: Message-ID: On Fri, Jul 3, 2020 at 7:48 AM Stephen Carboni wrote: > > Why are OR patterns going to use the bitwise operator instead of > logical or operator? > > https://www.python.org/dev/peps/pep-0622/#combining-multiple-patterns-or-patterns > Keep reading :) https://www.python.org/dev/peps/pep-0622/#use-some-other-syntax-instead-of-for-or-patterns ChrisA From ethan at stoneleaf.us Thu Jul 2 17:53:30 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 2 Jul 2020 14:53:30 -0700 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> Message-ID: <7c09c90b-70ba-8a78-fe21-9c00ca0faa0b@stoneleaf.us> On 07/02/2020 12:14 PM, Michael Torrie wrote: > The fact she would conflate an > author's name with some kind of race-related thing is a bit > embarrassing, frankly. It seems she has studied literary and English history, at least as related to the 20th century, so I don't think any name conflation is going on. I have asked for links that would support her view as expressed in the commit message, but haven't yet seen any. -- ~Ethan~ From torriem at gmail.com Thu Jul 2 18:29:49 2020 From: torriem at gmail.com (Michael Torrie) Date: Thu, 2 Jul 2020 16:29:49 -0600 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> Message-ID: <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> On 7/2/20 1:26 PM, Jon Ribbens via Python-list wrote: > On 2020-07-02, Michael Torrie wrote: >> Agreed. She just needs to fix her commit message to remove the sentence >> about the relics of white supremacy. The fact she would conflate an >> author's name with some kind of race-related thing is a bit >> embarrassing, frankly. > > She didn't - you did. Come again? I can see no other link in the verbage with the "relics of white supremacy" that she referred to. If there are other links, they should be included in the commit message. I agree with Rhodri that an explanation would be interesting. Far be it from me to demand one. So whatever. From torriem at gmail.com Thu Jul 2 18:30:18 2020 From: torriem at gmail.com (Michael Torrie) Date: Thu, 2 Jul 2020 16:30:18 -0600 Subject: FW: Pycharm Won't Do Long Underscore In-Reply-To: References: <1ba5e69e-f916-f96d-a67b-44a3df638228@mrabarnett.plus.com> <1ba70sdu8z.fsf@pfeifferfamily.net> <20200630200000.GB13992@hjp.at> <1bpn9g5irj.fsf@pfeifferfamily.net> Message-ID: On 7/2/20 2:55 PM, Danilo Coccia wrote: > Il 30/06/2020 23:46, Joe Pfeiffer ha scritto: >> "Peter J. Holzer" writes: >>> I agree. Although there are some fonts with special ligatures for >>> programming. I have never used one, but that seems like an interesting >>> concept. >> >> I've never heard of that before. I'd be curious to try one. >> > > I've been using this one, and I like it: > https://github.com/tonsky/FiraCode > https://www.fontsquirrel.com/fonts/fira-code > > Works well with PyCharm. Hmm. That is... interesting. I'm not at all sure how I feel about that. On the one hand it partly appeals, but on the other hand it quite repulses me. I don't find the FireCode samples any easier to read than a normal font. In fact I find it slightly more difficult to read, since my brain is not used to looking for those symbols. Hmmm. Yeah I dunno about this one! Very interesting. Thanks for sharing it. I tried it, and it's definitely not for me! From random832 at fastmail.com Thu Jul 2 18:46:06 2020 From: random832 at fastmail.com (Random832) Date: Thu, 02 Jul 2020 18:46:06 -0400 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> Message-ID: <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> On Thu, Jul 2, 2020, at 18:29, Michael Torrie wrote: > Come again? I can see no other link in the verbage with the "relics of > white supremacy" that she referred to. If there are other links, they > should be included in the commit message. I agree with Rhodri that an > explanation would be interesting. Far be it from me to demand one. So > whatever. It's possible that this wasn't explained clearly enough in the commit message itself (though I would argue it was definitely adequately explained in the ensuing on-list discussion, and wonder how much of that discussion you've actually read), but the point is that the *whole idea* of "standard English" is tied to white supremacy, not any particular standard whether via its authors or otherwise. From countryone77 at gmail.com Thu Jul 2 18:59:14 2020 From: countryone77 at gmail.com (Bev In TX) Date: Thu, 2 Jul 2020 17:59:14 -0500 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> References: <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> Message-ID: > On Jul 2, 2020, at 5:48 PM, Random832 wrote: > > but the point is that the *whole idea* of "standard English" is tied to white supremacy Bunkum. It is racist to claim that standards are against people, when their purpose to to make the written word understood by all who read it, as opposed to having to understand all dialects. There are numerous ?white? dialects whose words and grammars are not included in those standards. Bev in TX From torriem at gmail.com Thu Jul 2 20:03:18 2020 From: torriem at gmail.com (Michael Torrie) Date: Thu, 2 Jul 2020 18:03:18 -0600 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> Message-ID: <1b1a605e-2e56-b81c-90e5-daea099e56d7@gmail.com> On 7/2/20 4:46 PM, Random832 wrote: > It's possible that this wasn't explained clearly enough in the commit > message itself (though I would argue it was definitely adequately > explained in the ensuing on-list discussion, and wonder how much of > that discussion you've actually read), but the point is that the > *whole idea* of "standard English" is tied to white supremacy, not > any particular standard whether via its authors or otherwise. Good to know. Nothing at all was explained in the commit message justifying that particular sentence, leaving one unfamiliar with the background to wonder what she was referring to. I definitely agree the words "standard English" are pretty meaningless to would-be python developers anyway and the new phrase in the PEP 8 is much better. From arj.python at gmail.com Fri Jul 3 02:58:36 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 3 Jul 2020 10:58:36 +0400 Subject: FlaskCon: Today Friday 3rd July, Tomorrow and Sunday! Message-ID: Greetings List, FlaskCon is this week! Speakers include many interesting people such as: - Dustin Ingram - Adrian M?nnich (ThiefMaster) and a host of beautiful topics and diverse mix such as: - How Google cloud uses Flask - Demystifying Flask's Application and Request Contexts with pytest - How the FEC uses Flask to increase transparency in US elections - Running Flask on Kubernetes 3 , 4 and 5th July! Today's schedule includes interviews at 15:00 GMT with the authors of - DTale - Creatorlist This is the perfect session for beginners to attend so that FlaskCon is worth attending even for non-Flask people As panelists you have organisers and reviewers like - David Lord - Miguel Grinberg - Grey Li and others How to attend? See here: https://flaskcon.com/#faq Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy | blog github Mauritius From robin at reportlab.com Fri Jul 3 05:23:18 2020 From: robin at reportlab.com (Robin Becker) Date: Fri, 3 Jul 2020 10:23:18 +0100 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: References: Message-ID: <99d63dac-1a43-690d-7259-4d70be72738f@everest.reportlab.co.uk> ........ > Since explicit is better than implicit :-), I would like to formally ask the Steering Council to answer the following > questions. > > 1. Does the Steering Council think political statements have any place in the Python repositories? > > 2. If so, for the avoidance of doubt does the Steering Council support the statements in commit 0c6427d? > (https://github.com/python/peps/commit/0c6427dcec1e98ca0bd46a876a7219ee4a9347f4) > > 3. If not, what do they intend to do about the above commit? > > If the answer to question 1 is a qualified yes or no, both follow-up questions apply. > > If the answer to question 1 is a prevarication, non-answer or silence, people will still draw their own conclusions.? I > mention this merely to reinforce the idea that these things are still answers as well as hostages to fortune. > the above gets +10 from me according to the telegraph > John Cleese has accused the BBC of ?social engineering? after its head of comedy said Monty Python?s white Oxbridge males were out of step with modern television. so is there a pep for alternate language names ;) -- Robin Becker From rhodri at kynesim.co.uk Fri Jul 3 08:48:41 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 3 Jul 2020 13:48:41 +0100 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> Message-ID: <81b71511-d2a9-8c75-3a5a-22cd866d7b73@kynesim.co.uk> On 02/07/2020 23:46, Random832 wrote: > On Thu, Jul 2, 2020, at 18:29, Michael Torrie wrote: >> Come again? I can see no other link in the verbage with the >> "relics of white supremacy" that she referred to. If there are >> other links, they should be included in the commit message. I >> agree with Rhodri that an explanation would be interesting. Far be >> it from me to demand one. So whatever. > > It's possible that this wasn't explained clearly enough in the commit > message itself (though I would argue it was definitely adequately > explained in the ensuing on-list discussion, and wonder how much of > that discussion you've actually read), but the point is that the > *whole idea* of "standard English" is tied to white supremacy, not > any particular standard whether via its authors or otherwise. As I said in my preamble, it doesn't matter whether you believe that is true or think it's utter bollocks. I asked the question to get the Steering Council's opinion, not anyone else's. If you collectively really must rehash the arguments again, please have the decency to do so in a different thread. -- Rhodri James *-* Kynesim Ltd From jon+usenet at unequivocal.eu Fri Jul 3 10:28:17 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 3 Jul 2020 14:28:17 -0000 (UTC) Subject: Formal Question to Steering Council (re recent PEP8 changes) References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> <81b71511-d2a9-8c75-3a5a-22cd866d7b73@kynesim.co.uk> Message-ID: On 2020-07-03, Rhodri James wrote: > On 02/07/2020 23:46, Random832 wrote: >> On Thu, Jul 2, 2020, at 18:29, Michael Torrie wrote: >>> Come again? I can see no other link in the verbage with the >>> "relics of white supremacy" that she referred to. If there are >>> other links, they should be included in the commit message. I >>> agree with Rhodri that an explanation would be interesting. Far be >>> it from me to demand one. So whatever. >> >> It's possible that this wasn't explained clearly enough in the commit >> message itself (though I would argue it was definitely adequately >> explained in the ensuing on-list discussion, and wonder how much of >> that discussion you've actually read), but the point is that the >> *whole idea* of "standard English" is tied to white supremacy, not >> any particular standard whether via its authors or otherwise. > > As I said in my preamble, it doesn't matter whether you believe that is > true or think it's utter bollocks. I asked the question to get the > Steering Council's opinion, not anyone else's. You don't get to decide whose opinions are offered. From o1bigtenor at gmail.com Fri Jul 3 11:21:11 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Fri, 3 Jul 2020 10:21:11 -0500 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <1b1a605e-2e56-b81c-90e5-daea099e56d7@gmail.com> References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> <1b1a605e-2e56-b81c-90e5-daea099e56d7@gmail.com> Message-ID: On Thu, Jul 2, 2020 at 7:05 PM Michael Torrie wrote: > > On 7/2/20 4:46 PM, Random832 wrote: > > It's possible that this wasn't explained clearly enough in the commit > > message itself (though I would argue it was definitely adequately > > explained in the ensuing on-list discussion, and wonder how much of > > that discussion you've actually read), but the point is that the > > *whole idea* of "standard English" is tied to white supremacy, not > > any particular standard whether via its authors or otherwise. > > Good to know. Nothing at all was explained in the commit message > justifying that particular sentence, leaving one unfamiliar with the > background to wonder what she was referring to. > > I definitely agree the words "standard English" are pretty meaningless > to would-be python developers anyway and the new phrase in the PEP 8 is > much better. > -- Given that I have had plenteen (sic) years of education all in the English language including some instructors trained in the UK and also some periods of technical education in at least one language other than English and am quite familiar with the said "Stunk and White - - *The Elements* * of Style*" perhaps I could offer some background. Especially in an upper class year academic education Strunk and White is quite usually inflicted upon at least all Arts and Humanities kind of students. They advocate for short pithy sentences, including IIRC a statement something to the effect of a sentence with more than 5 words is too long. There are many other amorphisms most of which point out that such a writing style is perhaps the easiest to understand. As far as that goes their position is somewhat correct but I have come to very much differ with their quite heavy handed technique. When one is writing about very complex topics it is useful to be able to craft complex sentences but then said authors seemed to think that everything was reducible to a quite elementary level - - - I have not found that to be true. A little closer to the intent of the question. In good documentation reasonable sentences make it much easier to understand a previously unknown topic or idea. So in that way asking for writers to at least be aware of if not slavishly follow some so called 'standard of style'. Strunk and White and Kate Turabian have both published works that are quite accepted in the Arts and the Humanities as I did not do any graduate training in the Sciences I do not know what the recommended manuals are in such but in reading plenty of papers most of the authors would be quite assisted in writing to be understood rather than to impress. So I can understand a desire to suggest the usage of a 'Manual of Style' but I would not be comfortable if it were a requirement. Languages other than English have different strengths and their users, when faced with writing documentation in a language that, even though they are quite comfortable with English, they are not used to producing what may be possible by a writer who is fully cognisant with the most rigorous aspects of style, may enhance said documentation even if said documentation is not 'perfectly correct in style'. (The previous sentence is an example of what is possible using complex sentence structure - - - grin!) I decry the present hypersensitivity to any hint of culture that was present some 200 years ago especially when such sensitivity is used to block a wider group from participating. IMO such hypersensitive individuals might be better served by finding some other soap box to scream from if that is to be their primary input into a particular conversation. HTH Regards From dokuwa2000 at yahoo.co.uk Fri Jul 3 06:09:47 2020 From: dokuwa2000 at yahoo.co.uk (Daley Okuwa) Date: Fri, 3 Jul 2020 10:09:47 +0000 (UTC) Subject: New to python - Just a question References: <1292320940.3464592.1593770987225.ref@mail.yahoo.com> Message-ID: <1292320940.3464592.1593770987225@mail.yahoo.com> Please can someone help Write an algorithm (choose the language you prefer) that given a character string,?for instance {?c?,?a?,?i?,?o?,?p?,?a?}, will print out the list of characters appearing at least 2 times.?In this specific example, it would return {?a?}. Afterwards, comment out the cost in terms of space and time. Write a bash/python script that takes a directory as an argument and output the total lines of code in *.cpp files recursively. Thanks?Daley From rhodri at kynesim.co.uk Fri Jul 3 12:20:48 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 3 Jul 2020 17:20:48 +0100 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> <81b71511-d2a9-8c75-3a5a-22cd866d7b73@kynesim.co.uk> Message-ID: <1cb63371-d321-441d-debf-bb38be5512c1@kynesim.co.uk> On 03/07/2020 15:28, Jon Ribbens via Python-list wrote: > On 2020-07-03, Rhodri James wrote: >> On 02/07/2020 23:46, Random832 wrote: >>> On Thu, Jul 2, 2020, at 18:29, Michael Torrie wrote: >>>> Come again? I can see no other link in the verbage with the >>>> "relics of white supremacy" that she referred to. If there are >>>> other links, they should be included in the commit message. I >>>> agree with Rhodri that an explanation would be interesting. Far be >>>> it from me to demand one. So whatever. >>> >>> It's possible that this wasn't explained clearly enough in the commit >>> message itself (though I would argue it was definitely adequately >>> explained in the ensuing on-list discussion, and wonder how much of >>> that discussion you've actually read), but the point is that the >>> *whole idea* of "standard English" is tied to white supremacy, not >>> any particular standard whether via its authors or otherwise. >> >> As I said in my preamble, it doesn't matter whether you believe that is >> true or think it's utter bollocks. I asked the question to get the >> Steering Council's opinion, not anyone else's. > > You don't get to decide whose opinions are offered. But I do get to decide whose opinions are solicited. -- Rhodri James *-* Kynesim Ltd From jon+usenet at unequivocal.eu Thu Jul 2 22:42:57 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 3 Jul 2020 02:42:57 -0000 (UTC) Subject: Formal Question to Steering Council (re recent PEP8 changes) References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> Message-ID: On 2020-07-02, Michael Torrie wrote: > On 7/2/20 1:26 PM, Jon Ribbens via Python-list wrote: >> On 2020-07-02, Michael Torrie wrote: >>> Agreed. She just needs to fix her commit message to remove the sentence >>> about the relics of white supremacy. The fact she would conflate an >>> author's name with some kind of race-related thing is a bit >>> embarrassing, frankly. >> >> She didn't - you did. > > Come again? She didn't - you did. From countryone77 at gmail.com Fri Jul 3 11:50:43 2020 From: countryone77 at gmail.com (Bev In TX) Date: Fri, 3 Jul 2020 10:50:43 -0500 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: References: Message-ID: <8DCE9E91-8665-41B4-A0F2-94505C137C3E@gmail.com> > On Jul 3, 2020, at 10:23 AM, o1bigtenor wrote: > > I decry the present hypersensitivity to any hint of culture that was > present some 200 years ago especially when such sensitivity is used > to block a wider group from participating. IMO such hypersensitive > individuals might be better served by finding some other soap box > to scream from if that is to be their primary input into a particular > conversation. I have worked In harmony with multinational teams from all over the world. We never needed a writing standard for code changes. Are current Python code changes documented in such a poor way that they are not understandable? That would be the only reason to promote a standard, which would not have to be as stringent as Strunk and White. I don?t like the use of the word ?racism? in connection with writing standards, which is blatantly not true. Do the current leaders of Python promote political agendas? That?s what this sounds like. From david at lowryduda.com Fri Jul 3 12:37:16 2020 From: david at lowryduda.com (David Lowry-Duda) Date: Fri, 3 Jul 2020 12:37:16 -0400 Subject: New to python - Just a question In-Reply-To: <1292320940.3464592.1593770987225@mail.yahoo.com> References: <1292320940.3464592.1593770987225.ref@mail.yahoo.com> <1292320940.3464592.1593770987225@mail.yahoo.com> Message-ID: <20200703163716.GA2564@icerm-dld> Hello! > Please can someone help > > Write an algorithm (choose the language you prefer) that given a > character string,?for instance {?c?,?a?,?i?,?o?,?p?,?a?}, will print > out the list of characters appearing at least 2 times.?In this > specific example, it would return {?a?}. Afterwards, comment out the > cost in terms of space and time. > > Write a bash/python script that takes a directory as an argument and > output the total lines of code in *.cpp files recursively. These are both pretty classical problems. But the way you've presented them sounds a bit like a "do my homework for me" style question. Do you know any python? I recommend that you consider following a book or tutorial to get through some of the basics. I like to recommend Think Python (available for free from the author). If you have particular questions that come up while you're trying to write a solution, I think more people would be more inclined to help. Good luck! - DLD -- David Lowry-Duda From ethan at stoneleaf.us Fri Jul 3 12:40:33 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 3 Jul 2020 09:40:33 -0700 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> Message-ID: <781f4ce7-455d-26ea-0c8a-8f088ea86290@stoneleaf.us> On 07/02/2020 07:42 PM, Jon Ribbens via Python-list wrote: > She didn't - you did. Please keep the discourse civil. Petty taunts are not helpful. -- ~Ethan~ Python List Moderator From jon+usenet at unequivocal.eu Fri Jul 3 12:57:30 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 3 Jul 2020 16:57:30 -0000 (UTC) Subject: Formal Question to Steering Council (re recent PEP8 changes) References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <781f4ce7-455d-26ea-0c8a-8f088ea86290@stoneleaf.us> Message-ID: On 2020-07-03, Ethan Furman wrote: > On 07/02/2020 07:42 PM, Jon Ribbens via Python-list wrote: >> She didn't - you did. > > Please keep the discourse civil. Petty taunts are not helpful. Sorry, I don't understand what you are getting at. My comment was not a "petty taunt", it was an important factual correction, and perfectly civil - more so than the post it was a response to. (I'll concede my second post repeating it in response to "Come again?" was somewhat facetious though ;-) ) From rhodri at kynesim.co.uk Fri Jul 3 13:15:59 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 3 Jul 2020 18:15:59 +0100 Subject: New to python - Just a question In-Reply-To: <1292320940.3464592.1593770987225@mail.yahoo.com> References: <1292320940.3464592.1593770987225.ref@mail.yahoo.com> <1292320940.3464592.1593770987225@mail.yahoo.com> Message-ID: <2832dabb-7ef2-a117-c786-655a0e989a5a@kynesim.co.uk> On 03/07/2020 11:09, Daley Okuwa via Python-list wrote: > > Please can someone help > > Write an algorithm (choose the language you prefer) that given a character string,?for instance {?c?,?a?,?i?,?o?,?p?,?a?}, will print out the list of characters appearing at least 2 times.?In this specific example, it would return {?a?}. Afterwards, comment out the cost in terms of space and time. The first thing to do with any problem is to break it down into bits. In the case of Python, writing them out as "pseudo-code" instructions often helps. In this case you have: Set up something to count letters with For each letter in the string: If we haven't seen this letter before: Set the counter for the letter to 1 Else: Add 1 to the counter for the letter For each counter: If the count is 2 or more: Print the letter Now there are a lot of possible ways to write that, but they mostly come down to deciding what data structure to use to count letters with. Have a browse through a tutorial (or the standard library if you are feeling adventurous) and see what you think might work, then try it. > Write a bash/python script that takes a directory as an argument and output the total lines of code in *.cpp files recursively. In bash, what existing commands count things? If you don't know, how might you find out? Then you have to figure out how to do that for each *.cpp file in a directory, and add the totals together. In Python, you can read a file one line at a time, so how to count the number of lines in a file should be pretty obvious. Figuring out how to do that for every *.cpp file in a directory will involve looking through the standard library, or getting a bash script to do it for you :-) -- Rhodri James *-* Kynesim Ltd From torriem at gmail.com Fri Jul 3 13:43:28 2020 From: torriem at gmail.com (Michael Torrie) Date: Fri, 3 Jul 2020 11:43:28 -0600 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <781f4ce7-455d-26ea-0c8a-8f088ea86290@stoneleaf.us> Message-ID: <8cdbef85-966a-5cbb-4de4-ad34a0c4f01d@gmail.com> On 7/3/20 10:57 AM, Jon Ribbens via Python-list wrote: > On 2020-07-03, Ethan Furman wrote: >> On 07/02/2020 07:42 PM, Jon Ribbens via Python-list wrote: >>> She didn't - you did. >> >> Please keep the discourse civil. Petty taunts are not helpful. > > Sorry, I don't understand what you are getting at. My comment was not > a "petty taunt", it was an important factual correction, and perfectly > civil - more so than the post it was a response to. > > (I'll concede my second post repeating it in response to "Come again?" > was somewhat facetious though ;-) ) All you needed to say was, "No, she did not conflate 'White' with race." To say "[I] did," is a very odd thing, and certainly inaccurate. I definitely did not conflate White with race. Why do you think that? As others helpfully pointed out, the context for her comments was out of band (not on this list). Thus she was not conflating anything. If we want to go in circles, sure I did conflate that she conflated. thanks. From dieter at handshake.de Fri Jul 3 13:58:55 2020 From: dieter at handshake.de (Dieter Maurer) Date: Fri, 3 Jul 2020 19:58:55 +0200 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> Message-ID: <24319.29151.346390.737359@ixdm.fritz.box> Random832 wrote at 2020-7-2 18:46 -0400: > ... the *whole idea* of "standard English" is tied to white supremacy, not any particular standard whether via its authors or otherwise. PEP 8 was initially designed as a style specification for Python's runtime library. I hope we can agree that all documentation in Python's runtime library should use (some) standard English - understandable by any typical English speaker - and not some English dialect spoken and understood only in some parts of the world. PEP 8 has been adopted meanwhile by many external projects. Those projects might choose a different language and maybe even an English dialect. However, if the project want to be international, "standard English" (in contrast to an English dialect) has its advantages. From tjreedy at udel.edu Fri Jul 3 13:52:02 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 3 Jul 2020 13:52:02 -0400 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> Message-ID: On 7/2/2020 6:46 PM, Random832 wrote: how much of that discussion you've actually read), but the point is that the *whole idea* of "standard English" is tied to white supremacy, not any particular standard whether via its authors or otherwise. France has the French Academy to protect the purity of the French languages and reject foreign words. Spain similarly has a Royal Academy to regulate what is Castilian (Spanish Spanish). In ancient Bharata (India), about 2000 years ago, a 'cabal' of grammatcians, exemplified by Panini, defined Sanskrit. English is much more fluid and much more open to including foreign words and influences, including from 'non-white' peoples. -- Terry Jan Reedy From jon+usenet at unequivocal.eu Fri Jul 3 14:57:58 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 3 Jul 2020 18:57:58 -0000 (UTC) Subject: Formal Question to Steering Council (re recent PEP8 changes) References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <781f4ce7-455d-26ea-0c8a-8f088ea86290@stoneleaf.us> <8cdbef85-966a-5cbb-4de4-ad34a0c4f01d@gmail.com> Message-ID: On 2020-07-03, Michael Torrie wrote: > On 7/3/20 10:57 AM, Jon Ribbens via Python-list wrote: >> On 2020-07-03, Ethan Furman wrote: >>> On 07/02/2020 07:42 PM, Jon Ribbens via Python-list wrote: >>>> She didn't - you did. >>> >>> Please keep the discourse civil. Petty taunts are not helpful. >> >> Sorry, I don't understand what you are getting at. My comment was not >> a "petty taunt", it was an important factual correction, and perfectly >> civil - more so than the post it was a response to. >> >> (I'll concede my second post repeating it in response to "Come again?" >> was somewhat facetious though ;-) ) > > All you needed to say was, "No, she did not conflate 'White' with race." > To say "[I] did," is a very odd thing, and certainly inaccurate. I > definitely did not conflate White with race. Why do you think that? Because you conflated the name of the author and race in the post I was responding to. From ethan at stoneleaf.us Fri Jul 3 15:16:15 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 3 Jul 2020 12:16:15 -0700 Subject: Making and seeing mistakes [was: Formal Question to Steering Council] In-Reply-To: References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <781f4ce7-455d-26ea-0c8a-8f088ea86290@stoneleaf.us> <8cdbef85-966a-5cbb-4de4-ad34a0c4f01d@gmail.com> Message-ID: <2f493388-9859-87c9-a1f3-f71ecbb8ba20@stoneleaf.us> On 07/03/2020 11:57 AM, Jon Ribbens via Python-list wrote: > On 2020-07-03, Michael Torrie wrote: >> All you needed to say was, "No, she did not conflate 'White' with race." >> To say "[I] did," is a very odd thing, and certainly inaccurate. I >> definitely did not conflate White with race. Why do you think that? > > Because you conflated the name of the author and race in the post > I was responding to. That is ridiculous. It is possible to see someone else's mistake without making it oneself. Michael's mistake was assuming that the author had, in fact, conflated the names. Your mistake is to assume that since the author did not make that mistake that Michael must have made it. I'm sure somebody will point out what my mistake was. Can we now drop this subthread? -- ~Ethan~ From python.list at tim.thechases.com Fri Jul 3 17:59:40 2020 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 3 Jul 2020 16:59:40 -0500 Subject: New to python - Just a question In-Reply-To: <1292320940.3464592.1593770987225@mail.yahoo.com> References: <1292320940.3464592.1593770987225.ref@mail.yahoo.com> <1292320940.3464592.1593770987225@mail.yahoo.com> Message-ID: <20200703165940.3cfbb8fc@bigbox.attlocal.net> On 2020-07-03 10:09, Daley Okuwa via Python-list wrote: > Write an algorithm (choose the language you prefer) that given a > character string,?for instance {?c?,?a?,?i?,?o?,?p?,?a?}, will > print out the list of characters appearing at least 2 times.?In > this specific example, it would return {?a?}. Afterwards, comment > out the cost in terms of space and time. What have you tried already? Where are you having trouble? Have you written a program that accepts a character string? Is the string coming in as a command-line argument or on standard-input? The example string you give looks more like some sort of serialization format rather than a string. Are you having difficulty counting the letters? Python provides a "dict()" type that would work well. Should uppercase letters be counted the same as lowercase letters? I.e., should "Pop" report that there are 2 "p"s? If you've counted the duplicates, Have you studied space/time complexity and do you know how to evaluate code for these characteristics? The problem should be solvable in roughly O(k) per word. > Write a bash/python script that takes a directory as an argument > and output the total lines of code in *.cpp files recursively. Again, what have you tried? Have you been able to iterated over a directory? See find(1) or ls(1) or grep(1) in a shell-script or os.listdir()/os.scandir()/glob.glob() in Python Have you been able to open those files? Can you iterate over the lines in each file? Do you need to filter out any lines (such as blank lines or comments)? If you provide what you've tried, folks here on the list are pretty happy to help. But most won't do your homework for you. -tkc From lukasz at langa.pl Fri Jul 3 19:48:11 2020 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Sat, 4 Jul 2020 01:48:11 +0200 Subject: [RELEASE] Python 3.9.0b4 is now ready for testing Message-ID: <6E22078F-61D5-4377-BEDC-7008555FF54E@langa.pl> On behalf of the entire Python development community, and the currently serving Python release team in particular, I?m pleased to announce the release of Python 3.9.0b4. Get it here: https://www.python.org/downloads/release/python-390b4/ This is a beta preview of Python 3.9 Python 3.9 is still in development. This release, 3.9.0b4, is the fourth of five planned beta release previews. Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their projects to support the new feature release. Call to action We strongly encourage maintainers of third-party Python projects to test with 3.9 during the beta phase and report issues found to the Python bug tracker as soon as possible. While the release is planned to be feature complete entering the beta phase, it is possible that features may be modified or, in rare cases, deleted up until the start of the release candidate phase (2020-08-10). Our goal is have no ABI changes after beta 5 and as few code changes as possible after 3.9.0rc1, the first release candidate. To achieve that, it will be extremely important to get as much exposure for 3.9 as possible during the beta phase. Please keep in mind that this is a preview release and its use is not recommended for production environments. Major new features of the 3.9 series, compared to 3.8 Some of the new major new features and changes in Python 3.9 are: PEP 584 , Union Operators in dict PEP 585 , Type Hinting Generics In Standard Collections PEP 593 , Flexible function and variable annotations PEP 602 , Python adopts a stable annual release cadence PEP 615 , Support for the IANA Time Zone Database in the Standard Library PEP 616 , String methods to remove prefixes and suffixes PEP 617 , New PEG parser for CPython BPO 38379 , garbage collection does not block on resurrected objects; BPO 38692 , os.pidfd_open added that allows process management without races and signals; BPO 39926 , Unicode support updated to version 13.0.0; BPO 1635741 , when Python is initialized multiple times in the same process, it does not leak memory anymore; A number of Python builtins (range, tuple, set, frozenset, list, dict) are now sped up using PEP 590 vectorcall; A number of Python modules (_abc, audioop, _bz2, _codecs, _contextvars, _crypt, _functools, _json, _locale, operator, resource, time, _weakref) now use multiphase initialization as defined by PEP 489 ; A number of standard library modules (audioop, ast, grp, _hashlib, pwd, _posixsubprocess, random, select, struct, termios, zlib) are now using the stable ABI defined by PEP 384 . (Hey, fellow core developer, if a feature you find important is missing from this list, let ?ukasz know .) The next pre-release, the fifth beta release of Python 3.9, will be 3.9.0b5. It is currently scheduled for 2020-07-20. More resources Online Documentation PEP 596 , 3.9 Release Schedule Report bugs at https://bugs.python.org . Help fund Python and its community . Your friendly release team, Ned Deily @nad Steve Dower @steve.dower ?ukasz Langa @ambv From soyeomul at doraji.xyz Fri Jul 3 23:14:38 2020 From: soyeomul at doraji.xyz (=?utf-8?B?7Zmp67OR7Z2s?=) Date: Sat, 04 Jul 2020 12:14:38 +0900 Subject: a bit feedback for JSON documents Message-ID: There is some comment for https://docs.python.org/3.10/library/json.html. The latest RFC number is 8259. Thanks, Sincerely, JSON fan Byung-Hee -- ^????? _????_ ?????_^))// From random832 at fastmail.com Sat Jul 4 11:38:37 2020 From: random832 at fastmail.com (Random832) Date: Sat, 04 Jul 2020 11:38:37 -0400 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <81b71511-d2a9-8c75-3a5a-22cd866d7b73@kynesim.co.uk> References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> <81b71511-d2a9-8c75-3a5a-22cd866d7b73@kynesim.co.uk> Message-ID: <7c3ba329-c8bd-43ae-8e94-9faed3f12206@www.fastmail.com> On Fri, Jul 3, 2020, at 08:48, Rhodri James wrote: > As I said in my preamble, it doesn't matter whether you believe that is > true or think it's utter bollocks. I asked the question to get the > Steering Council's opinion, not anyone else's. If you collectively > really must rehash the arguments again, please have the decency to do so > in a different thread. The idea that the statement was in any way related to one of the authors being named "White" was an *obvious factual mistake* in your post. Regardless of anything else, that is *not a matter of opinion*, so saying whose opinion you wanted is irrelevant. From o1bigtenor at gmail.com Sat Jul 4 12:33:57 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Sat, 4 Jul 2020 11:33:57 -0500 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <7c3ba329-c8bd-43ae-8e94-9faed3f12206@www.fastmail.com> References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> <81b71511-d2a9-8c75-3a5a-22cd866d7b73@kynesim.co.uk> <7c3ba329-c8bd-43ae-8e94-9faed3f12206@www.fastmail.com> Message-ID: On Sat, Jul 4, 2020 at 10:41 AM Random832 wrote: > On Fri, Jul 3, 2020, at 08:48, Rhodri James wrote: > > As I said in my preamble, it doesn't matter whether you believe that is > > true or think it's utter bollocks. I asked the question to get the > > Steering Council's opinion, not anyone else's. If you collectively > > really must rehash the arguments again, please have the decency to do so > > in a different thread. > > The idea that the statement was in any way related to one of the authors > being named "White" was an *obvious factual mistake* in your post. > Regardless of anything else, that is *not a matter of opinion*, so saying > whose opinion you wanted is irrelevant. > Copied from the commit: Instead of requiring that comments be written in Strunk & White Standard English, require instead that English-language comments be clear and easily understandable by other English speakers. This accomplishes the same goal without upholding relics of white supremacy. Many native English speakers do not use Standard English as their native dialect, so requiring conformation to Standard English centers whiteness in an inappropriate and unnecessary way, and can alienate and put up barriers for people of color and those whose native dialect of English is not Standard English. This change is a simple way to correct that while maintaining the original intent of the requirement. I would point out that even suggesting that the issue be a *obvious factual mistake* only serves to prove that you didn't read the thing and I, at least, wonder why you're offering an opinion on any part of the discussion. IMO the language in the commit is inflammatory and should either be revised or it and the commit removed for its clear intellectual disfunction. Regards Regards From narenchunduri at gmail.com Sat Jul 4 13:20:46 2020 From: narenchunduri at gmail.com (narenchunduri at gmail.com) Date: Sat, 4 Jul 2020 10:20:46 -0700 (PDT) Subject: Assign Excel cell value from Datepicker widget Selection using Python In-Reply-To: References: <972e5d78-b594-43a1-88ef-43bf61e580a0o@googlegroups.com> <4b0b54b3-7d73-3619-fbc9-51e605025eb4@DancesWithMice.info> Message-ID: <2aa39304-ee8c-492d-835d-b7cb69679a07o@googlegroups.com> I am trying to assign a widget to an excel cell. Convertion wont help me.Thanks From random832 at fastmail.com Sat Jul 4 13:32:35 2020 From: random832 at fastmail.com (Random832) Date: Sat, 04 Jul 2020 13:32:35 -0400 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> <81b71511-d2a9-8c75-3a5a-22cd866d7b73@kynesim.co.uk> <7c3ba329-c8bd-43ae-8e94-9faed3f12206@www.fastmail.com> Message-ID: <5ffd08df-f045-44fe-aca6-90a2bd644dae@www.fastmail.com> On Sat, Jul 4, 2020, at 12:33, o1bigtenor wrote: > I would point out that even suggesting that the issue be a *obvious > factual mistake* only serves to prove that you didn't read the thing > and I, at least, wonder why you're offering an opinion on any part of > the discussion. I said obvious because even if it was not obvious from the commit message itself, it had *already been explained* in the thread on the other mailing list by the time Michael Torrie posted (July 02 15:14) his assertion of "The fact she would conflate an author's name with some kind of race-related thing". I even recall raising the question of whether he had in fact read any of that discussion. After all, Ethan Furman made the same mistake in his original post, and was corrected *very* early on in the discussion, so repeating it several days later makes little sense. *Regardless whether you agree or not* with the premise that "standard english" is a subtle means of enforcing white supremacy, the fact that some people do believe that is a far more plausible explanation for the statement in the commit message than the fact that one of the authors happens to have been named "White", and the idea that it was because of the latter only exists in the imagination of those determined to assume the worst of the person who wrote the commit message. On Tue, Jun 30, 2020, at 08:44, Ethan Furman wrote: > On 06/30/2020 05:03 AM, ?ukasz Langa wrote: > > > >> On 30 Jun 2020, at 12:44, Ethan Furman > wrote: > >> > >> Of course I don't know if Keara or Guido knew any of this, but it certainly feels to me that the commit message is ostracizing an entire family line because they had the misfortune to have the wrong last name. In fact, it seems like Strunk & White is making changes to be inclusive in its advice -- exactly what I would have thought we wanted on our side ("our side" being the diverse and welcoming side). > > > > In any case, saying that Keara and Guido mistook the family name of one of the authors for skin color feels derogatory. > > My apologies, that was not my intent. As I said, I never knew what it > was until today (er, yesterday now). From ethan at stoneleaf.us Sat Jul 4 18:17:01 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 4 Jul 2020 15:17:01 -0700 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <5ffd08df-f045-44fe-aca6-90a2bd644dae@www.fastmail.com> References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> <81b71511-d2a9-8c75-3a5a-22cd866d7b73@kynesim.co.uk> <7c3ba329-c8bd-43ae-8e94-9faed3f12206@www.fastmail.com> <5ffd08df-f045-44fe-aca6-90a2bd644dae@www.fastmail.com> Message-ID: On 07/04/2020 10:32 AM, Random832 wrote: > I said obvious because even if it was not obvious from the commit message itself, it had *already been explained* in the thread on the other mailing list That would require Michael to have been reading the other mailing list to know that. Just because the information is out there, doesn't mean everybody has seen it. -- ~Ethan~ From PythonList at DancesWithMice.info Sat Jul 4 18:30:02 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 5 Jul 2020 10:30:02 +1200 Subject: Assign Excel cell value from Datepicker widget Selection using Python In-Reply-To: <2aa39304-ee8c-492d-835d-b7cb69679a07o@googlegroups.com> References: <972e5d78-b594-43a1-88ef-43bf61e580a0o@googlegroups.com> <4b0b54b3-7d73-3619-fbc9-51e605025eb4@DancesWithMice.info> <2aa39304-ee8c-492d-835d-b7cb69679a07o@googlegroups.com> Message-ID: <15cb9a9c-7fa9-981f-fdaa-8227885c51f8@DancesWithMice.info> On 5/07/20 5:20 AM, narenchunduri at gmail.com wrote: > I am trying to assign a widget to an excel cell. Convertion wont help me.Thanks That's true - and false! Unfortunately, these posts have revealed little about you and your level of understanding of Python specifically, and computer programming more generally. This lack of information creates an impression that you are not used to working within a professional team. The example could easily be a professional task, or a student assignment. In the latter case, we will be happy to help you learn, but are not keen to 'do your homework'. (also, please be advised that there is a separate Python-Tutor Discussion List) To solve this problem requires an understanding of Python and how it works, plus ipy/Jupiter and their widgets, and Excel as seen through the openpyxl library. It is not a trivial task! To the problem:- First, we must understand how ipy.widgets work (https://minrk-ipywidgets.readthedocs.io/en/latest/examples/Widget%20Basics.html). A widget is not like Python's basic input() which displays a "prompt" and collects a (str) value for return across an assignment statement, eg amount = input( "How much? " ) A widget is an instantiated class, and as such we must consider its "attributes" and "methods" - which has the pre-requisite of understanding how Python works with "objects". The web.ref describes the value property. So, if the DatePicker()'s result is assigned to an intermediate variable, that could be printed-out, together with its type(). This will provide valuable information. Then, assign the value property of that variable (which is actually an object; that class instantiated) to another intermediate variable - let's call that returned_date, and print its value and type. Finally, we should be able to reconcile the above data-items with the workbook's format/type demands, so that the date can be assigned to the B2 cell... Let us know how you get on (copy-paste any relevant code and errors into your email message, if relevant)... -- Regards =dn From random832 at fastmail.com Sat Jul 4 21:29:15 2020 From: random832 at fastmail.com (Random832) Date: Sat, 04 Jul 2020 21:29:15 -0400 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> <81b71511-d2a9-8c75-3a5a-22cd866d7b73@kynesim.co.uk> <7c3ba329-c8bd-43ae-8e94-9faed3f12206@www.fastmail.com> <5ffd08df-f045-44fe-aca6-90a2bd644dae@www.fastmail.com> Message-ID: On Sat, Jul 4, 2020, at 18:17, Ethan Furman wrote: > On 07/04/2020 10:32 AM, Random832 wrote: > > > I said obvious because even if it was not obvious from the commit message itself, it had *already been explained* in the thread on the other mailing list > > That would require Michael to have been reading the other mailing list > to know that. Just because the information is out there, doesn't mean > everybody has seen it. ok, you know what? regardless of hairsplitting about how obvious or not it is what she meant, and whether or not "it's because of the name White" was a reasonable conclusion to jump to, none of that changes that the conclusion was, in fact, incorrect. So trying to fight with me for pointing that out and claiming I was offering my "opinion" was unreasonable. I was not offering an opinion, I was pointing out a factual error, and arguing that the error was reasonable to make rather than being obvious doesn't change that. From rhodri at kynesim.co.uk Sun Jul 5 06:50:21 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Sun, 5 Jul 2020 11:50:21 +0100 Subject: Formal Question to Steering Council (re recent PEP8 changes) In-Reply-To: <7c3ba329-c8bd-43ae-8e94-9faed3f12206@www.fastmail.com> References: <24318.5436.60768.176967@ixdm.fritz.box> <6edd3445-3bc3-59e7-a91a-1ecd8cdd4892@gmail.com> <0a25e19a-239d-4ede-437d-dfdd7d2e1d2f@gmail.com> <4a307f49-b211-4d74-aaee-8f2a1af87a83@www.fastmail.com> <81b71511-d2a9-8c75-3a5a-22cd866d7b73@kynesim.co.uk> <7c3ba329-c8bd-43ae-8e94-9faed3f12206@www.fastmail.com> Message-ID: On 04/07/2020 16:38, Random832 wrote: > On Fri, Jul 3, 2020, at 08:48, Rhodri James wrote: >> As I said in my preamble, it doesn't matter whether you believe that is >> true or think it's utter bollocks. I asked the question to get the >> Steering Council's opinion, not anyone else's. If you collectively >> really must rehash the arguments again, please have the decency to do so >> in a different thread. > > The idea that the statement was in any way related to one of the authors being named "White" was an *obvious factual mistake* in your post. Nope. It was a factual mistake in someone else's post. I hesitate to say "obvious" because I have in fact known people to genuinely think things like that. It is *still* irrelevant to what was asked of the Steering Council. -- Rhodri James *-* Kynesim Ltd From PythonList at DancesWithMice.info Mon Jul 6 05:51:30 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 6 Jul 2020 21:51:30 +1200 Subject: Assign Excel cell value from Datepicker widget Selection using Python In-Reply-To: <2aa39304-ee8c-492d-835d-b7cb69679a07o@googlegroups.com> References: <972e5d78-b594-43a1-88ef-43bf61e580a0o@googlegroups.com> <4b0b54b3-7d73-3619-fbc9-51e605025eb4@DancesWithMice.info> <2aa39304-ee8c-492d-835d-b7cb69679a07o@googlegroups.com> Message-ID: On 5/07/20 5:20 AM, narenchunduri at gmail.com wrote: > I am trying to assign a widget to an excel cell. Convertion wont help me.Thanks If you are following this post, you may be interested to view:- Using Widgets in Jupyter Notebook (Video) July 5, 2020 in the Mouse vs Python series. Whilst I haven't watched it myself, Mike's stuff is usually a solid investment! https://www.blog.pythonlibrary.org/2020/07/05/using-widgets-in-jupyter-notebook-video/ -- Regards =dn From a24061 at ducksburg.com Mon Jul 6 06:21:48 2020 From: a24061 at ducksburg.com (Adam Funk) Date: Mon, 06 Jul 2020 11:21:48 +0100 Subject: Bulletproof json.dump? Message-ID: Hi, I have a program that does a lot of work with URLs and requests, collecting data over about an hour, & then writing the collated data to a JSON file. The first time I ran it, the json.dump failed because there was a bytes value instead of a str, so I had to figure out where that was coming from before I could get any data out. I've previously run into the problem of collecting values in sets (for deduplication) & forgetting to walk through the big data object changing them to lists before serializing. Is there a "bulletproof" version of json.dump somewhere that will convert bytes to str, any other iterables to list, etc., so you can just get your data into a file & keep working? (I'm using Python 3.7.) Thanks! -- Slade was the coolest band in England. They were the kind of guys that would push your car out of a ditch. ---Alice Cooper From rosuav at gmail.com Mon Jul 6 07:36:15 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jul 2020 21:36:15 +1000 Subject: Bulletproof json.dump? In-Reply-To: References: Message-ID: On Mon, Jul 6, 2020 at 8:36 PM Adam Funk wrote: > > Hi, > > I have a program that does a lot of work with URLs and requests, > collecting data over about an hour, & then writing the collated data > to a JSON file. The first time I ran it, the json.dump failed because > there was a bytes value instead of a str, so I had to figure out where > that was coming from before I could get any data out. I've previously > run into the problem of collecting values in sets (for deduplication) > & forgetting to walk through the big data object changing them to > lists before serializing. > > Is there a "bulletproof" version of json.dump somewhere that will > convert bytes to str, any other iterables to list, etc., so you can > just get your data into a file & keep working? > That's the PHP definition of "bulletproof" - whatever happens, no matter how bad, just keep right on going. If you really want some way to write "just anything" to your file, I recommend not using JSON - instead, write out the repr of your data structure. That'll give a decent result for bytes, str, all forms of numbers, and pretty much any collection, and it won't break if given something that can't safely be represented. ChrisA From jon+usenet at unequivocal.eu Mon Jul 6 08:06:18 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 6 Jul 2020 12:06:18 -0000 (UTC) Subject: Bulletproof json.dump? References: Message-ID: On 2020-07-06, Chris Angelico wrote: > On Mon, Jul 6, 2020 at 8:36 PM Adam Funk wrote: >> Is there a "bulletproof" version of json.dump somewhere that will >> convert bytes to str, any other iterables to list, etc., so you can >> just get your data into a file & keep working? > > That's the PHP definition of "bulletproof" - whatever happens, no > matter how bad, just keep right on going. While I agree entirely with your point, there is however perhaps room for a bit more helpfulness from the json module. There is no sensible reason I can think of that it refuses to serialize sets, for example. Going a bit further and, for example, automatically calling isoformat() on date/time/datetime objects would perhaps be a bit more controversial, but would frequently be useful, and there's no obvious downside that occurs to me. From rosuav at gmail.com Mon Jul 6 08:20:31 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jul 2020 22:20:31 +1000 Subject: Bulletproof json.dump? In-Reply-To: References: Message-ID: On Mon, Jul 6, 2020 at 10:11 PM Jon Ribbens via Python-list wrote: > > On 2020-07-06, Chris Angelico wrote: > > On Mon, Jul 6, 2020 at 8:36 PM Adam Funk wrote: > >> Is there a "bulletproof" version of json.dump somewhere that will > >> convert bytes to str, any other iterables to list, etc., so you can > >> just get your data into a file & keep working? > > > > That's the PHP definition of "bulletproof" - whatever happens, no > > matter how bad, just keep right on going. > > While I agree entirely with your point, there is however perhaps room > for a bit more helpfulness from the json module. There is no sensible > reason I can think of that it refuses to serialize sets, for example. Sets don't exist in JSON. I think that's a sensible reason. > Going a bit further and, for example, automatically calling isoformat() > on date/time/datetime objects would perhaps be a bit more controversial, > but would frequently be useful, and there's no obvious downside that > occurs to me. They wouldn't round-trip without some way of knowing which strings represent date/times. If you just want a one-way output format, it's not too hard to subclass the encoder - there's an example right there in the docs (showing how to create a representation for complex numbers). The vanilla JSON encoder shouldn't do any of this. In fact, just supporting infinities and nans is fairly controversial - see other threads happening right now. Maybe what people want is a pretty printer instead? https://docs.python.org/3/library/pprint.html Resilient against recursive data structures, able to emit Python-like code for many formats, is as readable as JSON, and is often round-trippable. It lacks JSON's interoperability, but if you're trying to serialize sets and datetimes, you're forfeiting that anyway. ChrisA From frank at chagford.com Mon Jul 6 08:42:55 2020 From: frank at chagford.com (Frank Millman) Date: Mon, 6 Jul 2020 14:42:55 +0200 Subject: Bulletproof json.dump? In-Reply-To: References: Message-ID: On 2020-07-06 2:06 PM, Jon Ribbens via Python-list wrote: > On 2020-07-06, Chris Angelico wrote: >> On Mon, Jul 6, 2020 at 8:36 PM Adam Funk wrote: >>> Is there a "bulletproof" version of json.dump somewhere that will >>> convert bytes to str, any other iterables to list, etc., so you can >>> just get your data into a file & keep working? >> >> That's the PHP definition of "bulletproof" - whatever happens, no >> matter how bad, just keep right on going. > > While I agree entirely with your point, there is however perhaps room > for a bit more helpfulness from the json module. There is no sensible > reason I can think of that it refuses to serialize sets, for example. > Going a bit further and, for example, automatically calling isoformat() > on date/time/datetime objects would perhaps be a bit more controversial, > but would frequently be useful, and there's no obvious downside that > occurs to me. > I may be missing something, but that would cause a downside for me. I store Python lists and dicts in a database by calling dumps() when saving them to the database and loads() when retrieving them. If a date was 'dumped' using isoformat(), then on retrieval I would not know whether it was originally a string, which must remain as is, or was originally a date object, which must be converted back to a date object. There is no perfect answer, but my solution works fairly well. When dumping, I use 'default=repr'. This means that dates get dumped as 'datetime.date(2020, 7, 6)'. I look for that pattern on retrieval to detect that it is actually a date object. I use the same trick for Decimal objects. Maybe the OP could do something similar. Frank Millman From frank at chagford.com Mon Jul 6 08:42:55 2020 From: frank at chagford.com (Frank Millman) Date: Mon, 6 Jul 2020 14:42:55 +0200 Subject: Bulletproof json.dump? In-Reply-To: References: Message-ID: On 2020-07-06 2:06 PM, Jon Ribbens via Python-list wrote: > On 2020-07-06, Chris Angelico wrote: >> On Mon, Jul 6, 2020 at 8:36 PM Adam Funk wrote: >>> Is there a "bulletproof" version of json.dump somewhere that will >>> convert bytes to str, any other iterables to list, etc., so you can >>> just get your data into a file & keep working? >> >> That's the PHP definition of "bulletproof" - whatever happens, no >> matter how bad, just keep right on going. > > While I agree entirely with your point, there is however perhaps room > for a bit more helpfulness from the json module. There is no sensible > reason I can think of that it refuses to serialize sets, for example. > Going a bit further and, for example, automatically calling isoformat() > on date/time/datetime objects would perhaps be a bit more controversial, > but would frequently be useful, and there's no obvious downside that > occurs to me. > I may be missing something, but that would cause a downside for me. I store Python lists and dicts in a database by calling dumps() when saving them to the database and loads() when retrieving them. If a date was 'dumped' using isoformat(), then on retrieval I would not know whether it was originally a string, which must remain as is, or was originally a date object, which must be converted back to a date object. There is no perfect answer, but my solution works fairly well. When dumping, I use 'default=repr'. This means that dates get dumped as 'datetime.date(2020, 7, 6)'. I look for that pattern on retrieval to detect that it is actually a date object. I use the same trick for Decimal objects. Maybe the OP could do something similar. Frank Millman From jpic at yourlabs.org Mon Jul 6 08:59:41 2020 From: jpic at yourlabs.org (J. Pic) Date: Mon, 6 Jul 2020 14:59:41 +0200 Subject: Bulletproof json.dump? In-Reply-To: References: Message-ID: Well I made a suggestion on python-ideas and a PyPi lib came out of it, but since you can't patch a lot of internal types it's not so useful. Feel free to try it out: https://yourlabs.io/oss/jsonlight/ From jon+usenet at unequivocal.eu Mon Jul 6 09:04:41 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 6 Jul 2020 13:04:41 -0000 (UTC) Subject: Bulletproof json.dump? References: Message-ID: On 2020-07-06, Chris Angelico wrote: > On Mon, Jul 6, 2020 at 10:11 PM Jon Ribbens via Python-list > wrote: >> While I agree entirely with your point, there is however perhaps room >> for a bit more helpfulness from the json module. There is no sensible >> reason I can think of that it refuses to serialize sets, for example. > > Sets don't exist in JSON. I think that's a sensible reason. It is not. Tuples don't exist either, and yet they're supported. >> Going a bit further and, for example, automatically calling isoformat() >> on date/time/datetime objects would perhaps be a bit more controversial, >> but would frequently be useful, and there's no obvious downside that >> occurs to me. > > They wouldn't round-trip without some way of knowing which strings > represent date/times. The 'json' module already fails to provide round-trip functionality: >>> for data in ({True: 1}, {1: 2}, (1, 2)): ... if json.loads(json.dumps(data)) != data: ... print('oops', data, json.loads(json.dumps(data))) ... oops {True: 1} {'true': 1} oops {1: 2} {'1': 2} oops (1, 2) [1, 2] > Maybe what people want is a pretty printer instead? No. I want a JSON encoder to output JSON to be read by a JSON decoder. From jon+usenet at unequivocal.eu Mon Jul 6 09:08:24 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 6 Jul 2020 13:08:24 -0000 (UTC) Subject: Bulletproof json.dump? References: Message-ID: On 2020-07-06, Frank Millman wrote: > On 2020-07-06 2:06 PM, Jon Ribbens via Python-list wrote: >> While I agree entirely with your point, there is however perhaps room >> for a bit more helpfulness from the json module. There is no sensible >> reason I can think of that it refuses to serialize sets, for example. >> Going a bit further and, for example, automatically calling isoformat() >> on date/time/datetime objects would perhaps be a bit more controversial, >> but would frequently be useful, and there's no obvious downside that >> occurs to me. > > I may be missing something, but that would cause a downside for me. > > I store Python lists and dicts in a database by calling dumps() when > saving them to the database and loads() when retrieving them. > > If a date was 'dumped' using isoformat(), then on retrieval I would not > know whether it was originally a string, which must remain as is, or was > originally a date object, which must be converted back to a date object. > > There is no perfect answer, but my solution works fairly well. When > dumping, I use 'default=repr'. This means that dates get dumped as > 'datetime.date(2020, 7, 6)'. I look for that pattern on retrieval to > detect that it is actually a date object. There is no difference whatsoever between matching on the repr output you show above and matching on ISO-8601 datetimes, except that at least ISO-8601 is an actual standard. So no, you haven't found a downside. From rosuav at gmail.com Mon Jul 6 09:10:15 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jul 2020 23:10:15 +1000 Subject: Bulletproof json.dump? In-Reply-To: References: Message-ID: On Mon, Jul 6, 2020 at 11:06 PM Jon Ribbens via Python-list wrote: > > On 2020-07-06, Chris Angelico wrote: > > On Mon, Jul 6, 2020 at 10:11 PM Jon Ribbens via Python-list > > wrote: > >> While I agree entirely with your point, there is however perhaps room > >> for a bit more helpfulness from the json module. There is no sensible > >> reason I can think of that it refuses to serialize sets, for example. > > > > Sets don't exist in JSON. I think that's a sensible reason. > > It is not. Tuples don't exist either, and yet they're supported. Hmm, I didn't know that. Possibly it's as much a bug as the inf/nan issue. > >> Going a bit further and, for example, automatically calling isoformat() > >> on date/time/datetime objects would perhaps be a bit more controversial, > >> but would frequently be useful, and there's no obvious downside that > >> occurs to me. > > > > They wouldn't round-trip without some way of knowing which strings > > represent date/times. > > The 'json' module already fails to provide round-trip functionality: > > >>> for data in ({True: 1}, {1: 2}, (1, 2)): > ... if json.loads(json.dumps(data)) != data: > ... print('oops', data, json.loads(json.dumps(data))) > ... > oops {True: 1} {'true': 1} > oops {1: 2} {'1': 2} > oops (1, 2) [1, 2] There's a fundamental limitation of JSON in that it requires string keys, so this is an obvious transformation. I suppose you could call that one a bug too, but it's very useful and not too dangerous. (And then there's the tuple-to-list transformation, which I think probably shouldn't happen, although I don't think that's likely to cause issues either.) > > Maybe what people want is a pretty printer instead? > > No. I want a JSON encoder to output JSON to be read by a JSON decoder. Does it need to round-trip, though? If you stringify your datetimes, you can't decode it reliably any more. What's the purpose here? ChrisA From jon+usenet at unequivocal.eu Mon Jul 6 09:14:37 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 6 Jul 2020 13:14:37 -0000 (UTC) Subject: Bulletproof json.dump? References: Message-ID: On 2020-07-06, J. Pic wrote: > Well I made a suggestion on python-ideas and a PyPi lib came out of it, but > since you can't patch a lot of internal types it's not so useful. > > Feel free to try it out: > > https://yourlabs.io/oss/jsonlight/ While I applaud your experimentation, that is not suitable for any purpose. You would probably do better by starting off subclassing json.JSONEncoder. From jon+usenet at unequivocal.eu Mon Jul 6 09:28:31 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 6 Jul 2020 13:28:31 -0000 (UTC) Subject: Bulletproof json.dump? References: Message-ID: On 2020-07-06, Chris Angelico wrote: > On Mon, Jul 6, 2020 at 11:06 PM Jon Ribbens via Python-list > wrote: >> The 'json' module already fails to provide round-trip functionality: >> >> >>> for data in ({True: 1}, {1: 2}, (1, 2)): >> ... if json.loads(json.dumps(data)) != data: >> ... print('oops', data, json.loads(json.dumps(data))) >> ... >> oops {True: 1} {'true': 1} >> oops {1: 2} {'1': 2} >> oops (1, 2) [1, 2] > > There's a fundamental limitation of JSON in that it requires string > keys, so this is an obvious transformation. I suppose you could call > that one a bug too, but it's very useful and not too dangerous. (And > then there's the tuple-to-list transformation, which I think probably > shouldn't happen, although I don't think that's likely to cause issues > either.) That's my point though - there's almost no difference between allowing encoding of tuples and allowing encoding of sets. Any argument against the latter would also apply against the former. The only possible excuse for the difference is "historical reasons", and given that it would be useful to allow it, and there would be no negative consequences, this hardly seems sufficient. >> No. I want a JSON encoder to output JSON to be read by a JSON decoder. > > Does it need to round-trip, though? If you stringify your datetimes, > you can't decode it reliably any more. What's the purpose here? It doesn't need to round trip (which as mentioned above is fortunate because the existing module already doesn't round trip). The main use I have, and I should imagine the main use anyone has, for JSON is interoperability - to safely store and send data in a format in which it can be read by non-Python code. If you need, say, date/times to be understood as date/times by the receiving code they'll have to deal with that explicitly already. Improving Python to allow sending them at least gets us part way there by eliminating half the work. From frank at chagford.com Mon Jul 6 09:33:41 2020 From: frank at chagford.com (Frank Millman) Date: Mon, 6 Jul 2020 15:33:41 +0200 Subject: Bulletproof json.dump? In-Reply-To: References: Message-ID: <794ad350-d97d-91e2-60aa-65da0d865c97@chagford.com> On 2020-07-06 3:08 PM, Jon Ribbens via Python-list wrote: > On 2020-07-06, Frank Millman wrote: >> On 2020-07-06 2:06 PM, Jon Ribbens via Python-list wrote: >>> While I agree entirely with your point, there is however perhaps room >>> for a bit more helpfulness from the json module. There is no sensible >>> reason I can think of that it refuses to serialize sets, for example. >>> Going a bit further and, for example, automatically calling isoformat() >>> on date/time/datetime objects would perhaps be a bit more controversial, >>> but would frequently be useful, and there's no obvious downside that >>> occurs to me. >> >> I may be missing something, but that would cause a downside for me. >> >> I store Python lists and dicts in a database by calling dumps() when >> saving them to the database and loads() when retrieving them. >> >> If a date was 'dumped' using isoformat(), then on retrieval I would not >> know whether it was originally a string, which must remain as is, or was >> originally a date object, which must be converted back to a date object. >> >> There is no perfect answer, but my solution works fairly well. When >> dumping, I use 'default=repr'. This means that dates get dumped as >> 'datetime.date(2020, 7, 6)'. I look for that pattern on retrieval to >> detect that it is actually a date object. > > There is no difference whatsoever between matching on the repr output > you show above and matching on ISO-8601 datetimes, except that at least > ISO-8601 is an actual standard. So no, you haven't found a downside. > I don't understand. As you say, ISO-8601 is a standard, so the original object could well have been a string in that format. So how do you distinguish between an object that started out as a string, and an object that started out as a date/datetime object? Frank From frank at chagford.com Mon Jul 6 09:33:41 2020 From: frank at chagford.com (Frank Millman) Date: Mon, 6 Jul 2020 15:33:41 +0200 Subject: Bulletproof json.dump? In-Reply-To: References: Message-ID: <794ad350-d97d-91e2-60aa-65da0d865c97@chagford.com> On 2020-07-06 3:08 PM, Jon Ribbens via Python-list wrote: > On 2020-07-06, Frank Millman wrote: >> On 2020-07-06 2:06 PM, Jon Ribbens via Python-list wrote: >>> While I agree entirely with your point, there is however perhaps room >>> for a bit more helpfulness from the json module. There is no sensible >>> reason I can think of that it refuses to serialize sets, for example. >>> Going a bit further and, for example, automatically calling isoformat() >>> on date/time/datetime objects would perhaps be a bit more controversial, >>> but would frequently be useful, and there's no obvious downside that >>> occurs to me. >> >> I may be missing something, but that would cause a downside for me. >> >> I store Python lists and dicts in a database by calling dumps() when >> saving them to the database and loads() when retrieving them. >> >> If a date was 'dumped' using isoformat(), then on retrieval I would not >> know whether it was originally a string, which must remain as is, or was >> originally a date object, which must be converted back to a date object. >> >> There is no perfect answer, but my solution works fairly well. When >> dumping, I use 'default=repr'. This means that dates get dumped as >> 'datetime.date(2020, 7, 6)'. I look for that pattern on retrieval to >> detect that it is actually a date object. > > There is no difference whatsoever between matching on the repr output > you show above and matching on ISO-8601 datetimes, except that at least > ISO-8601 is an actual standard. So no, you haven't found a downside. > I don't understand. As you say, ISO-8601 is a standard, so the original object could well have been a string in that format. So how do you distinguish between an object that started out as a string, and an object that started out as a date/datetime object? Frank From a24061 at ducksburg.com Mon Jul 6 09:27:58 2020 From: a24061 at ducksburg.com (Adam Funk) Date: Mon, 06 Jul 2020 14:27:58 +0100 Subject: Bulletproof json.dump? References: Message-ID: On 2020-07-06, Chris Angelico wrote: > On Mon, Jul 6, 2020 at 8:36 PM Adam Funk wrote: >> >> Hi, >> >> I have a program that does a lot of work with URLs and requests, >> collecting data over about an hour, & then writing the collated data >> to a JSON file. The first time I ran it, the json.dump failed because >> there was a bytes value instead of a str, so I had to figure out where >> that was coming from before I could get any data out. I've previously >> run into the problem of collecting values in sets (for deduplication) >> & forgetting to walk through the big data object changing them to >> lists before serializing. >> >> Is there a "bulletproof" version of json.dump somewhere that will >> convert bytes to str, any other iterables to list, etc., so you can >> just get your data into a file & keep working? >> > > That's the PHP definition of "bulletproof" - whatever happens, no > matter how bad, just keep right on going. If you really want some way Well played! > to write "just anything" to your file, I recommend not using JSON - > instead, write out the repr of your data structure. That'll give a > decent result for bytes, str, all forms of numbers, and pretty much > any collection, and it won't break if given something that can't > safely be represented. Interesting point. At least the TypeError message does say what the unacceptable type is ("Object of type set is not JSON serializable"). -- "It is the role of librarians to keep government running in difficult times," replied Dramoren. "Librarians are the last line of defence against chaos." (McMullen 2001) From a24061 at ducksburg.com Mon Jul 6 09:24:25 2020 From: a24061 at ducksburg.com (Adam Funk) Date: Mon, 06 Jul 2020 14:24:25 +0100 Subject: Bulletproof json.dump? References: Message-ID: <99lbtgxcr4.ln2@news.ducksburg.com> On 2020-07-06, Frank Millman wrote: > On 2020-07-06 2:06 PM, Jon Ribbens via Python-list wrote: >> On 2020-07-06, Chris Angelico wrote: >>> On Mon, Jul 6, 2020 at 8:36 PM Adam Funk wrote: >>>> Is there a "bulletproof" version of json.dump somewhere that will >>>> convert bytes to str, any other iterables to list, etc., so you can >>>> just get your data into a file & keep working? >>> >>> That's the PHP definition of "bulletproof" - whatever happens, no >>> matter how bad, just keep right on going. >> >> While I agree entirely with your point, there is however perhaps room >> for a bit more helpfulness from the json module. There is no sensible >> reason I can think of that it refuses to serialize sets, for example. >> Going a bit further and, for example, automatically calling isoformat() >> on date/time/datetime objects would perhaps be a bit more controversial, >> but would frequently be useful, and there's no obvious downside that >> occurs to me. >> > > I may be missing something, but that would cause a downside for me. > > I store Python lists and dicts in a database by calling dumps() when > saving them to the database and loads() when retrieving them. > > If a date was 'dumped' using isoformat(), then on retrieval I would not > know whether it was originally a string, which must remain as is, or was > originally a date object, which must be converted back to a date object. > > There is no perfect answer, but my solution works fairly well. When > dumping, I use 'default=repr'. This means that dates get dumped as > 'datetime.date(2020, 7, 6)'. I look for that pattern on retrieval to > detect that it is actually a date object. > > I use the same trick for Decimal objects. > > Maybe the OP could do something similar. Aha, I think the default=repr option is probably just what I need; maybe (at least in the testing stages) something like this: try: with open(output_file, 'w') as f: json.dump(f) except TypeError: print('unexpected item in the bagging area!') with open(output_file, 'w') as f: json.dump(f, default=repr) and then I'd know when I need to go digging through the output for bytes, sets, etc., but at least I'd have the output to examine. -- Well, we had a lot of luck on Venus We always had a ball on Mars From rosuav at gmail.com Mon Jul 6 09:42:40 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jul 2020 23:42:40 +1000 Subject: Bulletproof json.dump? In-Reply-To: References: Message-ID: On Mon, Jul 6, 2020 at 11:31 PM Jon Ribbens via Python-list wrote: > > On 2020-07-06, Chris Angelico wrote: > > On Mon, Jul 6, 2020 at 11:06 PM Jon Ribbens via Python-list > > wrote: > >> The 'json' module already fails to provide round-trip functionality: > >> > >> >>> for data in ({True: 1}, {1: 2}, (1, 2)): > >> ... if json.loads(json.dumps(data)) != data: > >> ... print('oops', data, json.loads(json.dumps(data))) > >> ... > >> oops {True: 1} {'true': 1} > >> oops {1: 2} {'1': 2} > >> oops (1, 2) [1, 2] > > > > There's a fundamental limitation of JSON in that it requires string > > keys, so this is an obvious transformation. I suppose you could call > > that one a bug too, but it's very useful and not too dangerous. (And > > then there's the tuple-to-list transformation, which I think probably > > shouldn't happen, although I don't think that's likely to cause issues > > either.) > > That's my point though - there's almost no difference between allowing > encoding of tuples and allowing encoding of sets. Any argument against > the latter would also apply against the former. The only possible excuse > for the difference is "historical reasons", and given that it would be > useful to allow it, and there would be no negative consequences, this > hardly seems sufficient. > > >> No. I want a JSON encoder to output JSON to be read by a JSON decoder. > > > > Does it need to round-trip, though? If you stringify your datetimes, > > you can't decode it reliably any more. What's the purpose here? > > It doesn't need to round trip (which as mentioned above is fortunate > because the existing module already doesn't round trip). The main use > I have, and I should imagine the main use anyone has, for JSON is > interoperability - to safely store and send data in a format in which > it can be read by non-Python code. If you need, say, date/times to > be understood as date/times by the receiving code they'll have to > deal with that explicitly already. Improving Python to allow sending > them at least gets us part way there by eliminating half the work. That's fair. Maybe what we need is to fork out the default JSON encoder into two, or have a "strict=True" or "strict=False" flag. In non-strict mode, round-tripping is not guaranteed, and various types will be folded to each other - mainly, many built-in and stdlib types will be represented in strings. In strict mode, compliance with the RFC is ensured (so ValueError will be raised on inf/nan), and everything should round-trip safely. I think that even in non-strict mode, round-tripping should be achieved after one iteration. That is to say, anything you can JSON-encode will JSON-decode to something that would create the same encoded form. Not sure if there's anything that would violate that (weak) guarantee. ChrisA From a24061 at ducksburg.com Mon Jul 6 09:31:54 2020 From: a24061 at ducksburg.com (Adam Funk) Date: Mon, 06 Jul 2020 14:31:54 +0100 Subject: Bulletproof json.dump? References: Message-ID: On 2020-07-06, Chris Angelico wrote: > On Mon, Jul 6, 2020 at 10:11 PM Jon Ribbens via Python-list > wrote: >> >> On 2020-07-06, Chris Angelico wrote: >> > On Mon, Jul 6, 2020 at 8:36 PM Adam Funk wrote: >> >> Is there a "bulletproof" version of json.dump somewhere that will >> >> convert bytes to str, any other iterables to list, etc., so you can >> >> just get your data into a file & keep working? >> > >> > That's the PHP definition of "bulletproof" - whatever happens, no >> > matter how bad, just keep right on going. >> >> While I agree entirely with your point, there is however perhaps room >> for a bit more helpfulness from the json module. There is no sensible >> reason I can think of that it refuses to serialize sets, for example. > > Sets don't exist in JSON. I think that's a sensible reason. I don't agree. Tuples & lists don't exist separately in JSON, but both are serializable (to the same thing). Non-string keys aren't allowed in JSON, but it silently converts numbers to strings instead of barfing. Typically, I've been using sets to deduplicate values as I go along, & having to walk through the whole object changing them to lists before serialization strikes me as the kind of pointless labor that I expect when I'm using Java. ;-) >> Going a bit further and, for example, automatically calling isoformat() >> on date/time/datetime objects would perhaps be a bit more controversial, >> but would frequently be useful, and there's no obvious downside that >> occurs to me. > > They wouldn't round-trip without some way of knowing which strings > represent date/times. If you just want a one-way output format, it's > not too hard to subclass the encoder - there's an example right there > in the docs (showing how to create a representation for complex > numbers). The vanilla JSON encoder shouldn't do any of this. In fact, > just supporting infinities and nans is fairly controversial - see > other threads happening right now. > > Maybe what people want is a pretty printer instead? > > https://docs.python.org/3/library/pprint.html > > Resilient against recursive data structures, able to emit Python-like > code for many formats, is as readable as JSON, and is often > round-trippable. It lacks JSON's interoperability, but if you're > trying to serialize sets and datetimes, you're forfeiting that anyway. > > ChrisA -- "It is the role of librarians to keep government running in difficult times," replied Dramoren. "Librarians are the last line of defence against chaos." (McMullen 2001) From jon+usenet at unequivocal.eu Mon Jul 6 09:46:51 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 6 Jul 2020 13:46:51 -0000 (UTC) Subject: Bulletproof json.dump? References: <794ad350-d97d-91e2-60aa-65da0d865c97@chagford.com> Message-ID: On 2020-07-06, Frank Millman wrote: > On 2020-07-06 3:08 PM, Jon Ribbens via Python-list wrote: >> On 2020-07-06, Frank Millman wrote: >>> On 2020-07-06 2:06 PM, Jon Ribbens via Python-list wrote: >>>> While I agree entirely with your point, there is however perhaps room >>>> for a bit more helpfulness from the json module. There is no sensible >>>> reason I can think of that it refuses to serialize sets, for example. >>>> Going a bit further and, for example, automatically calling isoformat() >>>> on date/time/datetime objects would perhaps be a bit more controversial, >>>> but would frequently be useful, and there's no obvious downside that >>>> occurs to me. >>> >>> I may be missing something, but that would cause a downside for me. >>> >>> I store Python lists and dicts in a database by calling dumps() when >>> saving them to the database and loads() when retrieving them. >>> >>> If a date was 'dumped' using isoformat(), then on retrieval I would not >>> know whether it was originally a string, which must remain as is, or was >>> originally a date object, which must be converted back to a date object. >>> >>> There is no perfect answer, but my solution works fairly well. When >>> dumping, I use 'default=repr'. This means that dates get dumped as >>> 'datetime.date(2020, 7, 6)'. I look for that pattern on retrieval to >>> detect that it is actually a date object. >> >> There is no difference whatsoever between matching on the repr output >> you show above and matching on ISO-8601 datetimes, except that at least >> ISO-8601 is an actual standard. So no, you haven't found a downside. > > I don't understand. As you say, ISO-8601 is a standard, so the original > object could well have been a string in that format. So how do you > distinguish between an object that started out as a string, and an > object that started out as a date/datetime object? With your method, how do you distinguish between an object that started out as a string, and an object that started out as a date/datetime object? The answer with both my method and your method is that you cannot - and therefore my method is not a "downside" compared to yours. Not to mention, I am not suggesting that your method should be disallowed if you want to continue using it - I am suggesting that your code could be simplified and your job made easier by my suggested improvement. From rosuav at gmail.com Mon Jul 6 09:51:36 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jul 2020 23:51:36 +1000 Subject: Bulletproof json.dump? In-Reply-To: <99lbtgxcr4.ln2@news.ducksburg.com> References: <99lbtgxcr4.ln2@news.ducksburg.com> Message-ID: On Mon, Jul 6, 2020 at 11:39 PM Adam Funk wrote: > > Aha, I think the default=repr option is probably just what I need; > maybe (at least in the testing stages) something like this: > > try: > with open(output_file, 'w') as f: > json.dump(f) > except TypeError: > print('unexpected item in the bagging area!') > with open(output_file, 'w') as f: > json.dump(f, default=repr) > > and then I'd know when I need to go digging through the output for > bytes, sets, etc., but at least I'd have the output to examine. > Easier: def proclaimed_repr(): seen = False def show_obj(obj): nonlocal seen if not seen: seen = True print("unexpected item in the bagging area!") return repr(obj) return show_obj json.dump(f, default=proclaimed_repr()) If you don't care about "resetting" the marker, you can just use a global or a default-arg hack: def show_obj(obj, seen=[]): if not seen: seen.push(True) print("unexpected item in the bagging area!") return repr(obj) json.dump(f, default=show_obj) Either way, you can stick this function off in a utilities collection, and then use it without fiddling with try/except. ChrisA From jon+usenet at unequivocal.eu Mon Jul 6 09:59:46 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 6 Jul 2020 13:59:46 -0000 (UTC) Subject: Bulletproof json.dump? References: Message-ID: On 2020-07-06, Chris Angelico wrote: > I think that even in non-strict mode, round-tripping should be > achieved after one iteration. That is to say, anything you can > JSON-encode will JSON-decode to something that would create the same > encoded form. Not sure if there's anything that would violate that > (weak) guarantee. I think what you're saying is, if we do: json1 = json.dumps(foo) json2 = json.dumps(json.loads(json1)) assert json1 == json2 the assertion should never fail (given that Python dictionaries are ordered these days). I seems to me that should probably be true regardless of any 'strict mode' flag - I can't immediately think of any reason it wouldn't be. From rosuav at gmail.com Mon Jul 6 10:03:11 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jul 2020 00:03:11 +1000 Subject: Bulletproof json.dump? In-Reply-To: References: Message-ID: On Tue, Jul 7, 2020 at 12:01 AM Jon Ribbens via Python-list wrote: > > On 2020-07-06, Chris Angelico wrote: > > I think that even in non-strict mode, round-tripping should be > > achieved after one iteration. That is to say, anything you can > > JSON-encode will JSON-decode to something that would create the same > > encoded form. Not sure if there's anything that would violate that > > (weak) guarantee. > > I think what you're saying is, if we do: > > json1 = json.dumps(foo) > json2 = json.dumps(json.loads(json1)) > assert json1 == json2 > > the assertion should never fail (given that Python dictionaries are > ordered these days). I seems to me that should probably be true > regardless of any 'strict mode' flag - I can't immediately think of > any reason it wouldn't be. Right. But in strict mode, the stronger assertion would hold: assert obj == json.loads(json.dumps(obj)) Also, the intermediate text would be RFC-compliant. If this cannot be done, ValueError would be raised. (Or maybe TypeError in some cases.) ChrisA From jon+usenet at unequivocal.eu Mon Jul 6 10:32:49 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 6 Jul 2020 14:32:49 -0000 (UTC) Subject: Bulletproof json.dump? References: Message-ID: On 2020-07-06, Chris Angelico wrote: > On Tue, Jul 7, 2020 at 12:01 AM Jon Ribbens via Python-list > wrote: >> I think what you're saying is, if we do: >> >> json1 = json.dumps(foo) >> json2 = json.dumps(json.loads(json1)) >> assert json1 == json2 >> >> the assertion should never fail (given that Python dictionaries are >> ordered these days). I seems to me that should probably be true >> regardless of any 'strict mode' flag - I can't immediately think of >> any reason it wouldn't be. > > Right. But in strict mode, the stronger assertion would hold: > > assert obj == json.loads(json.dumps(obj)) > > Also, the intermediate text would be RFC-compliant. If this cannot be > done, ValueError would be raised. (Or maybe TypeError in some cases.) Yes, I agree (although you'd need to call it something other than 'strict' mode, since that flag already exists). But note nothing I am suggesting would involve JSONEncoder ever producing non-standard output (except in cases where it already would). From jpic at yourlabs.org Mon Jul 6 10:45:39 2020 From: jpic at yourlabs.org (J. Pic) Date: Mon, 6 Jul 2020 16:45:39 +0200 Subject: Bulletproof json.dump? In-Reply-To: References: <794ad350-d97d-91e2-60aa-65da0d865c97@chagford.com> Message-ID: You can achieve round-tripping by maintaining a type mapping in code, for a single datatype it would look like: newloads(datetime, newdumps(datetime.now()) If those would rely on __dump__ and __load__ functions in the fashion of pickle then nested data structures would also be easy: @dataclass class YourStruct: dt = datetime children = [] @classmethod def __load__(cls, data): return cls( dt=datetime.fromisoformat(data['dt']), children=[cls.__load__(c) for c in data['children']]) ) def __dump__(self): return dict( dt=self.dt.isoformat(), children=[c.__dump__() for c in self.children], ) If your datetime is not being loaded from C-code you can even monkey patch it and add __load__ and __dump__ on it and data round-trip as long as you keep the type mapping in a method. From rami.chowdhury at gmail.com Mon Jul 6 22:32:34 2020 From: rami.chowdhury at gmail.com (rami.chowdhury at gmail.com) Date: Mon, 06 Jul 2020 22:32:34 -0400 Subject: [PSF-Community] Unable to login | fbchat.Client In-Reply-To: References: Message-ID: Hi Shivam, Please be aware this mailing list is for PSF community-focused discussions -- see the list's purpose described at https://mail.python.org/mailman/listinfo/psf-community. I might suggest you participate in the discussion on on the `fbchat` project repository on GitHub -- the issue at https://github.com/carpedm20/fbchat/issues/598 seems to match the error you've pasted. Alternatively, you could try directing your question to the general Python list (python-list at python.org, CC'd here). Regards, Rami On Tue, Jul 7, 2020 at 07:52, Shivam Dutt Sharma wrote: > Dear All, > > I am facing an error while trying to log-in to fbchat.Client. This is > obviously despite me entering absolutely correct ID & P/W. It could > be because of any latest update in the package, or a user_agent / > session (cookies) issue too. > Prima-facie, if you think a few adjustments need to be made in the > client or state file/s, please let me know, else I shall share the > complete code link for your perusal. > > Below's the error message. I will be highly grateful, if I can get an > idea of where am I going wrong? > > Logging in xxxxxx.x.xxxxxx... > Attempt #1 failed, retrying > Traceback (most recent call last): > File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_client.py", > line 209, in login > user_agent=user_agent, > File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_state.py", > line 149, in login > return cls.from_session(session=session) > File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_state.py", > line 186, in from_session > fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1) > AttributeError: 'NoneType' object has no attribute 'group' > > Best, > Shivam Dutt Sharma > LinkedIn : shivam-dutt-sharma-020456149 > PGP in Machine Learning | NIT Warangal > Fundraising Volunteer @ The AIM Foundation > PCEP @ PythonInstitute > > > > From PythonList at DancesWithMice.info Tue Jul 7 02:04:07 2020 From: PythonList at DancesWithMice.info (dn) Date: Tue, 7 Jul 2020 18:04:07 +1200 Subject: Questioning the effects of multiple assignment Message-ID: <5aa9d135-d110-f38a-4dab-874147b19e62@etelligence.info> TLDR; if you are a Python 'Master' then feel free to skim the first part (which you should know hands-down), until the excerpts from 'the manual' and from there I'll be interested in learning from you... Yesterday I asked a junior prog to expand an __init__() to accept either a series of (>1) scalars (as it does now), or to take similar values but presented as a tuple. He was a bit concerned that I didn't want to introduce a (separate) keyword-argument, until 'we' remembered starred-parameters. He then set about experimenting. Here's a dichotomy that surfaced as part of our 'play':- (my problem is: I can't (reasonably) answer his question...) If you read this code: NB The print-ing does not follow the input-sequence, because that's the point to be made... >>> def f( a, *b, c=0 ): ... print( a, type( a ) ) ... print( c, type( c ) ) ... print( b ) ... >>> f( 1, 'two', 3, 'four' ) [I had to force "c" to become a keyword argument, but other than that, we'll be using these three parameters and four argument-values, again] Question 1: did you correctly predict the output? 1 0 ('two', 3, 'four') Ahah, "c" went to default because there was no way to identify when the "*b" 'stopped' and "c" started - so all the values 'went' to become "b" (were all "consumed by"...). Why did I also print "b" differently? Building tension! Please read on, gentle reader... Let's make two small changes: - amend the last line of the function to be similar: ... print( b, type( b ) ) - make proper use of the function's API: >>> f( 1, 'two', 3, c='four' ) Question 2: can you predict the output of "a"? Well duh! (same as before) 1 Question 3: has your predicted output of "c" changed? Yes? Good! (Web.Refs below, explain; should you wish...) four Question 4: can you correctly predict the content of "b" and its type? ('two', 3) That makes sense, doesn't it? The arguments were presented to the function as a tuple, and those not assigned to a scalar value ("a" and "c") were kept as a tuple when assigned to "b". Jolly good show, chaps! (which made my young(er) colleague very happy, because now he could see that by checking the length of the parameter, such would reveal if the arguments were being passed as scalars or as a tuple. Aside: however, it made me think how handy it would be if the newly-drafted PEP 622 -- Structural Pattern Matching were available today (proposed for v3.10, https://www.python.org/dev/peps/pep-0622/) because (YAGNI-aside) we could then more-easily empower the API to accept other/more collections! Why am I writing then? Because during the same conversations I was 'demonstrating'/training/playing with some code that is (apparently) very similar - and yet, it's not. Oops! Sticking with the same, toy-data, let's code: >>> a, *b, c = 1, 'two', 3, 'four' >>> a, type( a ) >>> c, type( c ) >>> b, type( b ) Question 5: what do you expect "a" and "c" to deliver in this context? (1, ) ('four', ) Happy so far? Question 6: (for maximum effect, re-read snippets from above, then) what do you expect from "b"? (['two', 3], ) List? A list? What's this "list" stuff??? When "b" was a parameter (above) it was assigned a tuple! Are you as shocked as I? Have you learned something? (will it ever be useful?) Has the world stopped turning? Can you explain why these two (apparently) logical assignment processes have been designed to realise different result-objects? NB The list cf tuple difference is 'legal' - at least in the sense that it is documented/expected behavior:- Python Reference Manual: 7.2. Assignment statements Assignment statements are used to (re)bind names to values and to modify attributes or items of mutable objects: ... An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right. ... A list of the remaining items in the iterable is then assigned to the starred target (the list can be empty). https://docs.python.org/3/reference/simple_stmts.html#assignment-statements Python Reference Manual: 6.3.4. Calls A call calls a callable object (e.g., a function) with a possibly empty series of arguments: ... If there are more positional arguments than there are formal parameter slots, a TypeError exception is raised, unless a formal parameter using the syntax *identifier is present; in this case, that formal parameter receives a tuple containing the excess positional arguments (or an empty tuple if there were no excess positional arguments). https://docs.python.org/dev/reference/expressions.html#calls -- Regards, =dn From miked at dewhirst.com.au Tue Jul 7 03:21:55 2020 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Tue, 07 Jul 2020 17:21:55 +1000 Subject: Questioning the effects of multiple assignment In-Reply-To: <5aa9d135-d110-f38a-4dab-874147b19e62@etelligence.info> Message-ID: <4B1DYM6cgpzpFJ7@mail.python.org> -------- Original message --------From: dn via Python-list Date: 7/7/20 16:04 (GMT+10:00) To: 'Python' Subject: Questioning the effects of multiple assignment TLDR; if you are a Python 'Master' then feel free to skim the first part (which you should know hands-down), until the excerpts from 'the manual' and from there I'll be interested in learning from you...Yesterday I asked a junior prog to expand an __init__() to accept either a series of (>1) scalars (as it does now), or to take similar values but presented as a tuple. He was a bit concerned that I didn't want to introduce a (separate) keyword-argument, until 'we' remembered starred-parameters. He then set about experimenting. Here's a dichotomy that surfaced as part of our 'play':-(my problem is: I can't (reasonably) answer his question...)If you read this code:NB The print-ing does not follow the input-sequence, because that's the point to be made... >>> def f( a, *b, c=0 ):Shouldn't that def be ...>>> def f(a, c=0, *b):???...???? print( a, type( a ) )...???? print( c, type( c ) )...???? print( b )... >>> f( 1, 'two', 3, 'four' )[I had to force "c" to become a keyword argument, but other than that, we'll be using these three parameters and four argument-values, again]Question 1: did you correctly predict the output?1 0 ('two', 3, 'four')Ahah, "c" went to default because there was no way to identify when the "*b" 'stopped' and "c" started - so all the values 'went' to become "b" (were all "consumed by"...).Why did I also print "b" differently?Building tension!Please read on, gentle reader...Let's make two small changes:- amend the last line of the function to be similar:...???? print( b, type( b ) )- make proper use of the function's API: >>> f( 1, 'two', 3, c='four' )Question 2: can you predict the output of "a"? Well duh!(same as before)1 Question 3: has your predicted output of "c" changed? Yes? Good!(Web.Refs below, explain; should you wish...)four Question 4: can you correctly predict the content of "b" and its type?('two', 3) That makes sense, doesn't it? The arguments were presented to the function as a tuple, and those not assigned to a scalar value ("a" and "c") were kept as a tuple when assigned to "b".Jolly good show, chaps!(which made my young(er) colleague very happy, because now he could see that by checking the length of the parameter, such would reveal if the arguments were being passed as scalars or as a tuple.Aside: however, it made me think how handy it would be if the newly-drafted PEP 622 -- Structural Pattern Matching were available today (proposed for v3.10, https://www.python.org/dev/peps/pep-0622/) because (YAGNI-aside) we could then more-easily empower the API to accept other/more collections!Why am I writing then?Because during the same conversations I was 'demonstrating'/training/playing with some code that is (apparently) very similar - and yet, it's not. Oops!Sticking with the same, toy-data, let's code: >>> a, *b, c = 1, 'two', 3, 'four' >>> a, type( a ) >>> c, type( c ) >>> b, type( b )Question 5: what do you expect "a" and "c" to deliver in this context?(1, )('four', )Happy so far?Question 6: (for maximum effect, re-read snippets from above, then) what do you expect from "b"?(['two', 3], )List? A list? What's this "list" stuff???When "b" was a parameter (above) it was assigned a tuple!Are you as shocked as I?Have you learned something?(will it ever be useful?)Has the world stopped turning?Can you explain why these two (apparently) logical assignment processes have been designed to realise different result-objects?NB The list cf tuple difference is 'legal' - at least in the sense that it is documented/expected behavior:-Python Reference Manual: 7.2. Assignment statementsAssignment statements are used to (re)bind names to values and to modify attributes or items of mutable objects:...An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right....A list of the remaining items in the iterable is then assigned to the starred target (the list can be empty).https://docs.python.org/3/reference/simple_stmts.html#assignment-statementsPython Reference Manual: 6.3.4. CallsA call calls a callable object (e.g., a function) with a possibly empty series of arguments:...If there are more positional arguments than there are formal parameter slots, a TypeError exception is raised, unless a formal parameter using the syntax *identifier is present; in this case, that formal parameter receives a tuple containing the excess positional arguments (or an empty tuple if there were no excess positional arguments).https://docs.python.org/dev/reference/expressions.html#calls-- Regards,=dn-- https://mail.python.org/mailman/listinfo/python-list From aeros167 at gmail.com Tue Jul 7 03:44:45 2020 From: aeros167 at gmail.com (Kyle Stanley) Date: Tue, 7 Jul 2020 03:44:45 -0400 Subject: Questioning the effects of multiple assignment In-Reply-To: <5aa9d135-d110-f38a-4dab-874147b19e62@etelligence.info> References: <5aa9d135-d110-f38a-4dab-874147b19e62@etelligence.info> Message-ID: > > Can you explain why these two (apparently) logical assignment processes > have been designed to realise different result-objects? The reason is because of the conventions chosen in PEP 3132, which implemented the feature in the first place. It was considered to return a tuple for the consistency w/ *args that you initially expected, but the author offered the following reasoning: > Make the starred target a tuple instead of a list. This would be consistent with a function's *args, but make further processing of the result harder. So, it was essentially a practicality > purity situation, where it was considered to be more useful to be able to easily transform the result rather than being consistent with *args. If it resulted in a tuple, it would be immutable; this IMO makes sense for *args, but not necessarily for * unpacking in assignments. The syntax is highly similar, but they are used for rather different purposes. That being said, I can certainly understand how the behavior is surprising at first. There's a bit more details in the mailing list discussion that started the PEP, see https://mail.python.org/pipermail/python-3000/2007-May/007300.html. On Tue, Jul 7, 2020 at 2:04 AM dn via Python-list wrote: > TLDR; if you are a Python 'Master' then feel free to skim the first part > (which you should know hands-down), until the excerpts from 'the manual' > and from there I'll be interested in learning from you... > > > Yesterday I asked a junior prog to expand an __init__() to accept either > a series of (>1) scalars (as it does now), or to take similar values but > presented as a tuple. He was a bit concerned that I didn't want to > introduce a (separate) keyword-argument, until 'we' remembered > starred-parameters. He then set about experimenting. Here's a dichotomy > that surfaced as part of our 'play':- > (my problem is: I can't (reasonably) answer his question...) > > > If you read this code: > NB The print-ing does not follow the input-sequence, because that's the > point to be made... > > >>> def f( a, *b, c=0 ): > ... print( a, type( a ) ) > ... print( c, type( c ) ) > ... print( b ) > ... > >>> f( 1, 'two', 3, 'four' ) > > [I had to force "c" to become a keyword argument, but other than that, > we'll be using these three parameters and four argument-values, again] > > > Question 1: did you correctly predict the output? > > 1 > 0 > ('two', 3, 'four') > > Ahah, "c" went to default because there was no way to identify when the > "*b" 'stopped' and "c" started - so all the values 'went' to become "b" > (were all "consumed by"...). > > Why did I also print "b" differently? > Building tension! > Please read on, gentle reader... > > > Let's make two small changes: > - amend the last line of the function to be similar: > ... print( b, type( b ) ) > - make proper use of the function's API: > >>> f( 1, 'two', 3, c='four' ) > > > Question 2: can you predict the output of "a"? Well duh! > (same as before) > > 1 > > > Question 3: has your predicted output of "c" changed? Yes? Good! > (Web.Refs below, explain; should you wish...) > > four > > > Question 4: can you correctly predict the content of "b" and its type? > > ('two', 3) > > That makes sense, doesn't it? The arguments were presented to the > function as a tuple, and those not assigned to a scalar value ("a" and > "c") were kept as a tuple when assigned to "b". > Jolly good show, chaps! > > (which made my young(er) colleague very happy, because now he could see > that by checking the length of the parameter, such would reveal if the > arguments were being passed as scalars or as a tuple. > > Aside: however, it made me think how handy it would be if the > newly-drafted PEP 622 -- Structural Pattern Matching were available > today (proposed for v3.10, https://www.python.org/dev/peps/pep-0622/) > because (YAGNI-aside) we could then more-easily empower the API to > accept other/more collections! > > > Why am I writing then? > > Because during the same conversations I was > 'demonstrating'/training/playing with some code that is (apparently) > very similar - and yet, it's not. Oops! > > > Sticking with the same, toy-data, let's code: > > >>> a, *b, c = 1, 'two', 3, 'four' > >>> a, type( a ) > >>> c, type( c ) > >>> b, type( b ) > > > Question 5: what do you expect "a" and "c" to deliver in this context? > > (1, ) > ('four', ) > > Happy so far? > > > Question 6: (for maximum effect, re-read snippets from above, then) what > do you expect from "b"? > > (['two', 3], ) > > List? A list? What's this "list" stuff??? > When "b" was a parameter (above) it was assigned a tuple! > > > Are you as shocked as I? > Have you learned something? > (will it ever be useful?) > Has the world stopped turning? > > > Can you explain why these two (apparently) logical assignment processes > have been designed to realise different result-objects? > > > NB The list cf tuple difference is 'legal' - at least in the sense that > it is documented/expected behavior:- > > Python Reference Manual: 7.2. Assignment statements > Assignment statements are used to (re)bind names to values and to modify > attributes or items of mutable objects: > ... > An assignment statement evaluates the expression list (remember that > this can be a single expression or a comma-separated list, the latter > yielding a tuple) and assigns the single resulting object to each of the > target lists, from left to right. > ... > A list of the remaining items in the iterable is then assigned to the > starred target (the list can be empty). > https://docs.python.org/3/reference/simple_stmts.html#assignment-statements > > > Python Reference Manual: 6.3.4. Calls > A call calls a callable object (e.g., a function) with a possibly empty > series of arguments: > ... > If there are more positional arguments than there are formal parameter > slots, a TypeError exception is raised, unless a formal parameter using > the syntax *identifier is present; in this case, that formal parameter > receives a tuple containing the excess positional arguments (or an empty > tuple if there were no excess positional arguments). > https://docs.python.org/dev/reference/expressions.html#calls > -- > Regards, > =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From a24061 at ducksburg.com Tue Jul 7 06:34:13 2020 From: a24061 at ducksburg.com (Adam Funk) Date: Tue, 07 Jul 2020 11:34:13 +0100 Subject: Bulletproof json.dump? References: Message-ID: <5mvdtgxc2s.ln2@news.ducksburg.com> On 2020-07-06, Adam Funk wrote: > On 2020-07-06, Chris Angelico wrote: >> On Mon, Jul 6, 2020 at 10:11 PM Jon Ribbens via Python-list >> wrote: >>> While I agree entirely with your point, there is however perhaps room >>> for a bit more helpfulness from the json module. There is no sensible >>> reason I can think of that it refuses to serialize sets, for example. >> >> Sets don't exist in JSON. I think that's a sensible reason. > > I don't agree. Tuples & lists don't exist separately in JSON, but > both are serializable (to the same thing). Non-string keys aren't > allowed in JSON, but it silently converts numbers to strings instead > of barfing. Typically, I've been using sets to deduplicate values as > I go along, & having to walk through the whole object changing them to > lists before serialization strikes me as the kind of pointless labor > that I expect when I'm using Java. ;-) Here's another "I'd expect to have to deal with this sort of thing in Java" example I just ran into: >>> r = requests.head(url, allow_redirects=True) >>> print(json.dumps(r.headers, indent=2)) ... TypeError: Object of type CaseInsensitiveDict is not JSON serializable >>> print(json.dumps(dict(r.headers), indent=2)) { "Content-Type": "text/html; charset=utf-8", "Server": "openresty", ... } -- I'm after rebellion --- I'll settle for lies. From frank at chagford.com Tue Jul 7 08:26:25 2020 From: frank at chagford.com (Frank Millman) Date: Tue, 7 Jul 2020 14:26:25 +0200 Subject: Access last element after iteration Message-ID: Hi all After iterating over a sequence, the final element is still accessible. In this case, the variable 'i' still references the integer 4. Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> >>> for i in range(5): ... print(i) ... 0 1 2 3 4 >>> print(i) 4 >>> Is this guaranteed in Python, or should it not be relied on? If the latter, and you wanted to do something additional using the last element, I assume that this would be the way to do it - >>> for i in range(5): ... print(i) ... j = i ... 0 1 2 3 4 >>> print(j) 4 >>> Alternatively, this also works, but is this one guaranteed? >>> for i in range(5): ... print(i) ... else: ... print() ... print(i) ... 0 1 2 3 4 4 >>> Frank Millman From jon+usenet at unequivocal.eu Tue Jul 7 08:37:34 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 7 Jul 2020 12:37:34 -0000 (UTC) Subject: Access last element after iteration References: Message-ID: On 2020-07-07, Frank Millman wrote: > After iterating over a sequence, the final element is still accessible. > In this case, the variable 'i' still references the integer 4. ... > Is this guaranteed in Python, or should it not be relied on? It is guaranteed, *except* if the sequence is empty and therefore the loop never executes at all, the variable will not have been assigned to and therefore may not exist. From rosuav at gmail.com Tue Jul 7 08:45:10 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jul 2020 22:45:10 +1000 Subject: Access last element after iteration In-Reply-To: References: Message-ID: On Tue, Jul 7, 2020 at 10:28 PM Frank Millman wrote: > > Hi all > > After iterating over a sequence, the final element is still accessible. > In this case, the variable 'i' still references the integer 4. > Yes, it's guaranteed. It isn't often useful; but the variant where there's a "break" in the loop most certainly is. If you hit the break, the iteration variable will still have whatever it had at the end. This is a great use of 'else' (arguably the primary use of it). You do something like: for thing in iterable: if want(thing): break else: thing = None If the iterable is empty, you go to the else. If you don't find the thing you want, you go to the else. But if you find it and break, thing has the thing you wanted. ChrisA From sirosen at uchicago.edu Tue Jul 7 12:43:36 2020 From: sirosen at uchicago.edu (Stephen Rosen) Date: Tue, 7 Jul 2020 12:43:36 -0400 Subject: Bulletproof json.dump? In-Reply-To: <5mvdtgxc2s.ln2@news.ducksburg.com> References: <5mvdtgxc2s.ln2@news.ducksburg.com> Message-ID: On Mon, Jul 6, 2020 at 6:37 AM Adam Funk wrote: > Is there a "bulletproof" version of json.dump somewhere that will > convert bytes to str, any other iterables to list, etc., so you can > just get your data into a file & keep working? > Is the data only being read by python programs? If so, consider using pickle: https://docs.python.org/3/library/pickle.html Unlike json dumping, the goal of pickle is to represent objects as exactly as possible and *not* to be interoperable with other languages. If you're using json to pass data between python and some other language, you don't want to silently convert bytes to strings. If you have a bytestring of utf-8 data, you want to utf-8 decode it before passing it to json.dumps. Likewise, if you have latin-1 data, you want to latin-1 decode it. There is no universal and correct bytes-to-string conversion. On Mon, Jul 6, 2020 at 9:45 AM Chris Angelico wrote: > Maybe what we need is to fork out the default JSON encoder into two, > or have a "strict=True" or "strict=False" flag. In non-strict mode, > round-tripping is not guaranteed, and various types will be folded to > each other - mainly, many built-in and stdlib types will be > represented in strings. In strict mode, compliance with the RFC is > ensured (so ValueError will be raised on inf/nan), and everything > should round-trip safely. > Wouldn't it be reasonable to represent this as an encoder which is provided by `json`? i.e. from json import dumps, UnsafeJSONEncoder ... json.dumps(foo, cls=UnsafeJSONEncoder) Emphasizing the "Unsafe" part of this and introducing people to the idea of setting an encoder also seems nice. On Mon, Jul 6, 2020 at 9:12 AM Chris Angelico wrote: > On Mon, Jul 6, 2020 at 11:06 PM Jon Ribbens via Python-list > wrote: > > > The 'json' module already fails to provide round-trip functionality: > > > > >>> for data in ({True: 1}, {1: 2}, (1, 2)): > > ... if json.loads(json.dumps(data)) != data: > > ... print('oops', data, json.loads(json.dumps(data))) > > ... > > oops {True: 1} {'true': 1} > > oops {1: 2} {'1': 2} > > oops (1, 2) [1, 2] > > There's a fundamental limitation of JSON in that it requires string > keys, so this is an obvious transformation. I suppose you could call > that one a bug too, but it's very useful and not too dangerous. (And > then there's the tuple-to-list transformation, which I think probably > shouldn't happen, although I don't think that's likely to cause issues > either.) Ideally, all of these bits of support for non-JSON types should be opt-in, not opt-out. But it's not worth making a breaking change to the stdlib over this. Especially for new programmers, the notion that deserialize(serialize(x)) != x just seems like a recipe for subtle bugs. You're never guaranteed that the deserialized object will match the original, but shouldn't one of the goals of a de/serialization library be to get it as close as is reasonable? I've seen people do things which boil down to json.loads(x)["some_id"] == UUID(...) plenty of times. It's obviously wrong and the fix is easy, but isn't making the default json encoder less strict just encouraging this type of bug? Comparing JSON data against non-JSON types is part of the same category of errors: conflating JSON with dictionaries. It's very easy for people to make this mistake, especially since JSON syntax is a subset of python dict syntax, so I don't think `json.dumps` should be encouraging it. On Tue, Jul 7, 2020 at 6:52 AM Adam Funk wrote: > Here's another "I'd expect to have to deal with this sort of thing in > Java" example I just ran into: > > >>> r = requests.head(url, allow_redirects=True) > >>> print(json.dumps(r.headers, indent=2)) > ... > TypeError: Object of type CaseInsensitiveDict is not JSON serializable > >>> print(json.dumps(dict(r.headers), indent=2)) > { > "Content-Type": "text/html; charset=utf-8", > "Server": "openresty", > ... > } > Why should the JSON encoder know about an arbitrary dict-like type? It might implement Mapping, but there's no way for json.dumps to know that in the general case (because not everything which implements Mapping actually inherits from the Mapping ABC). Converting it to a type which json.dumps understands is a reasonable constraint. Also, wouldn't it be fair, if your object is "case insensitive" to serialize it as { "CONTENT-TYPE": ... } or { "content-type": ... } or ... ? `r.headers["content-type"]` presumably gets a hit. `json.loads(json.dumps(dict(r.headers)))["content-type"]` will get a KeyError. This seems very much out of scope for the json package because it's not clear what it's supposed to do with this type. Libraries should ask users to specify what they mean and not make potentially harmful assumptions. Best, -Stephen From jpic at yourlabs.org Tue Jul 7 13:00:52 2020 From: jpic at yourlabs.org (J. Pic) Date: Tue, 7 Jul 2020 19:00:52 +0200 Subject: Bulletproof json.dump? In-Reply-To: <5mvdtgxc2s.ln2@news.ducksburg.com> References: <5mvdtgxc2s.ln2@news.ducksburg.com> Message-ID: Try jsonlight.dumps it'll just work. Le mar. 7 juil. 2020 ? 12:53, Adam Funk a ?crit : > On 2020-07-06, Adam Funk wrote: > > > On 2020-07-06, Chris Angelico wrote: > >> On Mon, Jul 6, 2020 at 10:11 PM Jon Ribbens via Python-list > >> wrote: > > >>> While I agree entirely with your point, there is however perhaps room > >>> for a bit more helpfulness from the json module. There is no sensible > >>> reason I can think of that it refuses to serialize sets, for example. > >> > >> Sets don't exist in JSON. I think that's a sensible reason. > > > > I don't agree. Tuples & lists don't exist separately in JSON, but > > both are serializable (to the same thing). Non-string keys aren't > > allowed in JSON, but it silently converts numbers to strings instead > > of barfing. Typically, I've been using sets to deduplicate values as > > I go along, & having to walk through the whole object changing them to > > lists before serialization strikes me as the kind of pointless labor > > that I expect when I'm using Java. ;-) > > Here's another "I'd expect to have to deal with this sort of thing in > Java" example I just ran into: > > > >>> r = requests.head(url, allow_redirects=True) > >>> print(json.dumps(r.headers, indent=2)) > ... > TypeError: Object of type CaseInsensitiveDict is not JSON serializable > >>> print(json.dumps(dict(r.headers), indent=2)) > { > "Content-Type": "text/html; charset=utf-8", > "Server": "openresty", > ... > } > > > -- > I'm after rebellion --- I'll settle for lies. > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Tue Jul 7 17:28:13 2020 From: PythonList at DancesWithMice.info (dn) Date: Wed, 8 Jul 2020 09:28:13 +1200 Subject: Access last element after iteration In-Reply-To: References: Message-ID: <9cf79e58-24ca-078b-f6b9-8a5571f6f96d@DancesWithMice.info> On 8/07/20 12:45 AM, Chris Angelico wrote: > On Tue, Jul 7, 2020 at 10:28 PM Frank Millman wrote: >> >> Hi all >> >> After iterating over a sequence, the final element is still accessible. >> In this case, the variable 'i' still references the integer 4. >> > > Yes, it's guaranteed. It isn't often useful; but the variant where > there's a "break" in the loop most certainly is. If you hit the break, > the iteration variable will still have whatever it had at the end. > > This is a great use of 'else' (arguably the primary use of it). You do > something like: > > for thing in iterable: > if want(thing): break > else: > thing = None > > If the iterable is empty, you go to the else. If you don't find the > thing you want, you go to the else. But if you find it and break, > thing has the thing you wanted. It wasn't clear if the OP was interested in the value of the pertinent index or that of the indexed element from the iterable/sequence. However, the techniques apply - adding enumerate() if the source is a collection (for example). Am impressed to see a constructive use of the else: clause! It is a most pythonic construction used in that mode. OTOH/IMHO, one of the harder philosophical lessons to learn, is that (in Python at least) an exception is not necessarily an error - as in 'catastrophe'! Accordingly, there are many examples where 'success' in such a search-pattern might be terminated with raise. The 'calling routine'/outer-block would then be able to utilise a try...except...else...finally structure - arguably both 'richer' and better-understood by 'the average pythonista' than for...else/while...else (per previous discussions 'here') Your thoughts? Apologies to OP, if am 'hi-jacking' original post. -- Regards =dn From PythonList at DancesWithMice.info Tue Jul 7 19:36:11 2020 From: PythonList at DancesWithMice.info (dn) Date: Wed, 8 Jul 2020 11:36:11 +1200 Subject: Questioning the effects of multiple assignment In-Reply-To: <20200707072211.B57693D81@mail.rangi.cloud> References: <20200707072211.B57693D81@mail.rangi.cloud> Message-ID: On 7/07/20 7:21 PM, Mike Dewhirst wrote: > -------- Original message -------- For comparison, here's the original form:- >>> def f( a, *b, c=0 ): ... print( a, type( a ) ) ... print( c, type( c ) ) ... print( b ) ... >>> f( 1, 'two', 3, 'four' ) 1 0 ('two', 3, 'four') > Shouldn't that def be ... > > >>> def f(a, c=0, *b): > ??? It might appear that way, but in v3.7*, they are not:- >>> def f(a, c=0, *b): ... print( a, type( a ) ) ... print( c, type( c ) ) ... print( b, type( b ) ) ... >>> f( 1, 'two', 3, 'four' ) 1 two ##### (3, 'four') ##### and even worse when we attempt to specify "c" as a keyword argument: >>> f( 1, 'two', 3, c='four' ) Traceback (most recent call last): File "", line 1, in TypeError: f() got multiple values for argument 'c' >>> f( 1, c='four', 'two', 3 ) File "", line 1 SyntaxError: positional argument follows keyword argument >>> f( 1, 'four', 'two', 3 ) 1 four ('two', 3) Please remember also, that the idea of interposing a keyword-argument was by way of illustration. The original spec was to expand the API to accept either a series of scalars or equivalent values as a tuple, without (also) changing the API to require the new/tuple option be implemented as a keyword-argument. However, to answer the question: the method of assigning the arguments' values to parameters is to start from the left, but upon reaching a *identifier to re-start by allocating from the right. This will leave zero or more values 'in the middle', to be tuple-ified as the *identifier. Otherwise, if the allocation were l-to-r and "greedy", there would never be any values assigned to 'later' parameters! For your reading pleasure:- > Python Reference Manual: 6.3.4. Calls > A call calls a callable object (e.g., a function) with a possibly empty > series of arguments: > ... > If there are more positional arguments than there are formal parameter > slots, a TypeError exception is raised, unless a formal parameter using > the syntax *identifier is present; in this case, that formal parameter > receives a tuple containing the excess positional arguments (or an empty > tuple if there were no excess positional arguments). > https://docs.python.org/dev/reference/expressions.html#calls * I was remiss in not stating that this project is (?still) running with Python v3.7. Apologies! (it was established some time ago, and evidently the client has not seen fit to even consider upgrading as part of any sprint, to-date. Note to self...) So, please be aware of: https://docs.python.org/3/whatsnew/3.8.html#positional-only-parameters https://www.python.org/dev/peps/pep-0570/ If you are running a more recent release, perhaps you might like to re-run the snippets, experiment, and document any contrary findings? -- Regards =dn From PythonList at DancesWithMice.info Tue Jul 7 20:26:06 2020 From: PythonList at DancesWithMice.info (dn) Date: Wed, 8 Jul 2020 12:26:06 +1200 Subject: Questioning the effects of multiple assignment In-Reply-To: References: <5aa9d135-d110-f38a-4dab-874147b19e62@etelligence.info> Message-ID: <55314849-ed22-26ed-b500-b6f3054a70f3@DancesWithMice.info> On 7/07/20 7:44 PM, Kyle Stanley wrote: > Can you explain why these two (apparently) logical assignment processes > have been designed to realise different result-objects? > > > The reason is because of the conventions chosen in PEP 3132, which > implemented the feature in the first place. It was considered to return > a tuple for the consistency w/ *args that you initially expected, but > the author offered the following reasoning: > > > Make the starred target a tuple instead of a list. This would be > consistent with a function's *args, but make further processing of the > result harder. > > So, it was essentially a practicality > purity situation, where it was > considered to be more useful to be able to easily transform the result > rather than being consistent with *args. If it resulted in a tuple, it > would be immutable; this IMO makes sense for *args, but not necessarily > for * unpacking in assignments. The syntax is highly similar, but they > are used for rather different purposes. That being said, I can certainly > understand how the behavior is surprising at first. > > There's a bit more details in the mailing list discussion that started > the PEP, see > https://mail.python.org/pipermail/python-3000/2007-May/007300.html. Thank you - I had failed to find that discussion, but it and the explanation above, make perfect sense. You can color me hobgoblin for expecting ?'consistency'! - and whilst I'm liberally (mis-)quoting: I'm not going to argue with the better minds of the giants, upon whose shoulders I stand... Continuing on, but instead of considering the handling of argument/parameters to be 'authoritative' (which we were, from the perspective of 'consistency'); perhaps consider the assignment decision as "authoritative" and consider if the calling-behavior should be made consistent:- One of the features of Python's sub-routines, which I enjoy, is summarised in two ways: 1 the many books on 'programming style' (for other languages) which talk about a function's signature needing to separate 'input-parameters', from 'output-parameters' to enhance readability. - in Python we have parameters (let's say: only for input), neatly separated from 'output' values which don't get-a-mention until the return statement (see also "typing" - although the "return" might be considerably separated from the "->"). Python:1, those others:nil! 2 a perennial-question is: "are Python's function-arguments passed by-reference, passed by-value, or what?" - in Python we pass by assignment and 'the rules' vary according to mutability. (in themselves a frequent 'gotcha' for newcomers, but once understood, make perfect sense and realise powerful opportunities) Python:2, those others:nil - still! (IMHO) A matter of style, which I like to follow [is it TDD's influence? - or does it actually come-from reading about DBC (Design by Contract*)?] is the injunction that one *not* vary the value of a parameter inside a method/function. (useful in 'open-box testing' to check both the API and that input+process agrees with the expected and actual output, but irrelevant for 'closed-box testing') This also has the effect of side-stepping any unintended issues caused by changing the values of mutable parameters! (although sometimes it's a equally-good idea to do-so!) Accordingly, binding argument-values to mutable parameters (instead of an immutable tuple) might cause problems/"side-effects", were those parameters' values changed within the function! Making sense to you? -- Regards =dn From msuginoo at reversalpoint.com Tue Jul 7 20:58:02 2020 From: msuginoo at reversalpoint.com (Michio Suginoo) Date: Tue, 7 Jul 2020 21:58:02 -0300 Subject: Installing Basemap in Jupyter Notebook Message-ID: Hi I have a trouble in installing basemap in my local Jupyter Notebook. I used the code below. But it did not work. !conda install -c conda-forge basemap==1.3.0 matplotlib==2.2.2 -y How can I install basemap in my Jupyter Notebook? Thanks Best Regards Mich From aeros167 at gmail.com Tue Jul 7 22:40:25 2020 From: aeros167 at gmail.com (Kyle Stanley) Date: Tue, 7 Jul 2020 22:40:25 -0400 Subject: Questioning the effects of multiple assignment In-Reply-To: <55314849-ed22-26ed-b500-b6f3054a70f3@DancesWithMice.info> References: <5aa9d135-d110-f38a-4dab-874147b19e62@etelligence.info> <55314849-ed22-26ed-b500-b6f3054a70f3@DancesWithMice.info> Message-ID: > > A matter of style, which I like to follow [is it TDD's influence? - or > does it actually come-from reading about DBC (Design by Contract*)?] is > the injunction that one *not* vary the value of a parameter inside a > method/function. > (useful in 'open-box testing' to check both the API and that > input+process agrees with the expected and actual output, but irrelevant > for 'closed-box testing') > This also has the effect of side-stepping any unintended issues caused > by changing the values of mutable parameters! > (although sometimes it's a equally-good idea to do-so!) > > Accordingly, binding argument-values to mutable parameters (instead of > an immutable tuple) might cause problems/"side-effects", were those parameters' values changed within the function! > Making sense to you? > I think I can see where you're going with this, and it makes me wonder if it might be a reasonable idea to have an explicit syntax to be able to change the behavior to store those values in a tuple instead of a list. The programming style of making use of immutability as much as possible to avoid side effects is quite common, and becoming increasingly so from what I've seen of recent programming trends. If something along those lines is something you'd be interested in and have some real-world examples of where it could specifically be useful (I currently don't), it might be worth pursuing further on python-ideas. Due to the backwards compatibility issues, I don't think we can realistically make the default change from a list to a tuple, but that doesn't mean having a means to explicitly specify that you want the immutability is unreasonable. You'd also likely have to argue against why being able to do it during assignment is advantageous compared to simply doing it immediately after the initial unpacking assignment. E.g. :: >>> a, *b, c = 1, 'two', 3, 'four' >>> b = tuple(b) (I'd like to particularly emphasize the importance of having some compelling real-world examples in the proposal if you decide to pursue this, as otherwise it would likely be dismissed as YAGNI.) On Tue, Jul 7, 2020 at 8:26 PM dn via Python-list wrote: > On 7/07/20 7:44 PM, Kyle Stanley wrote: > > Can you explain why these two (apparently) logical assignment > processes > > have been designed to realise different result-objects? > > > > > > The reason is because of the conventions chosen in PEP 3132, which > > implemented the feature in the first place. It was considered to return > > a tuple for the consistency w/ *args that you initially expected, but > > the author offered the following reasoning: > > > > > Make the starred target a tuple instead of a list. This would be > > consistent with a function's *args, but make further processing of the > > result harder. > > > > So, it was essentially a practicality > purity situation, where it was > > considered to be more useful to be able to easily transform the result > > rather than being consistent with *args. If it resulted in a tuple, it > > would be immutable; this IMO makes sense for *args, but not necessarily > > for * unpacking in assignments. The syntax is highly similar, but they > > are used for rather different purposes. That being said, I can certainly > > understand how the behavior is surprising at first. > > > > There's a bit more details in the mailing list discussion that started > > the PEP, see > > https://mail.python.org/pipermail/python-3000/2007-May/007300.html. > > > Thank you - I had failed to find that discussion, but it and the > explanation above, make perfect sense. > > > You can color me hobgoblin for expecting ?'consistency'! - and whilst > I'm liberally (mis-)quoting: I'm not going to argue with the better > minds of the giants, upon whose shoulders I stand... > > > Continuing on, but instead of considering the handling of > argument/parameters to be 'authoritative' (which we were, from the > perspective of 'consistency'); perhaps consider the assignment decision > as "authoritative" and consider if the calling-behavior should be made > consistent:- > > > One of the features of Python's sub-routines, which I enjoy, is > summarised in two ways: > > 1 the many books on 'programming style' (for other languages) which talk > about a function's signature needing to separate 'input-parameters', > from 'output-parameters' to enhance readability. > - in Python we have parameters (let's say: only for input), neatly > separated from 'output' values which don't get-a-mention until the > return statement > (see also "typing" - although the "return" might be considerably > separated from the "->"). > Python:1, those others:nil! > > 2 a perennial-question is: "are Python's function-arguments passed > by-reference, passed by-value, or what?" > - in Python we pass by assignment and 'the rules' vary according to > mutability. > (in themselves a frequent 'gotcha' for newcomers, but once understood, > make perfect sense and realise powerful opportunities) > Python:2, those others:nil - still! > (IMHO) > > A matter of style, which I like to follow [is it TDD's influence? - or > does it actually come-from reading about DBC (Design by Contract*)?] is > the injunction that one *not* vary the value of a parameter inside a > method/function. > (useful in 'open-box testing' to check both the API and that > input+process agrees with the expected and actual output, but irrelevant > for 'closed-box testing') > This also has the effect of side-stepping any unintended issues caused > by changing the values of mutable parameters! > (although sometimes it's a equally-good idea to do-so!) > > Accordingly, binding argument-values to mutable parameters (instead of > an immutable tuple) might cause problems/"side-effects", were those > parameters' values changed within the function! > > > Making sense to you? > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From hjp-python at hjp.at Wed Jul 8 06:19:52 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 8 Jul 2020 12:19:52 +0200 Subject: Questioning the effects of multiple assignment In-Reply-To: <55314849-ed22-26ed-b500-b6f3054a70f3@DancesWithMice.info> References: <5aa9d135-d110-f38a-4dab-874147b19e62@etelligence.info> <55314849-ed22-26ed-b500-b6f3054a70f3@DancesWithMice.info> Message-ID: <20200708101952.GA596@hjp.at> On 2020-07-08 12:26:06 +1200, dn via Python-list wrote: > A matter of style, which I like to follow [is it TDD's influence? - or > does it actually come-from reading about DBC (Design by Contract*)?] I think Design by Contract only affects the interfaces (parameters, return values and side effects), not internal operations of a component. > is the injunction that one *not* vary the value of a parameter inside > a method/function. > (useful in 'open-box testing' to check both the API and that input+process > agrees with the expected and actual output, but irrelevant for 'closed-box > testing') > This also has the effect of side-stepping any unintended issues caused by > changing the values of mutable parameters! > (although sometimes it's a equally-good idea to do-so!) > > Accordingly, binding argument-values to mutable parameters (instead of > an immutable tuple) might cause problems/"side-effects", were those > parameters' values changed within the function! I don't think so. The tuple/list is local to the function and never visible outside of it. So you can change it within the function without affecting the caller: #!/usr/bin/python3 def f(*a): # a = list(a) # simulate star-as-list a.append(2) v = { "old": 1} f(v) print(v) should print ?{'old': 1}?. OTOH, using a tuple doesn't prevent the function from mutating mutable arguments: #!/usr/bin/python3 def f(*a): a[0]["new"] = 2 v = { "old": 1} f(v) print(v) prints ?{'old': 1, 'new': 2}?. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From o1bigtenor at gmail.com Wed Jul 8 07:11:38 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Wed, 8 Jul 2020 06:11:38 -0500 Subject: Questioning the effects of multiple assignment In-Reply-To: <4B1DYM6cgpzpFJ7@mail.python.org> References: <5aa9d135-d110-f38a-4dab-874147b19e62@etelligence.info> <4B1DYM6cgpzpFJ7@mail.python.org> Message-ID: On Tue, Jul 7, 2020 at 2:30 AM Mike Dewhirst wrote: > > -------- Original message --------From: dn via Python-list < > python-list at python.org> Date: 7/7/20 16:04 (GMT+10:00) To: 'Python' < > python-list at python.org> Subject: Questioning the effects of multiple > assignment TLDR; if you are a Python 'Master' then feel free to skim the > first part (which you should know hands-down), until the excerpts from 'the > manual' and from there I'll be interested in learning from you...Yesterday > I asked a junior prog to expand an __init__() to accept either a series of > (>1) scalars (as it does now), or to take similar values but presented as a > tuple. He was a bit concerned that I didn't want to introduce a (separate) > keyword-argument, until 'we' remembered starred-parameters. He then set > about experimenting. Here's a dichotomy that surfaced as part of our > 'play':-(my problem is: I can't (reasonably) answer his question...)If you > read this code:NB The print-ing does not follow the input-sequence, because > that's the point to be made... >>> def f( a, *b, c=0 ):Shouldn't that def > be ...>>> def f(a, c=0, *b):???... print( a, type( a ) )... print( > c, type( c ) )... print( b )... >>> f( 1, 'two', 3, 'four' )[I had to > force "c" to become a keyword argument, but other than that, we'll be using > these three parameters and four argument-values, again]Question 1: did you > correctly predict the output?1 0 ('two', 3, > 'four')Ahah, "c" went to default because there was no way to identify when > the "*b" 'stopped' and "c" started - so all the values 'went' to become "b" > (were all "consumed by"...).Why did I also print "b" differently?Building > tension!Please read on, gentle reader...Let's make two small changes:- > amend the last line of the function to be similar:... print( b, type( b > ) )- make proper use of the function's API: >>> f( 1, 'two', 3, c='four' > )Question 2: can you predict the output of "a"? Well duh!(same as before)1 > Question 3: has your predicted output of "c" changed? Yes? > Good!(Web.Refs below, explain; should you wish...)four 'str'>Question 4: can you correctly predict the content of "b" and its > type?('two', 3) That makes sense, doesn't it? The arguments > were presented to the function as a tuple, and those not assigned to a > scalar value ("a" and "c") were kept as a tuple when assigned to "b".Jolly > good show, chaps!(which made my young(er) colleague very happy, because now > he could see that by checking the length of the parameter, such would > reveal if the arguments were being passed as scalars or as a tuple.Aside: > however, it made me think how handy it would be if the newly-drafted PEP > 622 -- Structural Pattern Matching were available today (proposed for > v3.10, https://www.python.org/dev/peps/pep-0622/) because (YAGNI-aside) > we could then more-easily empower the API to accept other/more > collections!Why am I writing then?Because during the same conversations I > was 'demonstrating'/training/playing with some code that is (apparently) > very similar - and yet, it's not. Oops!Sticking with the same, toy-data, > let's code: >>> a, *b, c = 1, 'two', 3, 'four' >>> a, type( a ) >>> c, > type( c ) >>> b, type( b )Question 5: what do you expect "a" and "c" to > deliver in this context?(1, )('four', )Happy so > far?Question 6: (for maximum effect, re-read snippets from above, then) > what do you expect from "b"?(['two', 3], )List? A list? > What's this "list" stuff???When "b" was a parameter (above) it was assigned > a tuple!Are you as shocked as I?Have you learned something?(will it ever be > useful?)Has the world stopped turning?Can you explain why these two > (apparently) logical assignment processes have been designed to realise > different result-objects?NB The list cf tuple difference is 'legal' - at > least in the sense that it is documented/expected behavior:-Python > Reference Manual: 7.2. Assignment statementsAssignment statements are used > to (re)bind names to values and to modify attributes or items of mutable > objects:...An assignment statement evaluates the expression list (remember > that this can be a single expression or a comma-separated list, the latter > yielding a tuple) and assigns the single resulting object to each of the > target lists, from left to right....A list of the remaining items in the > iterable is then assigned to the starred target (the list can be empty). > https://docs.python.org/3/reference/simple_stmts.html#assignment-statementsPython > Reference Manual: 6.3.4. CallsA call calls a callable object (e.g., a > function) with a possibly empty series of arguments:...If there are more > positional arguments than there are formal parameter slots, a TypeError > exception is raised, unless a formal parameter using the syntax *identifier > is present; in this case, that formal parameter receives a tuple containing > the excess positional arguments (or an empty tuple if there were no excess > positional arguments). > https://docs.python.org/dev/reference/expressions.html#calls-- > Regards,=dn-- https://mail.python.org/mailman/listinfo/python-list > -- > Dunno about the rest of the list but I'm finding this message incredibly hard to read. Please sir - - - - would you please break up your message into at least sentences? Regards From artis.paintre at gmail.com Wed Jul 8 16:11:55 2020 From: artis.paintre at gmail.com (artis.paintre at gmail.com) Date: Wed, 8 Jul 2020 13:11:55 -0700 (PDT) Subject: execution timing of the method QWidget.show() Message-ID: <3e4d8633-6f5c-434d-971a-602330a518e1o@googlegroups.com> I might be wrong but since I have not found anygroup newsgroup dedicated to PyQt5. My small program is expected to show a window GUI for 4 seconds before changing it, so I naively coded: "... ... # codes to set up the GUI ... F0.show() # F0 being a QMainWindow object time.sleep(4) ... # codes to change the GUI set up ... F0.update() " What happens: The a blank window is displayed, freezes for 4 seconds then second set up is displayed, the original set up is not displayed. Why is not the original set up displayed? Obviously, if I remove the codes for the second set up, and the "time.sleep(4)" instruction, the original set up is displayed immediatly after I launch the execution. From python at mrabarnett.plus.com Wed Jul 8 16:50:11 2020 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 8 Jul 2020 21:50:11 +0100 Subject: execution timing of the method QWidget.show() In-Reply-To: <3e4d8633-6f5c-434d-971a-602330a518e1o@googlegroups.com> References: <3e4d8633-6f5c-434d-971a-602330a518e1o@googlegroups.com> Message-ID: <160024a0-700e-97fd-0d14-806aa0482439@mrabarnett.plus.com> On 2020-07-08 21:11, artis.paintre at gmail.com wrote: > I might be wrong but since I have not found anygroup newsgroup dedicated to PyQt5. > > My small program is expected to show a window GUI for 4 seconds before changing it, so I naively coded: > > "... > ... > # codes to set up the GUI > ... > F0.show() # F0 being a QMainWindow object > time.sleep(4) > ... > # codes to change the GUI set up > ... > F0.update() > > " > > What happens: The a blank window is displayed, freezes for 4 seconds then second set up is displayed, the original set up is not displayed. > > Why is not the original set up displayed? > > Obviously, if I remove the codes for the second set up, and the "time.sleep(4)" instruction, the original set up is displayed immediatly after I launch the execution. > If you tell the program to sleep, or your code is busy processing, then the GUI won't be unresponsive. A GUI is based on events. Something happens, e.g. a button is pressed, a handler in your code is called, it does something, and then it passes control back to the GUI code to update the display and wait for the next event. Basically, your code needs to set up the GUI, set some kind timer (I'm not familiar with Qt), and return control to Qt. When the timer expires, your code will be called, and then you can change the display, and return control to Qt again. From PythonList at DancesWithMice.info Wed Jul 8 16:50:09 2020 From: PythonList at DancesWithMice.info (dn) Date: Thu, 9 Jul 2020 08:50:09 +1200 Subject: Questioning the effects of multiple assignment In-Reply-To: References: <5aa9d135-d110-f38a-4dab-874147b19e62@etelligence.info> <55314849-ed22-26ed-b500-b6f3054a70f3@DancesWithMice.info> Message-ID: <8c18b828-4d07-9c94-27b6-ed54d5edd7c0@DancesWithMice.info> On 8/07/20 2:40 PM, Kyle Stanley wrote: > A matter of style, which I like to follow [is it TDD's influence? - or > does it actually come-from reading about DBC (Design by Contract*)?] is > the injunction that one *not* vary the value of a parameter inside a > method/function. > (useful in 'open-box testing' to check both the API and that > input+process agrees with the expected and actual output, but > irrelevant > for 'closed-box testing') > This also has the effect of side-stepping any unintended issues caused > by changing the values of mutable parameters! > (although sometimes it's a equally-good idea to do-so!) > > Accordingly, binding argument-values to mutable parameters (instead of > an immutable tuple) might cause problems/"side-effects", were those > parameters' values changed within the function! > > I think I can see where you're going with this, and it makes me wonder > if it might be a reasonable idea to have an explicit syntax to be able > to change the behavior to store those values in a tuple instead of a > list. The programming style of making use of immutability as much as > possible to avoid side effects is quite common, and becoming > increasingly so from what I've seen of recent programming trends. > > If something along those lines is something you'd be interested in and > have some real-world examples of where it could specifically be useful > (I currently don't), it might be worth pursuing further on python-ideas. Thanks for this. Nor can I imagine a strong reason to vary the existing implementation, and have no real-world example to offer which might drive such motivation. Our surprise was an apparent lack of consistency. However, the explanation makes good sense (IMHO - now that it is properly informed). As you said, practicality trumps consistency. So, the two situations each have their own rule - and Python is better understood! The value of asking, "why?"! Contrary to many, I enjoy it when someone pushes me into a 'corner' that I can't explain - such represents both a challenge and learning opportunity, and probably useful that the Junior Programmer-concerned should appreciate that no-one knows 'everything'. (hopefully, others 'playing along at home' using the summary of our REPL-experimentation, have also learned - without first feeling as flummoxed, as we were...) -- Regards =dn From PythonList at DancesWithMice.info Wed Jul 8 16:56:42 2020 From: PythonList at DancesWithMice.info (dn) Date: Thu, 9 Jul 2020 08:56:42 +1200 Subject: Questioning the effects of multiple assignment In-Reply-To: References: <5aa9d135-d110-f38a-4dab-874147b19e62@etelligence.info> <4B1DYM6cgpzpFJ7@mail.python.org> Message-ID: On 8/07/20 11:11 PM, o1bigtenor wrote: > On Tue, Jul 7, 2020 at 2:30 AM Mike Dewhirst > wrote: > -------- Original message --------From: dn via Python-list > > Date: > 7/7/20? 16:04? (GMT+10:00) To: 'Python' > Subject: Questioning the effects of > multiple assignment TLDR; if you are a Python 'Master' then feel > free to skim the first part (which you should know hands-down), ... > Dunno about the rest of the list but I'm finding this message incredibly > hard to read. > > Please sir - - - - would you please break up your message into at least > sentences? That is a terrible mess indeed! This may be a local problem. The original (as reflected by the list-server), and each reply since, has been properly-formatted - at least when viewed in Thunderbird email-client. All due apologies. If you (any colleague) are interested in the (apparent) conundrum, I will be happy to format a text file copy and attach it to a personal message... -- Regards =dn From PythonList at DancesWithMice.info Wed Jul 8 18:37:33 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 9 Jul 2020 10:37:33 +1200 Subject: Questioning the effects of multiple assignment In-Reply-To: <20200708101952.GA596@hjp.at> References: <5aa9d135-d110-f38a-4dab-874147b19e62@etelligence.info> <55314849-ed22-26ed-b500-b6f3054a70f3@DancesWithMice.info> <20200708101952.GA596@hjp.at> Message-ID: <1b6f8383-c177-684c-384d-b5577c7827e6@DancesWithMice.info> On 8/07/20 10:19 PM, Peter J. Holzer wrote: > On 2020-07-08 12:26:06 +1200, dn via Python-list wrote: > OTOH, using a tuple doesn't prevent the function from mutating mutable > arguments: > > #!/usr/bin/python3 > def f(*a): > a[0]["new"] = 2 > > v = { "old": 1} > f(v) > print(v) > > prints ?{'old': 1, 'new': 2}?. Very clever! Place a mutable inside the immutable parameter... Any advance on return new_mutable? -- Regards =dn From barry at barrys-emacs.org Wed Jul 8 18:26:39 2020 From: barry at barrys-emacs.org (Barry) Date: Wed, 8 Jul 2020 23:26:39 +0100 Subject: execution timing of the method QWidget.show() In-Reply-To: <3e4d8633-6f5c-434d-971a-602330a518e1o@googlegroups.com> References: <3e4d8633-6f5c-434d-971a-602330a518e1o@googlegroups.com> Message-ID: <31A5D134-3A04-4E33-B71D-C6AB74AEF993@barrys-emacs.org> Search for PyQt mailing list will get you to https://www.riverbankcomputing.com/mailman/listinfo/pyqt Barry > On 8 Jul 2020, at 21:17, artis.paintre at gmail.com wrote: > > ?I might be wrong but since I have not found anygroup newsgroup dedicated to PyQt5. > > My small program is expected to show a window GUI for 4 seconds before changing it, so I naively coded: > > "... > ... > # codes to set up the GUI > ... > F0.show() # F0 being a QMainWindow object > time.sleep(4) > ... > # codes to change the GUI set up > ... > F0.update() > > " > > What happens: The a blank window is displayed, freezes for 4 seconds then second set up is displayed, the original set up is not displayed. > > Why is not the original set up displayed? > > Obviously, if I remove the codes for the second set up, and the "time.sleep(4)" instruction, the original set up is displayed immediatly after I launch the execution. > -- > https://mail.python.org/mailman/listinfo/python-list > From jgossage at gmail.com Wed Jul 8 19:17:14 2020 From: jgossage at gmail.com (Jonathan Gossage) Date: Wed, 8 Jul 2020 19:17:14 -0400 Subject: Function type in typing Message-ID: How could I type a function that returns a generic type? For example, I use a function that expects another function as an argument. This second function must return a datatype or a collection. I assume that I could use *Callable[..., return type]* and I have no way to specify the return type. -- Jonathan Gossage From a24061 at ducksburg.com Thu Jul 9 06:11:01 2020 From: a24061 at ducksburg.com (Adam Funk) Date: Thu, 09 Jul 2020 11:11:01 +0100 Subject: Bulletproof json.dump? References: <5mvdtgxc2s.ln2@news.ducksburg.com> Message-ID: On 2020-07-07, Stephen Rosen wrote: > On Mon, Jul 6, 2020 at 6:37 AM Adam Funk wrote: > >> Is there a "bulletproof" version of json.dump somewhere that will >> convert bytes to str, any other iterables to list, etc., so you can >> just get your data into a file & keep working? >> > > Is the data only being read by python programs? If so, consider using > pickle: https://docs.python.org/3/library/pickle.html > Unlike json dumping, the goal of pickle is to represent objects as exactly > as possible and *not* to be interoperable with other languages. > > > If you're using json to pass data between python and some other language, > you don't want to silently convert bytes to strings. > If you have a bytestring of utf-8 data, you want to utf-8 decode it before > passing it to json.dumps. > Likewise, if you have latin-1 data, you want to latin-1 decode it. > There is no universal and correct bytes-to-string conversion. > > On Mon, Jul 6, 2020 at 9:45 AM Chris Angelico wrote: > >> Maybe what we need is to fork out the default JSON encoder into two, >> or have a "strict=True" or "strict=False" flag. In non-strict mode, >> round-tripping is not guaranteed, and various types will be folded to >> each other - mainly, many built-in and stdlib types will be >> represented in strings. In strict mode, compliance with the RFC is >> ensured (so ValueError will be raised on inf/nan), and everything >> should round-trip safely. >> > > Wouldn't it be reasonable to represent this as an encoder which is provided > by `json`? i.e. > > from json import dumps, UnsafeJSONEncoder > ... > json.dumps(foo, cls=UnsafeJSONEncoder) > > Emphasizing the "Unsafe" part of this and introducing people to the idea of > setting an encoder also seems nice. > > > On Mon, Jul 6, 2020 at 9:12 AM Chris Angelico wrote: > >> On Mon, Jul 6, 2020 at 11:06 PM Jon Ribbens via Python-list >> wrote: >> > > >> The 'json' module already fails to provide round-trip functionality: >> > >> > >>> for data in ({True: 1}, {1: 2}, (1, 2)): >> > ... if json.loads(json.dumps(data)) != data: >> > ... print('oops', data, json.loads(json.dumps(data))) >> > ... >> > oops {True: 1} {'true': 1} >> > oops {1: 2} {'1': 2} >> > oops (1, 2) [1, 2] >> >> There's a fundamental limitation of JSON in that it requires string >> keys, so this is an obvious transformation. I suppose you could call >> that one a bug too, but it's very useful and not too dangerous. (And >> then there's the tuple-to-list transformation, which I think probably >> shouldn't happen, although I don't think that's likely to cause issues >> either.) > > > Ideally, all of these bits of support for non-JSON types should be opt-in, > not opt-out. > But it's not worth making a breaking change to the stdlib over this. > > Especially for new programmers, the notion that > deserialize(serialize(x)) != x > just seems like a recipe for subtle bugs. > > You're never guaranteed that the deserialized object will match the > original, but shouldn't one of the goals of a de/serialization library be > to get it as close as is reasonable? > > > I've seen people do things which boil down to > > json.loads(x)["some_id"] == UUID(...) > > plenty of times. It's obviously wrong and the fix is easy, but isn't making > the default json encoder less strict just encouraging this type of bug? > > Comparing JSON data against non-JSON types is part of the same category of > errors: conflating JSON with dictionaries. > It's very easy for people to make this mistake, especially since JSON > syntax is a subset of python dict syntax, so I don't think `json.dumps` > should be encouraging it. > > On Tue, Jul 7, 2020 at 6:52 AM Adam Funk wrote: > >> Here's another "I'd expect to have to deal with this sort of thing in >> Java" example I just ran into: >> >> >>> r = requests.head(url, allow_redirects=True) >> >>> print(json.dumps(r.headers, indent=2)) >> ... >> TypeError: Object of type CaseInsensitiveDict is not JSON serializable >> >>> print(json.dumps(dict(r.headers), indent=2)) >> { >> "Content-Type": "text/html; charset=utf-8", >> "Server": "openresty", >> ... >> } >> > > Why should the JSON encoder know about an arbitrary dict-like type? > It might implement Mapping, but there's no way for json.dumps to know that > in the general case (because not everything which implements Mapping > actually inherits from the Mapping ABC). > Converting it to a type which json.dumps understands is a reasonable > constraint. > > Also, wouldn't it be fair, if your object is "case insensitive" to > serialize it as > { "CONTENT-TYPE": ... } or { "content-type": ... } or ... > ? > > `r.headers["content-type"]` presumably gets a hit. > `json.loads(json.dumps(dict(r.headers)))["content-type"]` will get a > KeyError. > > This seems very much out of scope for the json package because it's not > clear what it's supposed to do with this type. > Libraries should ask users to specify what they mean and not make > potentially harmful assumptions. I see what you mean. I guess it just bugs me to have to do all this explicit type conversion (when I'm not using Java!). -- A drug is not bad. A drug is a chemical compound. The problem comes in when people who take drugs treat them like a license to behave like an asshole. ---Frank Zappa From patilchaitanya394 at gmail.com Tue Jul 7 22:40:43 2020 From: patilchaitanya394 at gmail.com (Chaitanya Patil) Date: Wed, 8 Jul 2020 08:10:43 +0530 Subject: Facing problem while opening phython Message-ID: I just installed python version 3.7.3 in my PC (Windows 7 ultimate) after installing it when i try to open it but i am not able to access it . It is showing some kind of system error. Even after reinstalling still the same error is reported If there is a solution for this then please let me know From ikorot01 at gmail.com Thu Jul 9 12:49:36 2020 From: ikorot01 at gmail.com (Igor Korot) Date: Thu, 9 Jul 2020 11:49:36 -0500 Subject: Facing problem while opening phython In-Reply-To: References: Message-ID: Hi, On Thu, Jul 9, 2020 at 11:07 AM Chaitanya Patil wrote: > > I just installed python version 3.7.3 in my PC (Windows 7 ultimate) > after installing it when i try to open it but i am not able to access it . > It is showing some kind of system error. > Even after reinstalling still the same error is reported > If there is a solution for this then please let me know What is an exact error message you received? Please copy'n'paste it here. Also - how do you launch it? Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list From patrickkidd at gmail.com Fri Jul 10 12:01:50 2020 From: patrickkidd at gmail.com (Patrick Stinson) Date: Fri, 10 Jul 2020 08:01:50 -0800 Subject: Equivalent of "make install" for Python on windows? Message-ID: <5404B2D0-C123-457B-A732-8BAD25012025@gmail.com> Building python from source on windows is straightforward enough with PCBuild/build.bat. But it seems as though the resulting distribution that runs from these standard build dirs ends up sort of incomplete and/or fragmented - at least for what I am used to on *NIX. Binaries are in ./PCBuild/platform instead of ./bin, there is no pip, then get-pip.py installs the pip module but puts the pip script in ./Scripts. And other things? Is there some kind of install step that I am missing? It?s fine if this is just a matter of adjusting to a non-standard distribution config, but I have always had the feeling that the distribution doesn?t really work correctly. Cheers, -Patrick From patrickkidd at gmail.com Fri Jul 10 12:05:03 2020 From: patrickkidd at gmail.com (Patrick Stinson) Date: Fri, 10 Jul 2020 08:05:03 -0800 Subject: Equivalent of "make install" for Python on windows? In-Reply-To: <5404B2D0-C123-457B-A732-8BAD25012025@gmail.com> References: <5404B2D0-C123-457B-A732-8BAD25012025@gmail.com> Message-ID: <1566794A-811E-4ABD-A9BF-C85A8C1F6ABA@gmail.com> Oh right, and another example: The binary names for debug builds have a _d suffix, but modules like pip (which I assume can only be installed with get-pip.py) expect them not to have this suffix. Once I started copying lots of .exe and .lib files around just to make the distribution work I started to think I was missing something. Cheers, -Patrick > On Jul 10, 2020, at 8:01 AM, Patrick Stinson wrote: > > Building python from source on windows is straightforward enough with PCBuild/build.bat. But it seems as though the resulting distribution that runs from these standard build dirs ends up sort of incomplete and/or fragmented - at least for what I am used to on *NIX. > > Binaries are in ./PCBuild/platform instead of ./bin, there is no pip, then get-pip.py installs the pip module but puts the pip script in ./Scripts. And other things? > > Is there some kind of install step that I am missing? It?s fine if this is just a matter of adjusting to a non-standard distribution config, but I have always had the feeling that the distribution doesn?t really work correctly. > > Cheers, > -Patrick From 6073sumant at gmail.com Fri Jul 10 04:13:39 2020 From: 6073sumant at gmail.com (Deepak Didmania) Date: Fri, 10 Jul 2020 13:43:39 +0530 Subject: python installation help Message-ID: please help me in installing python From t.jithesh27 at gmail.com Fri Jul 10 08:57:54 2020 From: t.jithesh27 at gmail.com (Jithesh Thirumaran) Date: Fri, 10 Jul 2020 18:27:54 +0530 Subject: python software foundation Message-ID: please uninstall the site packages of python 3.7.2 and tell me the result thank you (T.Jithesh) From rosuav at gmail.com Fri Jul 10 13:19:42 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 11 Jul 2020 03:19:42 +1000 Subject: python software foundation In-Reply-To: References: Message-ID: On Sat, Jul 11, 2020 at 3:10 AM Jithesh Thirumaran wrote: > > please uninstall the site packages of python 3.7.2 and tell me the result > thank you The result was 1. You're welcome. ChrisA PS. If that answer wasn't very helpful, consider clarifying your question. :) From Bischoop at vimuster.net Fri Jul 10 13:21:33 2020 From: Bischoop at vimuster.net (Bischoop) Date: Fri, 10 Jul 2020 17:21:33 -0000 (UTC) Subject: python installation help References: Message-ID: On 2020-07-10, Deepak Didmania <6073sumant at gmail.com> wrote: > please help me in installing python Well I don't think anybody here has a Wizard Glass Ball. You need to state what is your problem, what erro message you have during istallation. From Ralf_M at t-online.de Fri Jul 10 13:33:15 2020 From: Ralf_M at t-online.de (Ralf M.) Date: Fri, 10 Jul 2020 19:33:15 +0200 Subject: unittest test discovery: regular packages vs. namespace packages Message-ID: Hello, to my last question I got many helpful and enlightening answers. So I try again with a completely different topic. https://docs.python.org/3/library/unittest.html#test-discovery says about test discovery: "Unittest supports simple test discovery. In order to be compatible with test discovery, all of the test files must be modules or packages (including namespace packages) importable from the top-level directory of the project (this means that their filenames must be valid identifiers). [...] Note: As a shortcut, python -m unittest is the equivalent of python -m unittest discover." Therefore I expected python -m unittest to run all tests in the current directory and its subdirectories, regardless of whether the subdirectories contain a __init__.py or not. However, this only works for me if an (empty) __init__.py is present, i.e. the package is a regular one. As soon as I delete the __init__.py, turning the regular package into a namespace package, unittest doesn't find the test files any more. When I recreate __init__.py, the test file (e.g. test_demo.py) is found again. See demo session further down. I tried the following Python versions, all showed the same behavior: Python 3.7.1 (python.org) on Win10 Python 3.7.4 (python.org) on Win7 Python 3.7.7 (Anaconda) on Win10 Python 3.8.3 (Anaconda) on Win10 What am I missing / misunderstanding? Demo session: F:\demo>dir /s /b F:\demo\test_we4n7uke5vx F:\demo\test_we4n7uke5vx\test_demo.py F:\demo\test_we4n7uke5vx\__init__.py F:\demo>type test_we4n7uke5vx\__init__.py F:\demo>type test_we4n7uke5vx\test_demo.py import unittest class SomeTestCase(unittest.TestCase): def test_fail_always(self): self.assertTrue(False) F:\demo>py -m unittest F ====================================================================== FAIL: test_fail_always (test_we4n7uke5vx.test_demo.SomeTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "F:\demo\test_we4n7uke5vx\test_demo.py", line 4, in test_fail_always self.assertTrue(False) AssertionError: False is not true ---------------------------------------------------------------------- Ran 1 test in 0.001s FAILED (failures=1) F:\demo>del test_we4n7uke5vx\__init__.py F:\demo>py -m unittest ---------------------------------------------------------------------- Ran 0 tests in 0.000s OK F:\demo>echo # > test_we4n7uke5vx\__init__.py F:\demo>py -m unittest F ====================================================================== FAIL: test_fail_always (test_we4n7uke5vx.test_demo.SomeTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "F:\demo\test_we4n7uke5vx\test_demo.py", line 4, in test_fail_always self.assertTrue(False) AssertionError: False is not true ---------------------------------------------------------------------- Ran 1 test in 0.001s FAILED (failures=1) F:\demo> From bgailer at gmail.com Fri Jul 10 14:05:25 2020 From: bgailer at gmail.com (Bob Gailer) Date: Fri, 10 Jul 2020 14:05:25 -0400 Subject: python installation help In-Reply-To: References: Message-ID: On Jul 10, 2020 1:04 PM, "Deepak Didmania" <6073sumant at gmail.com> wrote: > > please help me in installing python Visit this page: https://www.python.org/about/gettingstarted/ If you get stuck, reply-all and tell us: Your computer's operating system, Version of python you're trying to install, What you tried, Results you got that you weren't expecting. Don't attach screenshots as they probably won't come through. Bob Gailer From PythonList at DancesWithMice.info Fri Jul 10 16:54:05 2020 From: PythonList at DancesWithMice.info (dn) Date: Sat, 11 Jul 2020 08:54:05 +1200 Subject: python software foundation In-Reply-To: References: Message-ID: <2dff15e5-c76f-2fd4-7c7e-727b23171749@DancesWithMice.info> On 11/07/20 5:19 AM, Chris Angelico wrote: > On Sat, Jul 11, 2020 at 3:10 AM Jithesh Thirumaran > wrote: >> >> please uninstall the site packages of python 3.7.2 and tell me the result >> thank you > > The result was 1. @Chris, we should discuss this: A correct result would be 0. Did you notice any warning or error messages? https://unix.stackexchange.com/questions/308207/exit-code-at-the-end-of-a-bash-script-- Regards =dn From PythonList at DancesWithMice.info Fri Jul 10 17:54:33 2020 From: PythonList at DancesWithMice.info (dn) Date: Sat, 11 Jul 2020 09:54:33 +1200 Subject: Friday Finking: Limiting parameters Message-ID: Do you prefer to limit the number of parameters accepted by a single function/method, and if so, how do you handle situations where more data is needed? TLDR; specific questions at the end of this msg Along with one of our list-colleagues (a fellow graduate?survivor from the time of mainframe computers, monolithic programs, when "structured programming" was 'the latest new idea', and OOP[s] was one's exclamation upon making a mistake) we have been re-reading and discussing "Code Complete". It is 'an oldie, but a goodie', and Python progs may feel so-superior by happily looking-past various C*/Java-based ideas. The chapter on "High-Quality Routines" covers a lot of (hopefully, to you) familiar ground, eg structural-decomposition, descriptive names, manageability, readability, reliability, changeability, isolating complexity, SRP, strong-cohesion, loose-coupling (and all the fun of the fair...). A particular focus is "Parameter passing issues" - that the list as an whole presents a "consistent interface abstraction", that the parameters are in a sensible sequence (that it matches any other similar function signatures), and that assumptions are documented. The recommendation is that the list be <= seven parameters. [I have a recollection that someone else (?'Uncle Bob Martin') recommends <= three] What should one do when a routine requires numbers of input values? Does Python's lack of "interfaces" let us down? If we were going to be pedantic, then the quick-and-dirty way to reduce the parameter-count might be to use a collection, eg put a physical address into a named-tuple or list called "address" instead of passing "street", "town", "city", "postal_code", etc. We shouldn't be childish when it comes to style-guides. If the data is as cohesive as the components of an address, we should define a class. Now we can pass a single instantiated-object, with style and flair! However, the criticism of that idea is that it 'breaks' encapsulation - the parameter's routine now needs to know which data-attributes exist within the passed object - which is an example of close-coupling. Also, if instead of creating a new object, eg "address", we passed across a containing object, eg "person"; we might save ourselves some effort! Sadly, we would (likely) be passing loads of unnecessary data, possibly even in an insecure fashion. Time for some compromise? How about we add a method to the "address" example-object, which is then passed to the routine? It can be called, and deliver the object's necessary attributes per the interface's spec. NB we can do this in Python because a function/method is a "first-class object"! Now our parameter list is shortened (hopefully to the recommended degree) - thus also the degree of "coupling" between the call-ing and call-ed routines, the data passed is minimised, and the communication across the interface clarified. That said, haven't we now built what other languages might call an "interface"? Questions: Is the idea of limiting the number of parameters passed across an interface a real concern or somewhat an affectation? Is three, five, seven, ... a valid limit (or warning-signal)? Do you have a personal or corporate style or 'standard' to limit parameter lists to seven parameters, or some other number? Given that Python enables labeled arguments ("keyword arguments"), does the concern really only apply to 'us' in terms of numbers of "positional arguments"? Why not simply create and pass a collection (to suit the 'standards committee') and be done. What's the big deal, don't have time to waste, bureaucracy (!)... What about the similar Q+D solution using a class? After all, we could just as easily build an extraction-routine into the calling-class, which reaches into the passed-class for the data it needs - then we don't have to go to the other team to ask their 'permission'/agreement/cooperation or wait for them to build the requisite method! Is passing a function as an argument a safe and valid way to do business, or is it 'showing off'? Does the pass-a-function idea making testing easier (of both the call-ed and the call-ing routines) and might it make a change (eg adding another field) easier to manage in-future? What do you do? Refs: Steve McConnell, "Code Complete", Microsoft Press, 2004. -- Regards, =dn From t.jithesh27 at gmail.com Sat Jul 11 06:35:07 2020 From: t.jithesh27 at gmail.com (Jithesh Thirumaran) Date: Sat, 11 Jul 2020 16:05:07 +0530 Subject: python software foundation Message-ID: Have you uninstall the site package of the python version 3.7.2 please reply me immediately Thank you, (T.Jithesh) From souvik.viksou at gmail.com Sat Jul 11 06:36:13 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sat, 11 Jul 2020 16:06:13 +0530 Subject: python software foundation In-Reply-To: References: Message-ID: No. On Sat, Jul 11, 2020, 4:04 PM Jithesh Thirumaran wrote: > Have you uninstall the site package of the python version 3.7.2 > please reply me immediately > Thank you, > (T.Jithesh) > -- > https://mail.python.org/mailman/listinfo/python-list > From shivamdutt606 at gmail.com Sat Jul 11 03:26:22 2020 From: shivamdutt606 at gmail.com (Shivam Dutt Sharma) Date: Sat, 11 Jul 2020 12:56:22 +0530 Subject: Unable to login | fbchat.Client In-Reply-To: References: Message-ID: Dear All, I am facing an error while trying to log-in to fbchat.Client. This is obviously despite me entering absolutely correct ID & P/W. It could be because of any latest update in the package, or a user_agent / session (cookies) issue too. Prima-facie, if you think a few adjustments need to be made in the client or state file/s, please let me know, else I shall share the complete code link for your perusal. Below's the error message. I will be highly grateful, if I can get an idea of where am I going wrong? *Logging in xxxxxx.x.xxxxxx... Attempt #1 failed, retrying Traceback (most recent call last): File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_client.py", line 209, in login user_agent=user_agent, File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_state.py", line 149, in login return cls.from_session(session=session) File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_state.py", line 186, in from_session fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1) AttributeError: 'NoneType' object has no attribute 'group'* *Best,* *Shivam Dutt Sharma* *LinkedIn : shivam-dutt-sharma-020456149 * *PGP in Machine Learning | NIT WarangalFundraising Volunteer @ The AIM Foundation* *PCEP @ PythonInstitute* ---------- Forwarded message --------- From: Shivam Dutt Sharma Date: Sun, Jul 5, 2020 at 8:38 AM Subject: Unable to login | fbchat.Client To: Dear All, I am facing an error while trying to log-in to fbchat.Client. This is obviously despite me entering absolutely correct ID & P/W. It could be because of any latest update in the package, or a user_agent / session (cookies) issue too. Prima-facie, if you think a few adjustments need to be made in the client or state file/s, please let me know, else I shall share the complete code link for your perusal. Below's the error message. I will be highly grateful, if I can get an idea of where am I going wrong? *Logging in xxxxxx.x.xxxxxx... Attempt #1 failed, retrying Traceback (most recent call last): File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_client.py", line 209, in login user_agent=user_agent, File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_state.py", line 149, in login return cls.from_session(session=session) File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_state.py", line 186, in from_session fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1) AttributeError: 'NoneType' object has no attribute 'group'* *Best,* *Shivam Dutt Sharma* *LinkedIn : shivam-dutt-sharma-020456149 * *PGP in Machine Learning | NIT WarangalFundraising Volunteer @ The AIM Foundation* *PCEP @ PythonInstitute* From narenchunduri at gmail.com Sat Jul 11 04:34:56 2020 From: narenchunduri at gmail.com (narenchunduri at gmail.com) Date: Sat, 11 Jul 2020 01:34:56 -0700 (PDT) Subject: Need a Dynamic vlookup using python In-Reply-To: References: Message-ID: <2f3cfd9b-7008-4d11-89e1-9733eab72fefo@googlegroups.com> Any suggestions please From 2QdxY4RzWzUUiLuE at potatochowder.com Sat Jul 11 09:43:25 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Sat, 11 Jul 2020 08:43:25 -0500 Subject: Unable to login | fbchat.Client In-Reply-To: References: Message-ID: <20200711134325.GB1373@scrozzle> On 2020-07-11 at 12:56:22 +0530, Shivam Dutt Sharma wrote: > *Logging in xxxxxx.x.xxxxxx... > Attempt #1 failed, retrying > Traceback (most recent call last): > File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_client.py", > line 209, in login > user_agent=user_agent, > File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_state.py", > line 149, in login > return cls.from_session(session=session) > File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_state.py", > line 186, in from_session > fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1) > AttributeError: 'NoneType' object has no attribute 'group'* I don't know anything about fbchat, but it looks like FB_DTSG_REGEX.search is returning None (indicating that the search failed), which doesn't have an attribute named "group." I would suggest breaking up fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1) into multiple statements and testing the result of the search before assuming that there's a group attribute: xxx = FB_DTSG_REGEX.search(r.text) if xxx: fb_dtsg = xxx.group(1) else: print("the search failed, now what?") From python at mrabarnett.plus.com Sat Jul 11 13:21:14 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 11 Jul 2020 18:21:14 +0100 Subject: Unable to login | fbchat.Client In-Reply-To: References: Message-ID: <26265de9-a5d4-e0b0-20ea-c75152ab7d6b@mrabarnett.plus.com> On 2020-07-11 08:26, Shivam Dutt Sharma wrote: > Dear All, > > > I am facing an error while trying to log-in to fbchat.Client. This is > obviously despite me entering absolutely correct ID & P/W. It could be > because of any latest update in the package, or a user_agent / session > (cookies) issue too. > > Prima-facie, if you think a few adjustments need to be made in the > client or state file/s, please let me know, else I shall share the > complete code link for your perusal. > > > Below's the error message. I will be highly grateful, if I can get an > idea of where am I going wrong? > > > *Logging in xxxxxx.x.xxxxxx... > Attempt #1 failed, retrying > Traceback (most recent call last): > File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_client.py", > line 209, in login > user_agent=user_agent, > File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_state.py", > line 149, in login > return cls.from_session(session=session) > File "C:\Users\my\Anaconda3\lib\site-packages\fbchat\_state.py", > line 186, in from_session > fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1) > AttributeError: 'NoneType' object has no attribute 'group'* > > [snip] You should look at the fbchat project itself. This looks like the same problem: https://github.com/carpedm20/fbchat/issues/517 From hjp-python at hjp.at Sat Jul 11 16:13:19 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 11 Jul 2020 22:13:19 +0200 Subject: Friday Finking: Limiting parameters In-Reply-To: References: Message-ID: <20200711201319.GA959@hjp.at> On 2020-07-11 09:54:33 +1200, dn via Python-list wrote: > Questions: > > Is the idea of limiting the number of parameters passed across an interface > a real concern or somewhat an affectation? > > Is three, five, seven, ... a valid limit (or warning-signal)? > > Do you have a personal or corporate style or 'standard' to limit parameter > lists to seven parameters, or some other number? > > Given that Python enables labeled arguments ("keyword arguments"), does the > concern really only apply to 'us' in terms of numbers of "positional > arguments"? Keyword arguments greatly ameliorate the problems I have with long parameter lists. While I think that calling a function with 7 positional parameters is pretty much unreadable, with 7 named parameters (or maybe 2 positional and 5 named parameters) it doesn't bother me much. The definition of the function might have even more parameters, as long as most of them are optional and have sensible defaults (subprocess.Popen with 20 parameters (if I counted correctly) is pushing it, though). > Why not simply create and pass a collection (to suit the 'standards > committee') and be done. What's the big deal, don't have time to waste, > bureaucracy (!)... > > What about the similar Q+D solution using a class? That's what I often do. The main reason is that often a lot of those parameters are repetitive. So instead of passing the same 7 parameters to every function, I create a "Context" or "Job" class with those 7 fields which I then pass to each function. So it not just looks tidier, it also reduces the risk of inconsistencies. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From PythonList at DancesWithMice.info Sat Jul 11 16:39:16 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 12 Jul 2020 08:39:16 +1200 Subject: Need a Dynamic vlookup using python In-Reply-To: <2f3cfd9b-7008-4d11-89e1-9733eab72fefo@googlegroups.com> References: <2f3cfd9b-7008-4d11-89e1-9733eab72fefo@googlegroups.com> Message-ID: <206bf286-f039-b98f-f476-cacfc80f6125@DancesWithMice.info> On 11/07/20 8:34 PM, narenchunduri at gmail.com wrote: > Any suggestions please Clarify the requirements, rather than starting with a 'solution'. Communicate the constraints, eg what is already in-place. "vlookup" has particular meaning in worksheet/spreadsheet packages. Is that what you are using? If so, with which Python interfacing package? Are you using one of Python's math/stats packages to hold and analyse the data? Remember please that all-here are volunteers, and will find it easier to help you if you (first) help us to understand the problem and your intentions... -- Regards =dn From PythonList at DancesWithMice.info Sat Jul 11 16:56:47 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 12 Jul 2020 08:56:47 +1200 Subject: Friday Finking: Limiting parameters In-Reply-To: <20200711201319.GA959@hjp.at> References: <20200711201319.GA959@hjp.at> Message-ID: <74d1c5a1-cdf6-fc5c-17a4-89104b4c9e4d@DancesWithMice.info> On 12/07/20 8:13 AM, Peter J. Holzer wrote: > On 2020-07-11 09:54:33 +1200, dn via Python-list wrote: >> Questions: >> >> Is the idea of limiting the number of parameters passed across an interface >> a real concern or somewhat an affectation? >> >> Is three, five, seven, ... a valid limit (or warning-signal)? >> >> Do you have a personal or corporate style or 'standard' to limit parameter >> lists to seven parameters, or some other number? >> >> Given that Python enables labeled arguments ("keyword arguments"), does the >> concern really only apply to 'us' in terms of numbers of "positional >> arguments"? > > Keyword arguments greatly ameliorate the problems I have with long > parameter lists. While I think that calling a function with 7 positional > parameters is pretty much unreadable, with 7 named parameters (or maybe > 2 positional and 5 named parameters) it doesn't bother me much. The > definition of the function might have even more parameters, as long as > most of them are optional and have sensible defaults (subprocess.Popen > with 20 parameters (if I counted correctly) is pushing it, though). Do you think, then, that the maxima should be applied to the number of arguments that will appear in the 'expected usage' of the routine? (cf the def's parameter-list) After all, calling Popen would rarely require all-20 arguments be stated, given the acceptability of the defaults and the irrelevance of many 'special cases'. Alternately/additionally, do you feel that the power and readability of Python's keyword-arguments + default-values, requires a modification of the advice to only limit the number of positional-arguments? Another discussion-point (which may be difficult because 'the answer' may vary according to implementation-requirements): rather than one do-it-all 'Swiss Army Knife' of a routine with dozens of parameters, might it be better-practice to code a number of methods/functions to take care of the special-cases, with a single 'core function' to carry-out the basic operations-required? (in a class environment: sub-classes maybe) >> Why not simply create and pass a collection (to suit the 'standards >> committee') and be done. What's the big deal, don't have time to waste, >> bureaucracy (!)... >> >> What about the similar Q+D solution using a class? > > That's what I often do. The main reason is that often a lot of those > parameters are repetitive. So instead of passing the same 7 parameters > to every function, I create a "Context" or "Job" class with those 7 > fields which I then pass to each function. So it not just looks tidier, > it also reduces the risk of inconsistencies. +1 Good thinking: promotes (indeed, dictates) consistency of interface! -- Regards =dn From dvl at psu.edu Sat Jul 11 17:46:24 2020 From: dvl at psu.edu (Christman, Roger Graydon) Date: Sat, 11 Jul 2020 21:46:24 +0000 Subject: Friday Finking: Limiting parameters Message-ID: I'll preface this by saying I am a programming instructor who still teaches from the ivory tower, so may not necessarily reflect actual practice in industry. But I have a very simple rule of thumb for limiting parameters: One should be able to summarize what a function does in one or two sentences, e.g. computes the volume of a cone, or print address labels. To fully understand the details of the task would certainly involve listing the parameters, but I would generally expect that a practical function would naturally put a cap on how much data is provided. If you need to include more than 7 parameters to describe what it is you want to do, you are probably doing more than one thing, or doing something unnecessarily complicated. I'll take your example with the address, and assume I want to print a mailing label. I could certainly see you needing to print: first name, middle initial, last name, house number, street name, apartment number, town, state, country, zip code, (and maybe more), and listing all of those individually would produce a very long list. But these values really are not all that independent of each other. A person's name can be viewed as a single value that happens to have multiple parts (collect that into a tuple or class). Similarly, a street address is a single object with multiple parts. These can easily be delivered as complete objects for a short parameter list. That does not necessarily mean that the function needs to know the particular representation or form of that data. Let those be objects with getter methods for the data you wish, and have the function document what methods it will attempt to call. Then any class that provides the expected methods would be suitable. That would also greatly simplify some other features for the problem. For example, "first name" "last name" really does not mean the same thing as "individual name" "family name", when some countries list the family name first. So it might be better to have a name object include a "full name" method for the print-mailing-address function to call instead of giving it access to component parts. TL;DR: I expect each parameter to a function to be independent or orthogonal to the others. Values that are closely related to each other can probably be encapsulated into a collection or object. If you still end up with a large number of independent parameters, I would question the simplicity of your function's intent. Roger Christman Pennsylvania State University From PythonList at DancesWithMice.info Sat Jul 11 19:15:56 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 12 Jul 2020 11:15:56 +1200 Subject: Friday Finking: Limiting parameters In-Reply-To: References: Message-ID: <617af290-3ffd-4cad-a992-49a70ecfc9e6@DancesWithMice.info> On 12/07/20 9:46 AM, Christman, Roger Graydon wrote: > I'll preface this by saying I am a programming instructor > who still teaches from the ivory tower, so may not necessarily > reflect actual practice in industry. ...in which case I will preface my response by saying that one of the virtues of this Discussion List is that we enjoy a wide range of membership. It is not limited or even focussed on 'professionals, so 'ivory tower' members have no less to offer. Similarly, insight from ardent hobbyists who (effectively) pay to use Python! PS there is a Python-Tutor list catering to both trainers and trainees which may be of interest and/or a resource for your students. Details at https://mail.python.org/mailman/listinfo Thank you for your considered response! > But I have a very simple rule of thumb for limiting parameters: > One should be able to summarize what a function does in one or two > sentences, e.g. computes the volume of a cone, or print address labels. > To fully understand the details of the task would certainly involve > listing the parameters, but I would generally expect that a practical > function would naturally put a cap on how much data is provided. > If you need to include more than 7 parameters to describe what > it is you want to do, you are probably doing more than one thing, > or doing something unnecessarily complicated. +1 (see also @Peter's example of ~20 parameters, and in PSL code, no less!) > I'll take your example with the address, and assume I want to > print a mailing label. I could certainly see you needing to print: > first name, middle initial, last name, house number, street name, > apartment number, town, state, country, zip code, (and maybe more), > and listing all of those individually would produce a very long list. > > But these values really are not all that independent of each other. > A person's name can be viewed as a single value that happens to > have multiple parts (collect that into a tuple or class). Similarly, > a street address is a single object with multiple parts. These can > easily be delivered as complete objects for a short parameter list. A good summary. Is there a counter-argument, that because the tuple or class is an encapsulation, its contents have to be taken on-trust - the component list is not as explicit as: street, number, town, city. Are we a particularly 'trusting' bunch? (particularly those who have been 'bitten' by assumptions in the past...) > That does not necessarily mean that the function needs to know > the particular representation or form of that data. Let those be > objects with getter methods for the data you wish, and have the > function document what methods it will attempt to call. Then > any class that provides the expected methods would be suitable. +1 Here, the proposal is not to pass an object per-se, but to pass a function/method ("getter method") which will deliver the requisite data-items? So, might we then find that our mailing-label routine includes something like (copy-pasting is NOT proper Python!): def mail_label( getter ): ... ( first name, middle initial, last name, house number, street name, apartment number, town, state, country, zip code ) = getter() In which case, have we not moved the "very long list" from the function def to a later line within the routine - and how is this in some way 'better'? > That would also greatly simplify some other features for the problem. > For example, "first name" "last name" really does not mean the same > thing as "individual name" "family name", when some countries > list the family name first. So it might be better to have a name > object include a "full name" method for the print-mailing-address > function to call instead of giving it access to component parts. +1 As mentioned, keep all the 'stuff' related to person/address in one place, rather than expecting mail_label() to know the attributes of the class! ('stuff' meaning the data-access methods as well as the data-attributes themselves) > TL;DR: I expect each parameter to a function to be independent > or orthogonal to the others. Values that are closely related to > each other can probably be encapsulated into a collection or object. > If you still end up with a large number of independent parameters, > I would question the simplicity of your function's intent. Well said! Zen of Python (includes): If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. -- Regards =dn From barry at barrys-emacs.org Sun Jul 12 06:10:54 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Sun, 12 Jul 2020 11:10:54 +0100 Subject: Friday Finking: Limiting parameters In-Reply-To: <617af290-3ffd-4cad-a992-49a70ecfc9e6@DancesWithMice.info> References: <617af290-3ffd-4cad-a992-49a70ecfc9e6@DancesWithMice.info> Message-ID: <65D21327-CAAC-4D3A-B5E2-859D170FB8EC@barrys-emacs.org> > On 12 Jul 2020, at 00:15, DL Neil via Python-list wrote: > >> That does not necessarily mean that the function needs to know >> the particular representation or form of that data. Let those be >> objects with getter methods for the data you wish, and have the >> function document what methods it will attempt to call. Then >> any class that provides the expected methods would be suitable. > > +1 > > Here, the proposal is not to pass an object per-se, but to pass a function/method ("getter method") which will deliver the requisite data-items? > > So, might we then find that our mailing-label routine includes something like (copy-pasting is NOT proper Python!): > > def mail_label( getter ): > ... > ( first name, middle initial, last name, house number, street name, > apartment number, town, state, country, zip code ) = getter() > > In which case, have we not moved the "very long list" from the function def to a later line within the routine - and how is this in some way 'better'? > This is not the refactor that Roger's excellent rule-of-thumb implies. Clearly moving the 20 positional args into a tuple is basically the same code, and the same maintenance problem. I'd expect to see something like this: def mail_label( person, address ): first_name = person.first_name # or if you want a function interface first_line_of_address = address.get_first_line() Barry From narenchunduri at gmail.com Sun Jul 12 11:03:41 2020 From: narenchunduri at gmail.com (narenchunduri at gmail.com) Date: Sun, 12 Jul 2020 08:03:41 -0700 (PDT) Subject: Need a Dynamic vlookup using python In-Reply-To: References: <2f3cfd9b-7008-4d11-89e1-9733eab72fefo@googlegroups.com> <206bf286-f039-b98f-f476-cacfc80f6125@DancesWithMice.info> Message-ID: Sorry for not making it clear. I tried below code # import modules from openpyxl import * from openpyxl.styles import * import webbrowser import pandas from openpyxl.worksheet.datavalidation import DataValidation # Read all Excels into pandas dataframes sowexcel = pandas.read_excel('Billing Roster - SOW.xlsx') #Load the existing Resource Allocation Excel wb = load_workbook('ACFC_Resource_Allocation.xlsx') allocationsheet = wb.active def load(): maxrow = allocationsheet.max_row sow_list = sowexcel['SOW #'].tolist() column_sow = ','.join(sow_list) validator_sow = DataValidation(type='list', formula1='"{}"'.format(column_sow), allow_blank=True) allocationsheet.add_data_validation(validator_sow) validator_sow.add('D2:D%s' %maxrow) # save the file wb.save('ACFC_Resource_Allocation.xlsx') wb.close() # Driver code if __name__ == "__main__": load() file_open = webbrowser.open('ACFC_Resource_Allocation.xlsx') In Billing Roster - SOW.xlsx I have new column data one is named as SOW and other is named SOW Description (Match value for SOW). And now when i open ACFC_Resource_Allocation.xlsx excel and for an example if select a value in D2 (SOW) cell from the dropdown i should get a matching value into E2 cell after the selection from dropdown. I only have an idea than a vlookup from Excel like below should solve my case. Not sure how to achieve in python. =VLOOKUP(D2,'[Billing Roster - SOW.xlsx]SOW List'!$A$1:$B$14,1,FALSE) Please let me know if am not still clear. From elbarbun at gmail.com Sun Jul 12 22:20:55 2020 From: elbarbun at gmail.com (Marco Sulla) Date: Mon, 13 Jul 2020 04:20:55 +0200 Subject: frozendict: an experiment Message-ID: TL;DR: I tried to implement in CPython a frozendict here: https://github.com/Marco-Sulla/cpython Long explaining: What is a frozendict? It's an immutable dict. The type was proposed in the past but rejected: https://www.python.org/dev/peps/pep-0416/ So why did I try to implement it? IMO, apart the considerations in PEP 416, a frozendict can be useful: - as a faster base for types.MutableMappingProxy - as a substitute of namedtuple - as set values - as a faster dict. Indeed a frozendict does not need views. Keys, values and items can be cached and could be a subclass of frozendict that implements also the set API (values apart). A possible problem is that frozendict requires more memory, since the hash is cached. My implementation is very naif. I tried to do the simplest thing, without any speed improvement. I haven't added frozendict in marshal, and the pickle implementation is very raw... Furthermore, I didn't touch the AST parser at all, and I did not add any test for Python or the C API in the battery, but I've done my tests apart, in pytest. PS: I used for tests and benchmarks a little modified version of the tests for my Python implementation of frozendict: https://github.com/Marco-Sulla/python-frozendict/tree/master/test . The results are interesting. A CPython builtin frozendict is faster in every bench that immutables.Map, that uses the HAMT algorithm. and was proposed as alternative in PEP 603: https://www.python.org/dev/peps/pep-0603/ . Maybe because I implemented it in CPython and immutables.Map is a C extension. From PythonList at DancesWithMice.info Mon Jul 13 01:21:40 2020 From: PythonList at DancesWithMice.info (dn) Date: Mon, 13 Jul 2020 17:21:40 +1200 Subject: Friday Finking: Limiting parameters In-Reply-To: <65D21327-CAAC-4D3A-B5E2-859D170FB8EC@barrys-emacs.org> References: <617af290-3ffd-4cad-a992-49a70ecfc9e6@DancesWithMice.info> <65D21327-CAAC-4D3A-B5E2-859D170FB8EC@barrys-emacs.org> Message-ID: <3b0af018-73f3-df41-9042-687eed5a4a63@DancesWithMice.info> On 12/07/20 10:10 PM, Barry Scott wrote: >> On 12 Jul 2020, at 00:15, DL Neil via Python-list >> > wrote: >> >>> That does not necessarily mean that the function needs to know >>> the particular representation or form of that data. ??Let those be >>> objects with getter methods for the data you wish, and have the >>> function document what methods it will attempt to call. ??Then >>> any class that provides the expected methods would be suitable. >> >> +1 >> >> Here, the proposal is not to pass an object per-se, but to pass a >> function/method ("getter method") which will deliver the requisite >> data-items? >> >> So, might we then find that our mailing-label routine includes >> something like (copy-pasting is NOT proper Python!): >> >> def mail_label( getter ): >> ???... >> ???( first name, middle initial, last name, house number, street name, >> ???apartment number, town, state, country, zip code ) = getter() >> >> In which case, have we not moved the "very long list" from the >> function def to a later line within the routine - and how is this in >> some way 'better'? >> > > This is not the refactor that Roger's excellent rule-of-thumb implies. > > Clearly moving the 20 positional args into a tuple is basically the same > code, > and the same maintenance problem. Agreed! > I'd expect to see something like this: > > def mail_label( person, address ): > first_name = person.first_name > # or if you want a function interface > first_line_of_address = address.get_first_line() Does this idea move whole objects across the interface? (see earlier in the thread) Taking a person class as subject and a mailing-label as the function's object, aren't there two criticisms? 1 the function needs to know which attributes of the person and address objects it wants to use, cf saying 'I need street, number, town, ...'* 2 "person" likely contains a load of data that is irrelevant to printing a mail-label. Why is this preferable to using a 'getter' method, or some other approach? * your point (above) being that these need not be (say) a dozen data elements, but could be just-enough data, and data-combinations which identify the addressee and which represent the components of the address. -- Regards =dn From sojirindamilare at gmail.com Mon Jul 13 12:08:43 2020 From: sojirindamilare at gmail.com (Damilare) Date: Mon, 13 Jul 2020 17:08:43 +0100 Subject: Urgent Message-ID: <5f0c870d.1c69fb81.6be43.5289@mx.google.com> I need help, am trying to activate python 3.8 on command prompt with Windows 10 but it?s proving rather difficult. I will appreciate any help. Thanks From barry at barrys-emacs.org Mon Jul 13 13:24:58 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 13 Jul 2020 18:24:58 +0100 Subject: Friday Finking: Limiting parameters In-Reply-To: <3b0af018-73f3-df41-9042-687eed5a4a63@DancesWithMice.info> References: <617af290-3ffd-4cad-a992-49a70ecfc9e6@DancesWithMice.info> <65D21327-CAAC-4D3A-B5E2-859D170FB8EC@barrys-emacs.org> <3b0af018-73f3-df41-9042-687eed5a4a63@DancesWithMice.info> Message-ID: > On 13 Jul 2020, at 06:21, dn via Python-list wrote: > > On 12/07/20 10:10 PM, Barry Scott wrote: >>> On 12 Jul 2020, at 00:15, DL Neil via Python-list > wrote: >>> >>>> That does not necessarily mean that the function needs to know >>>> the particular representation or form of that data. Let those be >>>> objects with getter methods for the data you wish, and have the >>>> function document what methods it will attempt to call. Then >>>> any class that provides the expected methods would be suitable. >>> >>> +1 >>> >>> Here, the proposal is not to pass an object per-se, but to pass a function/method ("getter method") which will deliver the requisite data-items? >>> >>> So, might we then find that our mailing-label routine includes something like (copy-pasting is NOT proper Python!): >>> >>> def mail_label( getter ): >>> ... >>> ( first name, middle initial, last name, house number, street name, >>> apartment number, town, state, country, zip code ) = getter() >>> >>> In which case, have we not moved the "very long list" from the function def to a later line within the routine - and how is this in some way 'better'? >>> >> This is not the refactor that Roger's excellent rule-of-thumb implies. >> Clearly moving the 20 positional args into a tuple is basically the same code, >> and the same maintenance problem. > > Agreed! > > >> I'd expect to see something like this: >> def mail_label( person, address ): >> first_name = person.first_name >> # or if you want a function interface >> first_line_of_address = address.get_first_line() > > Does this idea move whole objects across the interface? (see earlier in the thread) Taking a person class as subject and a mailing-label as the function's object, aren't there two criticisms? > > 1 the function needs to know which attributes of the person and address objects it wants to use, cf saying 'I need street, number, town, ...'* That is part of the requirements spec for the function - the function author will implement against spec so will know what is needed. > > 2 "person" likely contains a load of data that is irrelevant to printing a mail-label. The design problem we are solving is that it is easy (more maintainable) to call the function with a small number of args that provide what is needed. Having access to more than the minimum information is not a problem usually. One function might only need the family-name, another function the given-name (choose terms that match your region and culture here). > > Why is this preferable to using a 'getter' method, or some other approach? The idea of getter methods is to hide the implementation details of an object that may compute a value. This is useful when refactoring and debugging, but can be over complex for a simple app/object. person.get_name_formal() vs. person.get_name_informal() could use the same set of data combined in different ways. > > * your point (above) being that these need not be (say) a dozen data elements, but could be just-enough data, and data-combinations which identify the addressee and which represent the components of the address. The app designer will have to design the API to person and address that makes sense in the app. Barry From barry at barrys-emacs.org Mon Jul 13 13:28:08 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 13 Jul 2020 18:28:08 +0100 Subject: frozendict: an experiment In-Reply-To: References: Message-ID: > On 13 Jul 2020, at 03:20, Marco Sulla wrote: > > TL;DR: I tried to implement in CPython a frozendict here: > https://github.com/Marco-Sulla/cpython > > Long explaining: > > What is a frozendict? It's an immutable dict. The type was proposed in > the past but rejected: https://www.python.org/dev/peps/pep-0416/ > > So why did I try to implement it? IMO, apart the considerations in PEP > 416, a frozendict can be useful: > > - as a faster base for types.MutableMappingProxy > - as a substitute of namedtuple > - as set values > - as a faster dict. Indeed a frozendict does not need views. Keys, > values and items can be cached and could be a subclass of frozendict > that implements also the set API (values apart). Why is it faster? Have you benchmarked that claim? Why do you think I do not need views to use the frozendict? I thought that is what make d.key(), d.items() etc work? > > A possible problem is that frozendict requires more memory, since the > hash is cached. The hash is tiny 64 bits? > > My implementation is very naif. I tried to do the simplest thing, > without any speed improvement. I haven't added frozendict in marshal, > and the pickle implementation is very raw... Furthermore, I didn't > touch the AST parser at all, and I did not add any test for Python or > the C API in the battery, but I've done my tests apart, in pytest. > > PS: I used for tests and benchmarks a little modified version of the > tests for my Python implementation of frozendict: > https://github.com/Marco-Sulla/python-frozendict/tree/master/test . > The results are interesting. A CPython builtin frozendict is faster in > every bench that immutables.Map, that uses the HAMT algorithm. and was > proposed as alternative in PEP 603: > https://www.python.org/dev/peps/pep-0603/ . Maybe because I > implemented it in CPython and immutables.Map is a C extension. > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Mon Jul 13 13:34:46 2020 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 13 Jul 2020 18:34:46 +0100 Subject: Urgent In-Reply-To: <5f0c870d.1c69fb81.6be43.5289@mx.google.com> References: <5f0c870d.1c69fb81.6be43.5289@mx.google.com> Message-ID: <7d6184ff-c648-9c4f-e8af-fbf25dce9390@mrabarnett.plus.com> On 2020-07-13 17:08, Damilare wrote: > > > I need help, am trying to activate python 3.8 on command prompt with Windows 10 but it?s proving rather difficult. I will appreciate any help. Thanks > Why is it difficult? (Why doesn't the subject give a clue as to the topic of the post?) If it's saying that it can't find python.exe, try starting it with the Python launcher "py". From lukasz at langa.pl Mon Jul 13 17:09:25 2020 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Mon, 13 Jul 2020 23:09:25 +0200 Subject: [RELEASE] Python 3.8.4 is now available Message-ID: <70158281-E952-4F7F-97C0-541CDF4FB64A@langa.pl> Python 3.8.4 is the fourth maintenance release of Python 3.8. Go get it here: https://www.python.org/downloads/release/python-384/ Maintenance releases for the 3.8 series will continue at regular bi-monthly intervals, with 3.8.5 planned for mid-September 2020. What?s new? The Python 3.8 series is the newest feature release of the Python language, and it contains many new features and optimizations. See the ?What?s New in Python 3.8 ? document for more information about features included in the 3.8 series. This is the first bugfix release that is considerably smaller than the previous three. There?s almost 20% fewer changes at 162 commits than the average of previous three bugfix releases. Detailed information about all changes made in version 3.8.4 specifically can be found in its change log . Note that compared to 3.8.3, version 3.8.4 also contains the changes introduced in 3.8.4rc1. We hope you enjoy Python 3.8! Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. Your friendly release team, Ned Deily @nad Steve Dower @steve.dower ?ukasz Langa @ambv From Gronicus at SGA.Ninja Mon Jul 13 21:53:41 2020 From: Gronicus at SGA.Ninja (Steve) Date: Mon, 13 Jul 2020 21:53:41 -0400 Subject: App for Moto e6 using Python? Message-ID: <000401d65981$9a179ba0$ce46d2e0$@SGA.Ninja> I am looking for an app for my Moto e6 android phone that will accept a number of hours and count down. Then will beep every minute until I cancel the app. This is to remind me when to take my insulin. It has been written in python but I do not know how to convert it to an app. I wonder how much of the python code will still apply. When I was into this in the past, I installed Kivy and was able to finally generate a "Hello World" app and managed to get it to my phone. Then life called me back to reality and I lost track of what I was doing for a few years. )-: I doubt I can go through that installation and learning curve again. It works on my computer but I have projects that interfere with the alarm. This is why I would prefer to have it on my phone. I appreciate any assistance you can provide. Steve ---------------------------------------------------------------------------- ---------------- Footnote: There's 99 bugs in the code, in the code. 99 bugs in the code. So I take one down and patch it all around. Now there's 117 bugs in the code. - -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: e6 timer.py URL: From miked at dewhirst.com.au Mon Jul 13 23:58:47 2020 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Tue, 14 Jul 2020 13:58:47 +1000 Subject: App for Moto e6 using Python? In-Reply-To: <000401d65981$9a179ba0$ce46d2e0$@SGA.Ninja> References: <000401d65981$9a179ba0$ce46d2e0$@SGA.Ninja> Message-ID: On 14/07/2020 11:53 am, Steve wrote: > I am looking for an app for my Moto e6 android phone that will accept a > number of hours and count down. Then will beep every minute until I cancel > the app. This is to remind me when to take my insulin. > > > > It has been written in python but I do not know how to convert it to an app. > I wonder how much of the python code will still apply. Have you looked at Beeware? I believe they have recently released for Android. Mike > When I was into this > in the past, I installed Kivy and was able to finally generate a "Hello > World" app and managed to get it to my phone. Then life called me back to > reality and I lost track of what I was doing for a few years. )-: I doubt I > can go through that installation and learning curve again. > > > > It works on my computer but I have projects that interfere with the alarm. > This is why I would prefer to have it on my phone. > > I appreciate any assistance you can provide. > > Steve > > ---------------------------------------------------------------------------- > ---------------- > > Footnote: > > There's 99 bugs in the code, in the code. > > 99 bugs in the code. > > So I take one down and patch it all around. > > Now there's 117 bugs in the code. > > > > - > > From nobody at nobody.net Tue Jul 14 08:49:24 2020 From: nobody at nobody.net (Nomen Nescio) Date: Tue, 14 Jul 2020 08:49:24 -0400 Subject: A rule for your twitlist/mailing list Message-ID: Where path includes "google.com" and subject includes "solutions" or "test", delete..... 99 percent of the junk just ..... gone ..... feels so good I wish Google would still let you subscribe to the newsgroup and recieve updates in your inbox - that way I can mark the testbanks as "spam" Is the mailing list for comp.lang.python still open? From Marco.Sulla.Python at gmail.com Tue Jul 14 03:03:01 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Tue, 14 Jul 2020 09:03:01 +0200 Subject: frozendict: an experiment In-Reply-To: References: Message-ID: On Mon, 13 Jul 2020 at 19:28, Barry Scott wrote: > > On 13 Jul 2020, at 03:20, Marco Sulla wrote: > > So why did I try to implement it? IMO, apart the considerations in PEP > > 416, a frozendict can be useful: > > > > - as a faster base for types.MutableMappingProxy > > - as a substitute of namedtuple > > - as set values > > - as a faster dict. Indeed a frozendict does not need views. Keys, > > values and items can be cached and could be a subclass of frozendict > > that implements also the set API (values apart). > > > Why is it faster? Have you benchmarked that claim? It's not faster now, but it can. And yes, I've done a bench. I explain it better in the mail. > Why do you think I do not need views to use the frozendict? > I thought that is what make d.key(), d.items() etc work? Views for dict exist because dict is mutable. See this example: >>> d = {1: 2} >>> keys = d.keys() >>> d[2] = 3 >>> keys dict_keys([1, 2]) As you see, even if you modified the dict __after__ you created the keys view, the view returns also the new key, 2. This is desirable for a mutable object, but it's not needed for an immutable one. frozendict could create lazily an object that contains all its keys and cache it. It *seems* that this is already done, because PyDictObject struct has ma_keys and ma_values. But this is not always true. If you read the documentation in the comments of Object/dictobject.c, it's stated that, if the keys are not strings, there's actually not two separate objects for keys and values. On the contrary, key and value are stored together in ma_keys. This seems to be done because it's easier to preserve order when you modify the dict. But since frozendict cannot be modified, it could be a split dict every time. > > A possible problem is that frozendict requires more memory, since the > > hash is cached. > > The hash is tiny 64 bits? Well, it's the sum that makes the total. If, and only if, frozendict is really faster than dict, using always a split dict and cached "views", it could be used for a bunch of cases. kwargs for example. About bench, yes, as I wrote I've done a simple bench: ################################################################################ //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `d.get(key)`; total time: 0.389; iterations: 13000000; time: 2.990e-08 Dictionary size: 8; Type: frozendict; Statement: `d.get(key)`; total time: 0.416; iterations: 13000000; time: 3.202e-08 Dictionary size: 8; Type: Map; Statement: `d.get(key)`; total time: 0.559; iterations: 13000000; time: 4.302e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `d[key]`; total time: 0.375; iterations: 10000000; time: 3.753e-08 Dictionary size: 8; Type: frozendict; Statement: `d[key]`; total time: 0.338; iterations: 10000000; time: 3.384e-08 Dictionary size: 8; Type: Map; Statement: `d[key]`; total time: 0.502; iterations: 10000000; time: 5.021e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `key in d`; total time: 0.600; iterations: 20000000; time: 3.000e-08 Dictionary size: 8; Type: frozendict; Statement: `key in d`; total time: 0.541; iterations: 20000000; time: 2.703e-08 Dictionary size: 8; Type: Map; Statement: `key in d`; total time: 0.545; iterations: 20000000; time: 2.723e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `key not in d`; total time: 0.607; iterations: 20000000; time: 3.033e-08 Dictionary size: 8; Type: frozendict; Statement: `key not in d`; total time: 0.548; iterations: 20000000; time: 2.738e-08 Dictionary size: 8; Type: Map; Statement: `key not in d`; total time: 0.548; iterations: 20000000; time: 2.738e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `pickle.dumps(d)`; total time: 0.554; iterations: 625000; time: 8.869e-07 Dictionary size: 8; Type: frozendict; Statement: `pickle.dumps(d)`; total time: 0.545; iterations: 625000; time: 8.720e-07 Dictionary size: 8; Type: Map; Statement: `pickle.dumps(d)`; total time: 1.562; iterations: 625000; time: 2.499e-06 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `pickle.loads(dump)`; total time: 0.685; iterations: 500000; time: 1.371e-06 Dictionary size: 8; Type: frozendict; Statement: `pickle.loads(dump)`; total time: 0.816; iterations: 500000; time: 1.633e-06 Dictionary size: 8; Type: Map; Statement: `pickle.loads(dump)`; total time: 1.388; iterations: 500000; time: 2.775e-06 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: frozendict; Statement: `hash(d)`; total time: 0.548; iterations: 10000000; time: 5.484e-08 Dictionary size: 8; Type: Map; Statement: `hash(d)`; total time: 0.539; iterations: 10000000; time: 5.391e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `len(d)`; total time: 0.872; iterations: 20000000; time: 4.358e-08 Dictionary size: 8; Type: frozendict; Statement: `len(d)`; total time: 0.872; iterations: 20000000; time: 4.362e-08 Dictionary size: 8; Type: Map; Statement: `len(d)`; total time: 0.869; iterations: 20000000; time: 4.347e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `d.keys()`; total time: 1.453; iterations: 12500000; time: 1.163e-07 Dictionary size: 8; Type: frozendict; Statement: `d.keys()`; total time: 1.457; iterations: 12500000; time: 1.165e-07 Dictionary size: 8; Type: Map; Statement: `d.keys()`; total time: 1.896; iterations: 12500000; time: 1.517e-07 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `d.values()`; total time: 1.505; iterations: 12500000; time: 1.204e-07 Dictionary size: 8; Type: frozendict; Statement: `d.values()`; total time: 1.494; iterations: 12500000; time: 1.195e-07 Dictionary size: 8; Type: Map; Statement: `d.values()`; total time: 1.890; iterations: 12500000; time: 1.512e-07 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `d.items()`; total time: 1.213; iterations: 6250000; time: 1.941e-07 Dictionary size: 8; Type: frozendict; Statement: `d.items()`; total time: 1.214; iterations: 6250000; time: 1.942e-07 Dictionary size: 8; Type: Map; Statement: `d.items()`; total time: 1.759; iterations: 6250000; time: 2.815e-07 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `iter(d)`; total time: 1.594; iterations: 12500000; time: 1.275e-07 Dictionary size: 8; Type: frozendict; Statement: `iter(d)`; total time: 1.622; iterations: 12500000; time: 1.298e-07 Dictionary size: 8; Type: Map; Statement: `iter(d)`; total time: 1.990; iterations: 12500000; time: 1.592e-07 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `constructor(dict)`; total time: 0.301; iterations: 1250000; time: 2.405e-07 Dictionary size: 8; Type: frozendict; Statement: `constructor(dict)`; total time: 0.308; iterations: 1250000; time: 2.466e-07 Dictionary size: 8; Type: Map; Statement: `constructor(dict)`; total time: 0.815; iterations: 1250000; time: 6.523e-07 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `constructor(d.items())`; total time: 0.363; iterations: 1250000; time: 2.902e-07 Dictionary size: 8; Type: frozendict; Statement: `constructor(d.items())`; total time: 0.374; iterations: 1250000; time: 2.994e-07 Dictionary size: 8; Type: Map; Statement: `constructor(d.items())`; total time: 0.764; iterations: 1250000; time: 6.109e-07 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `constructor(**d)`; total time: 0.150; iterations: 625000; time: 2.393e-07 Dictionary size: 8; Type: frozendict; Statement: `constructor(**d)`; total time: 0.152; iterations: 625000; time: 2.428e-07 Dictionary size: 8; Type: Map; Statement: `constructor(**d)`; total time: 0.408; iterations: 625000; time: 6.536e-07 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `constructor(self)`; total time: 1.499; iterations: 6250000; time: 2.399e-07 Dictionary size: 8; Type: frozendict; Statement: `constructor(self)`; total time: 0.279; iterations: 6250000; time: 4.466e-08 Dictionary size: 8; Type: Map; Statement: `constructor(self)`; total time: 0.395; iterations: 6250000; time: 6.327e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `d.copy()`; total time: 1.320; iterations: 12500000; time: 1.056e-07 Dictionary size: 8; Type: frozendict; Statement: `d.copy()`; total time: 0.439; iterations: 12500000; time: 3.511e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `d1 == d2`; total time: 1.295; iterations: 12500000; time: 1.036e-07 Dictionary size: 8; Type: frozendict; Statement: `d1 == d2`; total time: 1.305; iterations: 12500000; time: 1.044e-07 Dictionary size: 8; Type: Map; Statement: `d1 == d2`; total time: 0.501; iterations: 12500000; time: 4.004e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `self == self`; total time: 1.286; iterations: 12500000; time: 1.029e-07 Dictionary size: 8; Type: frozendict; Statement: `self == self`; total time: 1.296; iterations: 12500000; time: 1.037e-07 Dictionary size: 8; Type: Map; Statement: `self == self`; total time: 0.403; iterations: 12500000; time: 3.223e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `repr(d)`; total time: 0.991; iterations: 375000; time: 2.643e-06 Dictionary size: 8; Type: frozendict; Statement: `repr(d)`; total time: 1.145; iterations: 375000; time: 3.052e-06 Dictionary size: 8; Type: Map; Statement: `repr(d)`; total time: 1.426; iterations: 375000; time: 3.802e-06 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `str(d)`; total time: 1.003; iterations: 375000; time: 2.676e-06 Dictionary size: 8; Type: frozendict; Statement: `str(d)`; total time: 1.156; iterations: 375000; time: 3.084e-06 Dictionary size: 8; Type: Map; Statement: `str(d)`; total time: 1.453; iterations: 375000; time: 3.876e-06 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 8; Type: dict; Statement: `class.fromkeys()`; total time: 1.075; iterations: 3125000; time: 3.441e-07 Dictionary size: 8; Type: frozendict; Statement: `class.fromkeys()`; total time: 1.083; iterations: 3125000; time: 3.464e-07 ################################################################################ //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `d.get(key)`; total time: 0.387; iterations: 13000000; time: 2.975e-08 Dictionary size: 1000; Type: frozendict; Statement: `d.get(key)`; total time: 0.386; iterations: 13000000; time: 2.971e-08 Dictionary size: 1000; Type: Map; Statement: `d.get(key)`; total time: 0.611; iterations: 13000000; time: 4.703e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `d[key]`; total time: 0.332; iterations: 10000000; time: 3.317e-08 Dictionary size: 1000; Type: frozendict; Statement: `d[key]`; total time: 0.333; iterations: 10000000; time: 3.328e-08 Dictionary size: 1000; Type: Map; Statement: `d[key]`; total time: 0.448; iterations: 10000000; time: 4.480e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `key in d`; total time: 0.552; iterations: 20000000; time: 2.760e-08 Dictionary size: 1000; Type: frozendict; Statement: `key in d`; total time: 0.582; iterations: 20000000; time: 2.911e-08 Dictionary size: 1000; Type: Map; Statement: `key in d`; total time: 0.599; iterations: 20000000; time: 2.996e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `key not in d`; total time: 0.561; iterations: 20000000; time: 2.807e-08 Dictionary size: 1000; Type: frozendict; Statement: `key not in d`; total time: 0.557; iterations: 20000000; time: 2.784e-08 Dictionary size: 1000; Type: Map; Statement: `key not in d`; total time: 0.645; iterations: 20000000; time: 3.224e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `pickle.dumps(d)`; total time: 0.677; iterations: 5000; time: 1.353e-04 Dictionary size: 1000; Type: frozendict; Statement: `pickle.dumps(d)`; total time: 0.672; iterations: 5000; time: 1.345e-04 Dictionary size: 1000; Type: Map; Statement: `pickle.dumps(d)`; total time: 1.049; iterations: 5000; time: 2.098e-04 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `pickle.loads(dump)`; total time: 0.557; iterations: 4000; time: 1.392e-04 Dictionary size: 1000; Type: frozendict; Statement: `pickle.loads(dump)`; total time: 0.622; iterations: 4000; time: 1.554e-04 Dictionary size: 1000; Type: Map; Statement: `pickle.loads(dump)`; total time: 1.312; iterations: 4000; time: 3.279e-04 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: frozendict; Statement: `hash(d)`; total time: 0.545; iterations: 10000000; time: 5.447e-08 Dictionary size: 1000; Type: Map; Statement: `hash(d)`; total time: 0.539; iterations: 10000000; time: 5.394e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `len(d)`; total time: 1.032; iterations: 20000000; time: 5.161e-08 Dictionary size: 1000; Type: frozendict; Statement: `len(d)`; total time: 1.035; iterations: 20000000; time: 5.177e-08 Dictionary size: 1000; Type: Map; Statement: `len(d)`; total time: 1.032; iterations: 20000000; time: 5.162e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `d.keys()`; total time: 0.907; iterations: 100000; time: 9.066e-06 Dictionary size: 1000; Type: frozendict; Statement: `d.keys()`; total time: 0.906; iterations: 100000; time: 9.055e-06 Dictionary size: 1000; Type: Map; Statement: `d.keys()`; total time: 1.699; iterations: 100000; time: 1.699e-05 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `d.values()`; total time: 0.964; iterations: 100000; time: 9.644e-06 Dictionary size: 1000; Type: frozendict; Statement: `d.values()`; total time: 0.962; iterations: 100000; time: 9.622e-06 Dictionary size: 1000; Type: Map; Statement: `d.values()`; total time: 1.701; iterations: 100000; time: 1.701e-05 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `d.items()`; total time: 0.842; iterations: 50000; time: 1.684e-05 Dictionary size: 1000; Type: frozendict; Statement: `d.items()`; total time: 0.833; iterations: 50000; time: 1.666e-05 Dictionary size: 1000; Type: Map; Statement: `d.items()`; total time: 1.669; iterations: 50000; time: 3.338e-05 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `iter(d)`; total time: 0.918; iterations: 100000; time: 9.183e-06 Dictionary size: 1000; Type: frozendict; Statement: `iter(d)`; total time: 0.906; iterations: 100000; time: 9.065e-06 Dictionary size: 1000; Type: Map; Statement: `iter(d)`; total time: 1.703; iterations: 100000; time: 1.703e-05 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `constructor(dict)`; total time: 0.214; iterations: 10000; time: 2.140e-05 Dictionary size: 1000; Type: frozendict; Statement: `constructor(dict)`; total time: 0.214; iterations: 10000; time: 2.139e-05 Dictionary size: 1000; Type: Map; Statement: `constructor(dict)`; total time: 1.718; iterations: 10000; time: 1.718e-04 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `constructor(d.items())`; total time: 0.326; iterations: 10000; time: 3.260e-05 Dictionary size: 1000; Type: frozendict; Statement: `constructor(d.items())`; total time: 0.329; iterations: 10000; time: 3.294e-05 Dictionary size: 1000; Type: Map; Statement: `constructor(d.items())`; total time: 1.617; iterations: 10000; time: 1.617e-04 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `constructor(**d)`; total time: 0.108; iterations: 5000; time: 2.168e-05 Dictionary size: 1000; Type: frozendict; Statement: `constructor(**d)`; total time: 0.108; iterations: 5000; time: 2.165e-05 Dictionary size: 1000; Type: Map; Statement: `constructor(**d)`; total time: 0.854; iterations: 5000; time: 1.707e-04 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `constructor(self)`; total time: 1.066; iterations: 50000; time: 2.132e-05 Dictionary size: 1000; Type: frozendict; Statement: `constructor(self)`; total time: 0.002; iterations: 50000; time: 4.366e-08 Dictionary size: 1000; Type: Map; Statement: `constructor(self)`; total time: 0.003; iterations: 50000; time: 6.227e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `d.copy()`; total time: 0.635; iterations: 100000; time: 6.348e-06 Dictionary size: 1000; Type: frozendict; Statement: `d.copy()`; total time: 0.003; iterations: 100000; time: 3.495e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `d1 == d2`; total time: 1.270; iterations: 100000; time: 1.270e-05 Dictionary size: 1000; Type: frozendict; Statement: `d1 == d2`; total time: 1.280; iterations: 100000; time: 1.280e-05 Dictionary size: 1000; Type: Map; Statement: `d1 == d2`; total time: 0.004; iterations: 100000; time: 3.928e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `self == self`; total time: 1.262; iterations: 100000; time: 1.262e-05 Dictionary size: 1000; Type: frozendict; Statement: `self == self`; total time: 1.278; iterations: 100000; time: 1.278e-05 Dictionary size: 1000; Type: Map; Statement: `self == self`; total time: 0.003; iterations: 100000; time: 3.210e-08 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `repr(d)`; total time: 0.716; iterations: 3000; time: 2.386e-04 Dictionary size: 1000; Type: frozendict; Statement: `repr(d)`; total time: 0.804; iterations: 3000; time: 2.680e-04 Dictionary size: 1000; Type: Map; Statement: `repr(d)`; total time: 1.180; iterations: 3000; time: 3.934e-04 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `str(d)`; total time: 0.712; iterations: 3000; time: 2.374e-04 Dictionary size: 1000; Type: frozendict; Statement: `str(d)`; total time: 0.798; iterations: 3000; time: 2.660e-04 Dictionary size: 1000; Type: Map; Statement: `str(d)`; total time: 1.179; iterations: 3000; time: 3.931e-04 //////////////////////////////////////////////////////////////////////////////// Dictionary size: 1000; Type: dict; Statement: `class.fromkeys()`; total time: 0.900; iterations: 25000; time: 3.600e-05 Dictionary size: 1000; Type: frozendict; Statement: `class.fromkeys()`; total time: 0.511; iterations: 25000; time: 2.045e-05 Some considerations: 1. copy() and frozendict(a_frozendict) are faster. This is expected, since they simply returns the same frozendict, as frozenset and tuple 2. pickle.loads is slower. This is expected too, since my pickle implementation for frozendict is very quick and dirty... 3. immutables.Map seems to be faster in equal comparison, but only because it does not implement it. 4. the other operations have the same performance. Again, this is expected since no optimization was done. From cs at cskk.id.au Tue Jul 14 20:23:09 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 15 Jul 2020 10:23:09 +1000 Subject: A rule for your twitlist/mailing list In-Reply-To: References: Message-ID: <20200715002309.GA65778@cskk.homeip.net> On 14Jul2020 08:49, Nomen Nescio wrote: >Where path includes "google.com" and subject includes "solutions" or >"test", delete..... > >99 percent of the junk just ..... gone ..... feels so good > >I wish Google would still let you subscribe to the newsgroup and >recieve updates in your inbox - that way I can mark the testbanks as >"spam" > >Is the mailing list for comp.lang.python still open? If you mean the python-list mailing list, yes. It is what I use, and it does not suffer from the spam you describe. Here: https://mail.python.org/mailman/listinfo/python-list It gateways with the newsgroup, but has much better spam qualities. Cheers, Cameron Simpson From info at wingware.com Wed Jul 15 00:15:17 2020 From: info at wingware.com (Wingware) Date: Wed, 15 Jul 2020 00:15:17 -0400 Subject: ANN: Wing Python IDE 7.2.3 has been released Message-ID: <5F0E82D5.2040504@wingware.com> Wing 7.2.3 has been released. This update introduces a How-To for using Wing with PyXLL, adds folding in .pyi and .pi files, fixes opening files from the macOS Catalina Finder, and makes many usability improvements. For details see the change log: https://wingware.com/pub/wingpro/7.2.3.0/CHANGELOG.txt == New features in Wing 7.2 include == * Auto-Reformatting with Black and YAPF (Wing Pro) Wing 7.2 adds support for Black and YAPF for code reformatting, in addition to the previously available built-in autopep8 reformatting. To use Black or YAPF, they must first be installed into your Python with pip, conda, or other package manager. Reformatting options are available from the Source > Reformatting menu group, and automatic reformatting may be configured in the Editor > Auto-reformatting preferences group. Details: https://wingware.com/doc/edit/auto-reformatting * Improved Support for Virtualenv Wing 7.2 improves support for virtualenv by allowing the command that activates the environment to be entered in the Python Executable in Project Properties, Launch Configurations, and when creating new projects. The New Project dialog now also includes the option to create a new virtualenv along with the new project, optionally specifying packages to install. Details: https://wingware.com/doc/howtos/virtualenv * Support for Anaconda Environments Similarly, Wing 7.2 adds support for Anaconda environments, so the conda activate command can be entered when configuring the Python Executable and the New Project dialog supports using an existing Anaconda environment or creating a new one along with the project. Details: https://wingware.com/doc/howtos/anaconda * And More Wing 7.2 also introduces How-Tos for using Wing with AWS and PyXLL, makes it easier to debug modules with python -m, adds support for Python 3 enums, simplifies manual configuration of remote debugging, allows using a command line for the configured Python Executable, supports constraining Find Uses of imported symbols to only the current file, allows folding .pyi and .pi files, and makes a number of usability and stability improvements. For a complete list of new features in Wing 7, see What's New in Wing 7: https://wingware.com/wingide/whatsnew == Downloads == Wing Pro: https://wingware.com/downloads/wing-pro/7.2/binaries Wing Personal: https://wingware.com/downloads/wing-personal/7.2/binaries Wing 101: https://wingware.com/downloads/wing-101/7.2/binaries Compare products: https://wingware.com/downloads See https://wingware.com/doc/install/upgrading for details on upgrading from Wing 6 and earlier, and https://wingware.com/doc/install/migrating for a list of compatibility notes. From songofacandy at gmail.com Wed Jul 15 02:07:07 2020 From: songofacandy at gmail.com (Inada Naoki) Date: Wed, 15 Jul 2020 15:07:07 +0900 Subject: frozendict: an experiment In-Reply-To: References: Message-ID: On Wed, Jul 15, 2020 at 2:01 AM Marco Sulla wrote: > > > Why do you think I do not need views to use the frozendict? > > I thought that is what make d.key(), d.items() etc work? > > Views for dict exist because dict is mutable. See this example: > > >>> d = {1: 2} > >>> keys = d.keys() > >>> d[2] = 3 > >>> keys > dict_keys([1, 2]) > > As you see, even if you modified the dict __after__ you created the > keys view, the view returns also the new key, 2. > This is desirable for a mutable object, but it's not needed for an > immutable one. frozendict could create lazily an object that contains > all its keys and cache it. I don't think so. The view objects are useful when we need a set-like operation. (e.g. `assert d.keys() == {"spam", "egg"}`) There is no difference between mutable and immutable dicts. -- Inada Naoki From grant.b.edwards at gmail.com Tue Jul 14 22:51:15 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 15 Jul 2020 02:51:15 -0000 (UTC) Subject: A rule for your twitlist/mailing list References: <20200715002309.GA65778@cskk.homeip.net> Message-ID: On 2020-07-15, Cameron Simpson wrote: > On 14Jul2020 08:49, Nomen Nescio wrote: >>Is the mailing list for comp.lang.python still open? > > If you mean the python-list mailing list, yes. It is what I use, and it > does not suffer from the spam you describe. Here: > > https://mail.python.org/mailman/listinfo/python-list > > It gateways with the newsgroup, but has much better spam qualities. And if you prefer to read the mailing list with an NNTP client, you can point your favorite newsreader at news.gmane.org and subscribe to gmane.comp.python.general -- Grant From songofacandy at gmail.com Thu Jul 16 00:10:39 2020 From: songofacandy at gmail.com (Inada Naoki) Date: Thu, 16 Jul 2020 13:10:39 +0900 Subject: frozendict: an experiment In-Reply-To: References: Message-ID: On Thu, Jul 16, 2020 at 2:32 AM Marco Sulla wrote: > > On Wed, 15 Jul 2020 at 08:07, Inada Naoki wrote: > > I don't think so. The view objects are useful when we need a set-like > > operation. (e.g. `assert d.keys() == {"spam", "egg"}`) > > Yes, but, instead of creating a view, you can create and cache the > pointer of a "real" object, that implements the dict view API. > For example, keys for a frozendict could be an "ordered" frozenset. > This "oset" could be a frozendict, which values are the keys and the > keys are the key hashes (as set). > I am not sure about what are you saying. Does it really solve the usage of dict views? How about my example? (`assert d.keys() == {"spam", "egg"}`) > On Wed, 15 Jul 2020 at 08:07, Inada Naoki wrote: > > There is no difference between mutable and immutable dicts. > > There's a huge difference, and it's in the contract. As I said, if we > assume that a frozendict is immutable, we can optimize its speed. > Furthermore, currently no real functional programming can be done in > Python with dicts. Oh, ! am talking about dict views. I meant there is no difference between "how dict view is useful for dict" and "how dict view is useful for frozendict". But I am still not sure about the optimizations and functional programming you are talking about. Please elaborate more, please? -- Inada Naoki From vincent at vincentdavis.net Thu Jul 16 12:46:41 2020 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 16 Jul 2020 10:46:41 -0600 Subject: How to match scipy.spatial.distance results back to pandas df Message-ID: I am trying to find points in the activity that are near points in segment. I get the results from distance() and what to identify the points in segment and activity that are within some value of each other .0001 for example. One idea I had was to append each array row (or column) to the corresponding row in the df after converting it to a dict so that I can lookup the point in the other df. Any suggestions, ideas? from scipy.spatial import distance a = distance.cdist(segment[['Latitude', 'Longitude']], activity[['Latitude', 'Longitude']], 'euclidean') b = a[a < .0001] b array([8.83911760e-05, 6.31347765e-05, 3.89486842e-05, 2.13775583e-05, 2.10950231e-05, 4.10487515e-05, 6.70000000e-05, 9.10878697e-05, 7.61183289e-05, 9.90050504e-05, 7.88162420e-05, 5.90931468e-05, 4.50111097e-05, 4.97393205e-05, 6.78969808e-05, 8.52115016e-05, ... Thanks Vincent Davis 720-301-3003 *Want to get a hold of me?* *SMS: awesome.phone: ok...* *email: bad!* From jf_byrnes at comcast.net Wed Jul 15 12:46:41 2020 From: jf_byrnes at comcast.net (Jim) Date: Wed, 15 Jul 2020 11:46:41 -0500 Subject: A rule for your twitlist/mailing list In-Reply-To: References: <20200715002309.GA65778@cskk.homeip.net> Message-ID: On 7/14/20 9:51 PM, Grant Edwards wrote: > On 2020-07-15, Cameron Simpson wrote: >> On 14Jul2020 08:49, Nomen Nescio wrote: > >>> Is the mailing list for comp.lang.python still open? >> >> If you mean the python-list mailing list, yes. It is what I use, and it >> does not suffer from the spam you describe. Here: >> >> https://mail.python.org/mailman/listinfo/python-list >> >> It gateways with the newsgroup, but has much better spam qualities. > > And if you prefer to read the mailing list with an NNTP client, you > can point your favorite newsreader at news.gmane.org and subscribe to > gmane.comp.python.general > > -- > Grant > I think that should now be news.gmane.io, at least that's how I get comp.python. I think gmane.org shut down. Regards, Jim From Marco.Sulla.Python at gmail.com Wed Jul 15 13:31:48 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Wed, 15 Jul 2020 19:31:48 +0200 Subject: frozendict: an experiment In-Reply-To: References: Message-ID: On Wed, 15 Jul 2020 at 08:07, Inada Naoki wrote: > I don't think so. The view objects are useful when we need a set-like > operation. (e.g. `assert d.keys() == {"spam", "egg"}`) Yes, but, instead of creating a view, you can create and cache the pointer of a "real" object, that implements the dict view API. For example, keys for a frozendict could be an "ordered" frozenset. This "oset" could be a frozendict, which values are the keys and the keys are the key hashes (as set). On Wed, 15 Jul 2020 at 08:07, Inada Naoki wrote: > There is no difference between mutable and immutable dicts. There's a huge difference, and it's in the contract. As I said, if we assume that a frozendict is immutable, we can optimize its speed. Furthermore, currently no real functional programming can be done in Python with dicts. From Marco.Sulla.Python at gmail.com Thu Jul 16 13:16:19 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Thu, 16 Jul 2020 19:16:19 +0200 Subject: frozendict: an experiment In-Reply-To: References: Message-ID: On Thu, 16 Jul 2020 at 06:11, Inada Naoki wrote: > On Thu, Jul 16, 2020 at 2:32 AM Marco Sulla > wrote: > > Yes, but, instead of creating a view, you can create and cache the > > pointer of a "real" object, that implements the dict view API. > > For example, keys for a frozendict could be an "ordered" frozenset. > > This "oset" could be a frozendict > I am not sure about what are you saying. > Does it really solve the usage of dict views? > How about my example? (`assert d.keys() == {"spam", "egg"}`) Well, if the frozendict "views" will implement the full API of the dict views, your assert and all the existing code will continue to work. The difference will be that views *could* be faster. > > On Wed, 15 Jul 2020 at 08:07, Inada Naoki wrote: > Oh, ! am talking about dict views. I meant there is no difference > between "how dict view is useful for dict" and "how dict view is > useful for frozendict". > > But I am still not sure about the optimizations and functional > programming you are talking about. > Please elaborate more, please? About frozendict optimization an immutable dict could be optimized in different ways in Python: 1. as I said, views can be replaced with "real", cached objects. This will speed up subsequent calls to keys() etc. 2. as tuples and strings, small frozendicts can be interned in a cache. The same cache can be used to return a cached frozendict instead of recreate it, as tuples. 3. many python internals uses a mapping proxy to a dict, to avoid its modification. A frozendict can be used instead. 4. dicts can use a split table or a combined table. This is useful for maintaining insertion order upon deletion and insertion. This is not required for frozendicts, since once created they can't be modified. frozendicts can be all split or all combined dicts. So in theory frozendicts could be created with the max useful size, without resizing them, add the keys and values and then remove the unused. This could speed up creation. About functional programming Well, pure functional programming requires no side effects: https://en.wikipedia.org/wiki/Functional_programming Object mutability is a side effect. Pure functional programming uses only immutable objects. In Python, pure functional programming is impossible, since even functions are (partially) mutable objects. But Python has a lot of functional programming features: https://docs.python.org/3/howto/functional.html Every builtin mutable data type has its immutable counterpart now, dict apart. And types.MappingProxyType is not usable in real world, since it's really slow. From grant.b.edwards at gmail.com Thu Jul 16 16:03:34 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 16 Jul 2020 20:03:34 -0000 (UTC) Subject: A rule for your twitlist/mailing list References: <20200715002309.GA65778@cskk.homeip.net> Message-ID: On 2020-07-15, Jim wrote: > On 7/14/20 9:51 PM, Grant Edwards wrote: >> On 2020-07-15, Cameron Simpson wrote: >>> On 14Jul2020 08:49, Nomen Nescio wrote: >> >>>> Is the mailing list for comp.lang.python still open? >>> >>> If you mean the python-list mailing list, yes. It is what I use, and it >>> does not suffer from the spam you describe. Here: >>> >>> https://mail.python.org/mailman/listinfo/python-list >>> >>> It gateways with the newsgroup, but has much better spam qualities. >> >> And if you prefer to read the mailing list with an NNTP client, you >> can point your favorite newsreader at news.gmane.org and subscribe to >> gmane.comp.python.general > > I think that should now be news.gmane.io, at least that's how I get > comp.python. I think gmane.org shut down. You're right. I was looking at an old entry in my slrn config file. -- Grant From songofacandy at gmail.com Thu Jul 16 22:13:10 2020 From: songofacandy at gmail.com (Inada Naoki) Date: Fri, 17 Jul 2020 11:13:10 +0900 Subject: frozendict: an experiment In-Reply-To: References: Message-ID: On Fri, Jul 17, 2020 at 2:16 AM Marco Sulla wrote: > > On Thu, 16 Jul 2020 at 06:11, Inada Naoki wrote: > > On Thu, Jul 16, 2020 at 2:32 AM Marco Sulla > > wrote: > > > Yes, but, instead of creating a view, you can create and cache the > > > pointer of a "real" object, that implements the dict view API. > > > For example, keys for a frozendict could be an "ordered" frozenset. > > > This "oset" could be a frozendict > > I am not sure about what are you saying. > > Does it really solve the usage of dict views? > > How about my example? (`assert d.keys() == {"spam", "egg"}`) > > Well, if the frozendict "views" will implement the full API of the > dict views, your assert and all the existing code will continue to > work. > The difference will be that views *could* be faster. > Then, there is no reason to not support the view for frozendict? > > > On Wed, 15 Jul 2020 at 08:07, Inada Naoki wrote: > About frozendict optimization > > an immutable dict could be optimized in different ways in Python: > 1. as I said, views can be replaced with "real", cached objects. This > will speed up subsequent calls to keys() etc. I don't think it is an interesting optimization. > 2. as tuples and strings, small frozendicts can be interned in a > cache. The same cache can be used to return a cached frozendict > instead of recreate it, as tuples. I am not sure tuple is "internined" or just "merged". (I don't know precise definition of the "interning"). Tuples are merged while compiling. ``` for a in ["foo", "bar"]: # compiler convert this list to tuple ... for b in ("foo", "bar"): # and compiler merge same tuple ... ``` But when frozendicts are merged? I think there is a very little chance. > 3. many python internals uses a mapping proxy to a dict, to avoid its > modification. A frozendict can be used instead. Are they used frequently in performance critical path? Could you point some concrete examples? > 4. dicts can use a split table or a combined table. This is useful for > maintaining insertion order upon deletion and insertion. > This is not required for frozendicts, since once created they can't > be modified. frozendicts can be all split or all combined dicts Key-sharing dict vs regular dict are not relating to insertion order. Key-sharing dict is implemented before insertion order keeping dict. And when I implemented order preserving dict, key-sharing dict is very difficult to maintain. I even wanted to drop key-sharing dict support. I'm OK to all combined dict for frozen dict. But I think key-sharing is still interesting optimization for frozen dict. And supporting key-sharing dict is much easier for frozendict than for mutable dict. > > About functional programming > > Well, pure functional programming requires no side effects: > https://en.wikipedia.org/wiki/Functional_programming > Object mutability is a side effect. Pure functional programming uses > only immutable objects. > In Python, pure functional programming is impossible, since even > functions are (partially) mutable objects. But Python has a lot of > functional programming features: > https://docs.python.org/3/howto/functional.html > Every builtin mutable data type has its immutable counterpart now, > dict apart. And types.MappingProxyType is not usable in real world, > since it's really slow. I feel this motivation is too theorical. And theorically, I don't think Python should add bultin type for pure functional programming. Python should focus only Pytohnic programming. Would you provide some concrete examples how frozendict can improve Python code significantly? -- Inada Naoki From stackflowauto at gmail.com Thu Jul 16 22:38:09 2020 From: stackflowauto at gmail.com (stack flow) Date: Thu, 16 Jul 2020 19:38:09 -0700 (PDT) Subject: excel (multiple sheets) to yml file for each sheet Message-ID: Hi, I have excel file with multiple sheets and need output as yml file for each sheet. could someone help me with python code? following is an example: aep sheet: aep aep_description infra_vlan test_AEP test aep no aeps_to_domain sheet: aep domain domain_type test_AEP test_PHY_DOM phys test1_AEP test1_PHY_DOM l3dom scription should output two files: aeps-vars.yml: aeps: - aep: test_AEP aep_description: test aep infra_vlan: no aeps_to_domain-vars.yml: aeps_to_domain: - aep: test_AEP domain: test_PHY_DOM domain_type: phys - aep: test_AEP domain: test_L3O_DOM domain_type: l3dom From bill at baddogconsulting.com Thu Jul 16 23:24:04 2020 From: bill at baddogconsulting.com (Bill Deegan) Date: Thu, 16 Jul 2020 20:24:04 -0700 Subject: SCons 4.0.1 Released Message-ID: A new SCons release, 4.0.1, is now available on the SCons download page: https://scons.org/pages/download.html Here is a summary of the changes since 4.0.1: NEW FUNCTIONALITY - Added Environment() variable TEMPFILEDIR which allows setting the directory which temp files createdby TEMPFILEMUNGE are created in. DEPRECATED FUNCTIONALITY - N/A CHANGED/ENHANCED EXISTING FUNCTIONALITY - N/A FIXES - Fix fortran tools to set SHFORTRAN variables to $FORTRAN, similarly SHF77, SHF90, SHF95, SHF03 and SHF08 will default to the variables $F77, $F90, $F95, $F03 and $F08 respectively. If you were depending on changing the value of FORTRAN (or $F[0-9][0-9]) having no effect on the value of SHFORTRAN, this change will break that. The values of FORTRAN, F77, F90, F95, F03, F08 and SHFORTRAN, SHF77 (etc.) now are not overridden in generate if alredy set by the user. - Fix subprocess execution of 'lslpp' on AIX to produce text standard i/o. - Re-do the fix for suncxx tool (Oracle Studio compiler) now that only Python 3 is supported, to avoid decoding errors. IMPROVEMENTS - N/A PACKAGING - N/A DOCUMENTATION - N/A DEVELOPMENT - N/A Thanks to the following contributors listed below for their contributions to this release. git shortlog --no-merges -ns 4.0.0..HEAD 12 William Deegan 2 Rob Boehne 1 Clemens Tolboom From mal at europython.eu Fri Jul 17 03:51:13 2020 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 17 Jul 2020 09:51:13 +0200 Subject: EuroPython 2020: Find a new job at the conference Message-ID: <14684367-cbd0-a544-7f03-f052da10918c@europython.eu> We?d like to draw your attention to our job board, with plenty of job ads from our sponsors: * EuroPython 2020 Job Board * https://ep2020.europython.eu/sponsor/job-board/ Our sponsors would love to get in touch with you, so please have a look and visit them at their sponsor exhibit channel on Discord or contact them via the links and email addresses given on the page. Job ad emails ------------- We will also send out job ad emails to attendees who have agreed to receiving these emails. If you are interested, please log in, go to your profile and enable the recruiting email option in the privacy section: https://ep2020.europython.eu/user-panel/privacy-settings/ Note that we will not give your email addresses to sponsors, but only send out these emails on behalf of them. Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/post/623783726150778880/europython-2020-find-a-new-j$ Tweet: https://twitter.com/europython/status/1283720815146565632 Thanks, -- EuroPython 2020 Team https://ep2020.europython.eu/ https://www.europython-society.org/ From jorge.conforte at inpe.br Fri Jul 17 11:36:53 2020 From: jorge.conforte at inpe.br (J Conrado) Date: Fri, 17 Jul 2020 12:36:53 -0300 Subject: Python pandas Excel Message-ID: <42ba64c1-6e3d-50f4-2b52-48ee1cae4833@inpe.br> HI, I have an excel file with several columns, the first day/month,/year and hour: Data 01/11/2017 00:00 01/11/2017 03:00 01/11/2017 06:00 01/11/2017 09:00 01/11/2017 12:00 01/11/2017 15:00 01/11/2017 18:00 01/11/2017 21:00 02/11/2017 00:00 02/11/2017 03:00 02/11/2017 06:00 02/11/2017 09:00 02/11/2017 12:00 02/11/2017 15:00 02/11/2017 18:00 02/11/2017 21:00 03/11/2017 00:00 03/11/2017 03:00 03/11/2017 06:00 03/11/2017 09:00 03/11/2017 12:00 03/11/2017 15:00 03/11/2017 18:00 03/11/2017 21:00 04/11/2017 00:00 04/11/2017 03:00 04/11/2017 06:00 04/11/2017 09:00 04/11/2017 12:00 04/11/2017 15:00 04/11/2017 18:00 04/11/2017 21:00 05/11/2017 00:00 05/11/2017 03:00 05/11/2017 06:00 05/11/2017 09:00 05/11/2017 12:00 05/11/2017 15:00 05/11/2017 18:00 05/11/2017 21:00 06/11/2017 00:00 06/11/2017 03:00 06/11/2017 06:00 06/11/2017 09:00 06/11/2017 12:00 06/11/2017 15:00 06/11/2017 18:00 06/11/2017 21:00 07/11/2017 00:00 07/11/2017 03:00 07/11/2017 06:00 07/11/2017 09:00 07/11/2017 12:00 07/11/2017 15:00 07/11/2017 18:00 07/11/2017 21:00 08/11/2017 00:00 08/11/2017 03:00 08/11/2017 06:00 08/11/2017 09:00 08/11/2017 12:00 08/11/2017 15:00 08/11/2017 21:00 09/11/2017 00:00 09/11/2017 03:00 09/11/2017 06:00 09/11/2017 09:00 09/11/2017 12:00 09/11/2017 15:00 09/11/2017 18:00 09/11/2017 21:00 10/11/2017 00:00 10/11/2017 03:00 10/11/2017 06:00 10/11/2017 09:00 10/11/2017 12:00 10/11/2017 15:00 10/11/2017 18:00 10/11/2017 21:00 11/11/2017 00:00 11/11/2017 03:00 11/11/2017 06:00 11/11/2017 09:00 11/11/2017 12:00 11/11/2017 15:00 11/11/2017 18:00 11/11/2017 21:00 12/11/2017 00:00 12/11/2017 03:00 12/11/2017 06:00 12/11/2017 09:00 12/11/2017 12:00 12/11/2017 15:00 12/11/2017 18:00 12/11/2017 21:00 13/11/2017 00:00 13/11/2017 03:00 13/11/2017 06:00 13/11/2017 09:00 13/11/2017 12:00 13/11/2017 15:00 13/11/2017 18:00 13/11/2017 21:00 14/11/2017 00:00 14/11/2017 03:00 14/11/2017 06:00 14/11/2017 09:00 14/11/2017 12:00 14/11/2017 15:00 14/11/2017 18:00 14/11/2017 21:00 15/11/2017 00:00 15/11/2017 03:00 15/11/2017 06:00 15/11/2017 09:00 15/11/2017 12:00 15/11/2017 15:00 15/11/2017 18:00 15/11/2017 21:00 16/11/2017 00:00 16/11/2017 03:00 16/11/2017 06:00 16/11/2017 09:00 16/11/2017 12:00 16/11/2017 15:00 16/11/2017 18:00 16/11/2017 21:00 17/11/2017 00:00 17/11/2017 03:00 17/11/2017 06:00 17/11/2017 09:00 17/11/2017 12:00 17/11/2017 15:00 17/11/2017 18:00 18/11/2017 00:00 18/11/2017 03:00 18/11/2017 06:00 18/11/2017 09:00 18/11/2017 12:00 18/11/2017 15:00 18/11/2017 18:00 18/11/2017 21:00 19/11/2017 00:00 19/11/2017 03:00 19/11/2017 06:00 19/11/2017 09:00 19/11/2017 12:00 19/11/2017 15:00 19/11/2017 18:00 19/11/2017 21:00 20/11/2017 00:00 20/11/2017 03:00 20/11/2017 06:00 20/11/2017 09:00 20/11/2017 12:00 20/11/2017 15:00 20/11/2017 18:00 20/11/2017 21:00 21/11/2017 00:00 21/11/2017 03:00 21/11/2017 06:00 21/11/2017 09:00 21/11/2017 12:00 21/11/2017 15:00 21/11/2017 18:00 22/11/2017 03:00 22/11/2017 06:00 22/11/2017 09:00 22/11/2017 12:00 22/11/2017 15:00 22/11/2017 18:00 22/11/2017 21:00 23/11/2017 00:00 23/11/2017 03:00 23/11/2017 06:00 23/11/2017 09:00 23/11/2017 12:00 23/11/2017 15:00 23/11/2017 18:00 23/11/2017 21:00 24/11/2017 00:00 24/11/2017 03:00 24/11/2017 06:00 24/11/2017 09:00 24/11/2017 12:00 24/11/2017 15:00 24/11/2017 18:00 24/11/2017 21:00 25/11/2017 00:00 25/11/2017 03:00 25/11/2017 06:00 25/11/2017 09:00 25/11/2017 12:00 25/11/2017 15:00 25/11/2017 18:00 25/11/2017 21:00 26/11/2017 00:00 26/11/2017 03:00 26/11/2017 06:00 26/11/2017 09:00 26/11/2017 12:00 26/11/2017 15:00 26/11/2017 18:00 26/11/2017 21:00 27/11/2017 03:00 27/11/2017 06:00 27/11/2017 09:00 27/11/2017 12:00 27/11/2017 15:00 27/11/2017 18:00 27/11/2017 21:00 28/11/2017 06:00 28/11/2017 09:00 28/11/2017 12:00 28/11/2017 15:00 28/11/2017 18:00 28/11/2017 21:00 29/11/2017 00:00 29/11/2017 03:00 29/11/2017 06:00 29/11/2017 09:00 29/11/2017 12:00 29/11/2017 15:00 29/11/2017 18:00 29/11/2017 21:00 30/11/2017 00:00 30/11/2017 03:00 30/11/2017 06:00 30/11/2017 09:00 30/11/2017 12:00 30/11/2017 15:00 30/11/2017 18:00 30/11/2017 21:00 This is the value tha a have using pandas: print(data) 0???? 2017-01-11 00:00:00 1???? 2017-01-11 03:00:00 2???? 2017-01-11 06:00:00 3???? 2017-01-11 09:00:00 4???? 2017-01-11 12:00:00 ????????????? ... 228?? 2017-11-30 09:00:00 229?? 2017-11-30 12:00:00 230?? 2017-11-30 15:00:00 231?? 2017-11-30 18:00:00 232?? 2017-11-30 21:00:00 Please, how can I get four arrays for day, month, year and hour this column of my excel. : Conrado From Gazu at freoeo.net Fri Jul 17 12:02:15 2020 From: Gazu at freoeo.net (Gazu) Date: Fri, 17 Jul 2020 16:02:15 -0000 (UTC) Subject: Fake news Detect Message-ID: Hey Guys I am new to python and i am building a fake news detection system my goal is that when some one post a news the system will check it by searching that news on Web and find solution that whether that news is Fake or Not. But the issue is that i have no idea how to search on Web or which algorithm to use. However i know about web scrapping and other stuff, so guys help me out on this by giving your remarks. thanks in advance. From shanmisugu8897 at outlook.com Fri Jul 17 03:22:18 2020 From: shanmisugu8897 at outlook.com (Shanmika Sugavaneswaran) Date: Fri, 17 Jul 2020 07:22:18 +0000 Subject: Issues in downloading python Message-ID: Though I install the setup , I couldn?t find Python in my system . I don?t know what cause the problem. Please help me! Sent from Mail for Windows 10 From info at cmcc.it Fri Jul 17 08:49:51 2020 From: info at cmcc.it (CMCC Info) Date: Fri, 17 Jul 2020 14:49:51 +0200 Subject: Web Developer | Job position at CMCC Foundation, Italy Message-ID: <0f2fb1a1-1ba9-79f2-33a0-361b8520a0b8@cmcc.it> /Please, feel free to circulate //to anyone you think may be interested./// -- Web Developer (code 11648*)* *Deadline: **23/08/2020* The CMCC is taking into consideration the possibility to hire a talented, motivated and proactive Web Developer to support research and development activities. This job announcement is a public invitation to express interest for the above mentioned CMCC Position. ?The location of reference is CMCC premises in Lecce, Italy. The primary purposes for this position are to support the CMCC Communication and Media Office in the design, development, realization, and maintenance of websites and web-based products and initiatives that are aimed at: - disseminating the CMCC?s scientific research and its outcomes - exploring innovative languages to communicate climate science to a vast and diversified audience. _The desired qualifications are:_ ??? Experience in WordPress websites, themes and plugins development and maintenance; ??? Experience with web tools and languages like HTML, CSS3, SASS, JavaScript and PHP, SQL programming languages and good attitude to learn new tools and software languages and paradigms; ??? Experience with Unix/Linux and MAC OS Systems; ??? Experience with computer graphics software: raster and vector graphic; ??? Experience with development tools (github, docker, pipelines building tools); ??? Experience with remote collaboration and office tools like GSuite and good attitude in working with teams; ??? Fluency in English language; ??? Attitude to work remotely and availability to take part in meeting in presence and in videoconference; ??? Willing to travel in Italy and abroad. _Appreciated qualifications and skills:_ ??? Competencies in sysadmin tasks for GNU/Linux systems; ??? Experience with frontend frameworks and libraries (like React, jQuery, d3.js); ??? Experience of devops tools like terraform, ansible; ??? Experience with cloud services providers (AWS, Google Cloud); ??? Experience with backend environments like Node.js; ??? Experience with the Clojure/ClojureScript language. Belonging to legally protected categories (ex L. 68/99) will constitute a preferential condition. The initial appointment is for 12 months starting from September 2020 at an annual salary ranging from 20K to 30K Euros, comprehensive of benefits, depending on qualification and experience. *How to Apply* Applicants should register to CMCC JAM (Job Application Manager) website and fill the online form following the link below: http://jam.cmcc.it/careers/apply/11648/ -- Fondazione Centro Euro-Mediterraneo sui Cambiamenti Climatici Web: www.cmcc.it - Contact us: info at cmcc.it From abhi.darkness at gmail.com Fri Jul 17 13:09:52 2020 From: abhi.darkness at gmail.com (Abhiram R) Date: Fri, 17 Jul 2020 22:39:52 +0530 Subject: Issues in downloading python In-Reply-To: References: Message-ID: It's most likely because you haven't added Python to your environment PATH variable. The easiest path forward is to uninstall it from Applications and then when you reinstall, tick the option on the bottom of the first splash screen of the installer. It will add Python to your PATH variable automatically and you should be able to access it from CMD after that. Regards Abhiram R On Fri, Jul 17, 2020 at 10:28 PM Shanmika Sugavaneswaran < shanmisugu8897 at outlook.com> wrote: > Though I install the setup , I couldn?t find Python in my system . I don?t > know what cause the problem. Please help me! > > > > Sent from Mail for > Windows 10 > > -- > https://mail.python.org/mailman/listinfo/python-list > -- -Abhiram R From Gronicus at SGA.Ninja Fri Jul 17 13:16:58 2020 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 17 Jul 2020 13:16:58 -0400 Subject: Fake news Detect In-Reply-To: References: Message-ID: <006301d65c5e$14263da0$3c72b8e0$@SGA.Ninja> I posted a request for assistance about a week ago, no response. I also see very little traffic here, less than there used to be. Has something gone wrong with my set up? ---------------------------------------------------------------------------- ---------------- Footnote: There's 99 bugs in the code, in the code. 99 bugs in the code. Take one down and patch it all around. Now there's 117 bugs in the code. -----Original Message----- From: Python-list On Behalf Of Gazu Sent: Friday, July 17, 2020 12:02 PM To: python-list at python.org Subject: Fake news Detect Hey Guys I am new to python and i am building a fake news detection system my goal is that when some one post a news the system will check it by searching that news on Web and find solution that whether that news is Fake or Not. But the issue is that i have no idea how to search on Web or which algorithm to use. However i know about web scrapping and other stuff, so guys help me out on this by giving your remarks. thanks in advance. -- https://mail.python.org/mailman/listinfo/python-list From dokuwa2000 at yahoo.co.uk Fri Jul 17 13:54:51 2020 From: dokuwa2000 at yahoo.co.uk (Daley Okuwa) Date: Fri, 17 Jul 2020 17:54:51 +0000 (UTC) Subject: Issues in downloading python In-Reply-To: References: Message-ID: <1599388264.5108599.1595008491229@mail.yahoo.com> on linux or windows On Friday, 17 July 2020, 17:57:01 BST, Shanmika Sugavaneswaran wrote: Though I install the setup , I couldn?t find Python in my system . I don?t know what cause the problem. Please help me! Sent from Mail for Windows 10 -- https://mail.python.org/mailman/listinfo/python-list From mats at python.org Fri Jul 17 14:21:56 2020 From: mats at python.org (Mats Wichmann) Date: Fri, 17 Jul 2020 12:21:56 -0600 Subject: Issues in downloading python In-Reply-To: References: Message-ID: <0c2e5302-4862-a064-c12e-eca663530996@python.org> On 7/17/20 11:09 AM, Abhiram R wrote: > It's most likely because you haven't added Python to your environment PATH > variable. > > The easiest path forward is to uninstall it from Applications and then when > you reinstall, tick the option on the bottom of the first splash screen of > the installer. It will add Python to your PATH variable automatically and > you should be able to access it from CMD after that. > > Regards > Abhiram R The Python Launcher exists for this purpose. Otherwise, as Abhiram notes, you have to add to PATH, which on Windows is a bit of an irritant, because that path entry will change as the Python version changes (e.g. when you change from 3.8 to 3.9 you'll have a different default path location). Try locating Python by using the command py in a command shell (or in PowerShell). From Gronicus at SGA.Ninja Fri Jul 17 14:33:45 2020 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 17 Jul 2020 14:33:45 -0400 Subject: An I connected here? Message-ID: <007201d65c68$dad3b4f0$907b1ed0$@SGA.Ninja> Sorry folks, I really messed that one up. I tried to doctor up a reply to get the address correct but failed to delete enough to own the message... My message did not have anything to do with the "Fake News Detect" subject. I posted a request for assistance about a week ago, no response. I also see very little traffic here, less than there used to be. Has something gone wrong with my set up? My goof, sorry about that..... ---------------------------------------------------------------------------- ---------------- Footnote: There's 99 bugs in the code, in the code. 99 bugs in the code. Take one down and patch it all around. Now there's 117 bugs in the code. From xuanwu348 at 163.com Fri Jul 17 14:05:24 2020 From: xuanwu348 at 163.com (xuanwu348) Date: Sat, 18 Jul 2020 02:05:24 +0800 (CST) Subject: about the function in class Message-ID: <6deb9daf.44.1735df3ca4a.Coremail.xuanwu348@163.com> Hi, all There are some methods to define functions in a class, include member functions, static method, class method. My question is that which type of function for "decorate(f),diff_con(f)" I think these functions all were belong to member function, (f <-->self) f can be replace by self. but how to explain "decorate(f)", "@decorate(f)" if f == self; then in wrapper function: res = self(*args, **kwargs) and self means Diff_methods("somgthing") <==> Diff_methods("somgthing")(*args, **kwargs) But it's not correct. thanks lass Diff_methods: def __init__(self, something): self.something = something def decorate(f): @wraps(f) def wrapper(*args, **kwargs): start_time = time.time() res = f(*args, **kwargs) elapse = time.time() - start_time return res, elapse return wrapper def diff_con(f): print(f.something) @decorate def member_function(self, n): return 2 << n @staticmethod def static_function(): pass @classmethod def class_method(cls): pass if __name__ == "__main__": sssss = Diff_methods("something") print(sssss.member_function(10)) sssss.diff_con() From reto at labrat.space Fri Jul 17 12:50:52 2020 From: reto at labrat.space (Reto) Date: Fri, 17 Jul 2020 18:50:52 +0200 Subject: Fake news Detect In-Reply-To: References: Message-ID: <20200717165052.6iixyd3pbwufvyp3@feather.localdomain> What you want is called "natural language processing" and whole research papers have been written about this topic. Search your favorite research paper index for those keywords, say google scholar. From rhodri at kynesim.co.uk Fri Jul 17 14:59:33 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 17 Jul 2020 19:59:33 +0100 Subject: An I connected here? In-Reply-To: <007201d65c68$dad3b4f0$907b1ed0$@SGA.Ninja> References: <007201d65c68$dad3b4f0$907b1ed0$@SGA.Ninja> Message-ID: <7cf767f6-4c78-23a2-2aa9-ea0e1545f44f@kynesim.co.uk> On 17/07/2020 19:33, Steve wrote: > Sorry folks, I really messed that one up. I tried to doctor up a reply to > get the address correct but failed to delete enough to own the message... Yeah, don't do that. Just start a new message, otherwise you'll end up with all the threading for the old message thread, irritating those of us who sort by thread so that we aren't chopping and changing subject all the time :-/ > My message did not have anything to do with the "Fake News Detect" subject. > > I posted a request for assistance about a week ago, no response. I also see > very little traffic here, less than there used to be. Has something gone > wrong with my set up? No, nothing's wrong. I can't answer for anyone else and I can't recall your specific question, but I suspect you were asking about something I know nothing about and wasn't sufficiently intrigued to go find out about. I think there are fewer experts with time lurking around here (and I don't count myself as one of those, TBH). Recent controversies and the attempts to moderate them have probably upset quite a lot of people one way or another. -- Rhodri James *-* Kynesim Ltd From jpic at yourlabs.org Fri Jul 17 15:12:43 2020 From: jpic at yourlabs.org (J. Pic) Date: Fri, 17 Jul 2020 21:12:43 +0200 Subject: An I connected here? In-Reply-To: <7cf767f6-4c78-23a2-2aa9-ea0e1545f44f@kynesim.co.uk> References: <007201d65c68$dad3b4f0$907b1ed0$@SGA.Ninja> <7cf767f6-4c78-23a2-2aa9-ea0e1545f44f@kynesim.co.uk> Message-ID: And Hollidays ;) Le ven. 17 juil. 2020 ? 21:03, Rhodri James a ?crit : > On 17/07/2020 19:33, Steve wrote: > > Sorry folks, I really messed that one up. I tried to doctor up a reply > to > > get the address correct but failed to delete enough to own the message... > > Yeah, don't do that. Just start a new message, otherwise you'll end up > with all the threading for the old message thread, irritating those of > us who sort by thread so that we aren't chopping and changing subject > all the time :-/ > > > My message did not have anything to do with the "Fake News Detect" > subject. > > > > I posted a request for assistance about a week ago, no response. I also > see > > very little traffic here, less than there used to be. Has something gone > > wrong with my set up? > > No, nothing's wrong. I can't answer for anyone else and I can't recall > your specific question, but I suspect you were asking about something I > know nothing about and wasn't sufficiently intrigued to go find out about. > > I think there are fewer experts with time lurking around here (and I > don't count myself as one of those, TBH). Recent controversies and the > attempts to moderate them have probably upset quite a lot of people one > way or another. > > -- > Rhodri James *-* Kynesim Ltd > -- > https://mail.python.org/mailman/listinfo/python-list > From rhodri at kynesim.co.uk Fri Jul 17 15:20:20 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 17 Jul 2020 20:20:20 +0100 Subject: An I connected here? In-Reply-To: References: <007201d65c68$dad3b4f0$907b1ed0$@SGA.Ninja> <7cf767f6-4c78-23a2-2aa9-ea0e1545f44f@kynesim.co.uk> Message-ID: On 17/07/2020 20:12, J. Pic wrote: > And Hollidays ;) Nah, that's next week ;-) > > Le ven. 17 juil. 2020 ? 21:03, Rhodri James a ?crit : > >> On 17/07/2020 19:33, Steve wrote: >>> Sorry folks, I really messed that one up. I tried to doctor up a reply >> to >>> get the address correct but failed to delete enough to own the message... >> >> Yeah, don't do that. Just start a new message, otherwise you'll end up >> with all the threading for the old message thread, irritating those of >> us who sort by thread so that we aren't chopping and changing subject >> all the time :-/ >> >>> My message did not have anything to do with the "Fake News Detect" >> subject. >>> >>> I posted a request for assistance about a week ago, no response. I also >> see >>> very little traffic here, less than there used to be. Has something gone >>> wrong with my set up? >> >> No, nothing's wrong. I can't answer for anyone else and I can't recall >> your specific question, but I suspect you were asking about something I >> know nothing about and wasn't sufficiently intrigued to go find out about. >> >> I think there are fewer experts with time lurking around here (and I >> don't count myself as one of those, TBH). Recent controversies and the >> attempts to moderate them have probably upset quite a lot of people one >> way or another. >> >> -- >> Rhodri James *-* Kynesim Ltd >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- Rhodri James *-* Kynesim Ltd From orges.leka at gmail.com Fri Jul 17 16:06:06 2020 From: orges.leka at gmail.com (Orges Leka) Date: Fri, 17 Jul 2020 22:06:06 +0200 Subject: Fake news Detect In-Reply-To: <20200717165052.6iixyd3pbwufvyp3@feather.localdomain> References: <20200717165052.6iixyd3pbwufvyp3@feather.localdomain> Message-ID: you could use scikit learn tfidf and svm or random forest. for this you need labeled data ( fake news, no fake news) you could start at Kaggle (natural language processing) if you are new to this. Reto schrieb am Fr., 17. Juli 2020, 20:49: > What you want is called "natural language processing" and whole research > papers > have been written about this topic. > > Search your favorite research paper index for those keywords, say google > scholar. > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Fri Jul 17 17:08:50 2020 From: PythonList at DancesWithMice.info (dn) Date: Sat, 18 Jul 2020 09:08:50 +1200 Subject: Python pandas Excel In-Reply-To: <42ba64c1-6e3d-50f4-2b52-48ee1cae4833@inpe.br> References: <42ba64c1-6e3d-50f4-2b52-48ee1cae4833@inpe.br> Message-ID: On 18/07/20 3:36 AM, J Conrado wrote: > HI, > > I have an excel file with several columns, the first day/month,/year and > hour: > > Data > 01/11/2017 00:00 > 01/11/2017 03:00 ... > Please, how can I get four arrays for day, month, year and hour this > column of my excel. What do you have so-far? How are you importing the Excel data into the Python environment? Are you able to import a single cell's value, eg "01/11/2017 00:00" Assuming the import produces a string, are you able to "slice" the string into the requisite components? -- Regards =dn From grant.b.edwards at gmail.com Fri Jul 17 16:12:42 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 17 Jul 2020 20:12:42 -0000 (UTC) Subject: An I connected here? References: <007201d65c68$dad3b4f0$907b1ed0$@SGA.Ninja> <7cf767f6-4c78-23a2-2aa9-ea0e1545f44f@kynesim.co.uk> Message-ID: On 2020-07-17, Rhodri James wrote: > On 17/07/2020 19:33, Steve wrote: > >> I posted a request for assistance about a week ago, no response. I >> also see very little traffic here, less than there used to be. Has >> something gone wrong with my set up? > > No, nothing's wrong. I can't answer for anyone else and I can't recall > your specific question, but I suspect you were asking about something I > know nothing about and wasn't sufficiently intrigued to go find out about. And if it's not clear from the subject line that it _is_ something somebody knows/cares about, then that somebody is unlikely to read the body of the message. Subject lines like "help me please" or "Python doesn't work" or "An I connected here" are likely to be ignored by most of the people who probably know how to help. There are a few kind souls who make a habit of reading those, dog bless em. [I'm not one of them, I only read this by accident.] That said, there is definitely less traffic these days. I assume it's a continuation the gradual abandonment of usenet/email in favor of various almost-entirely-useless web "forums". -- Grant From grant.b.edwards at gmail.com Fri Jul 17 16:16:51 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 17 Jul 2020 20:16:51 -0000 (UTC) Subject: Fake news Detect References: <39p3hflda843mucd7rkojara3aufl8jgu5@4ax.com> Message-ID: On 2020-07-17, Dennis Lee Bieber wrote: > On Fri, 17 Jul 2020 16:02:15 -0000 (UTC), Gazu declaimed > the following: > >>Hey Guys I am new to python and i am building a fake news detection >>system ... > > I suspect that, if anyone had done this already, it would likely be > found on some source code archive (github?) -- and you'd just be > duplicating the effort. > > Essentially, since the core of this functionality depends upon the > algorithm, YOU will have to develop the algorithm. Or he could do something easier like eliminating hunger, war and Covid-19. -- Grant From Marco.Sulla.Python at gmail.com Fri Jul 17 18:04:28 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Sat, 18 Jul 2020 00:04:28 +0200 Subject: frozendict: an experiment In-Reply-To: References: Message-ID: On Fri, 17 Jul 2020 at 04:13, Inada Naoki wrote: > > 3. many python internals uses a mapping proxy to a dict, to avoid its > > modification. A frozendict can be used instead. > > Are they used frequently in performance critical path? > Could you point some concrete examples? I searched a little in CPython code, and it seems that MappingProxy is used in a number of critical points. In re: ./Modules/_sre.c: return PyDictProxy_New(self->groupindex); in mutiprocessing: ./Lib/multiprocessing/managers.py:DictProxy = MakeProxyType('DictProxy', ( ./Lib/multiprocessing/managers.py:DictProxy._method_to_typeid_ = { ./Lib/multiprocessing/managers.py:SyncManager.register('dict', dict, DictProxy) In functools: ./Lib/functools.py: wrapper.registry = types.MappingProxyType(registry) In enum: ./Lib/enum.py: return MappingProxyType(cls._member_map_) I suppose the more crucial is _sre, since it's used extensively in CPython. groupindex is used by a large number of _sre functions. Note: I'm not sure that mappingproxyobject is much slower than dict, as types.MappyingProxyType. On Fri, 17 Jul 2020 at 04:13, Inada Naoki wrote: > I am not sure tuple is "internined" or just "merged". (I don't know precise > definition of the "interning"). > > Tuples are merged while compiling. > > ``` > for a in ["foo", "bar"]: # compiler convert this list to tuple > ... > for b in ("foo", "bar"): # and compiler merge same tuple > ... > ``` > > But when frozendicts are merged? > I think there is a very little chance. frozendicts could be used for kwargs: f(a=1, b=2) # some code f(a=1, b=2) For what I know, CPython uses PyDictObject for kwargs. Since dicts are mutable, it's a problem to cache them properly. On Fri, 17 Jul 2020 at 04:13, Inada Naoki wrote: > I'm OK to all combined dict for frozen dict. But I think key-sharing is still > interesting optimization for frozen dict. And supporting key-sharing dict > is much easier for frozendict than for mutable dict. Yes, I think the same. On Fri, 17 Jul 2020 at 04:13, Inada Naoki wrote: > Then, there is no reason to not support the view for frozendict? I didn't say to not support views... I said that "real objects", that implement the dictview API, could be returned by frozendict.keys() etc. From stackflowauto at gmail.com Fri Jul 17 20:04:08 2020 From: stackflowauto at gmail.com (stack flow) Date: Fri, 17 Jul 2020 17:04:08 -0700 (PDT) Subject: excel (multiple sheets) to yml file for each sheet In-Reply-To: References: Message-ID: <3167d667-7954-452b-855f-23a6f50f7882o@googlegroups.com> help please. On Thursday, July 16, 2020 at 10:38:23 PM UTC-4, stack flow wrote: > Hi, > > I have excel file with multiple sheets and need output as yml file for each sheet. could someone help me with python code? following is an example: > > aep sheet: > > aep aep_description infra_vlan > test_AEP test aep no > > aeps_to_domain sheet: > > aep domain domain_type > test_AEP test_PHY_DOM phys > test1_AEP test1_PHY_DOM l3dom > > > scription should output two files: > > aeps-vars.yml: > > aeps: > - aep: test_AEP > aep_description: test aep > infra_vlan: no > > > aeps_to_domain-vars.yml: > > aeps_to_domain: > - aep: test_AEP > domain: test_PHY_DOM > domain_type: phys > - aep: test_AEP > domain: test_L3O_DOM > domain_type: l3dom From Gronicus at SGA.Ninja Fri Jul 17 20:05:13 2020 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 17 Jul 2020 20:05:13 -0400 Subject: An I connected here? In-Reply-To: References: <007201d65c68$dad3b4f0$907b1ed0$@SGA.Ninja> <7cf767f6-4c78-23a2-2aa9-ea0e1545f44f@kynesim.co.uk> Message-ID: <00a101d65c97$1c3c4fa0$54b4eee0$@SGA.Ninja> Thanks for the verification. I received my original message back and that also shows success in my attempt. The first message had no such copy back so it went off somewhere... Thanks for the guidance but I always try to make the subject line pertinent and explanatory. It is the selling point to get results. I will repost it later. FootNote: If money does not grow on trees, then why do banks have branches? -----Original Message----- From: Python-list On Behalf Of Grant Edwards Sent: Friday, July 17, 2020 4:13 PM To: python-list at python.org Subject: Re: An I connected here? On 2020-07-17, Rhodri James wrote: > On 17/07/2020 19:33, Steve wrote: > >> I posted a request for assistance about a week ago, no response. I >> also see very little traffic here, less than there used to be. Has >> something gone wrong with my set up? > > No, nothing's wrong. I can't answer for anyone else and I can't > recall your specific question, but I suspect you were asking about > something I know nothing about and wasn't sufficiently intrigued to go find out about. And if it's not clear from the subject line that it _is_ something somebody knows/cares about, then that somebody is unlikely to read the body of the message. Subject lines like "help me please" or "Python doesn't work" or "An I connected here" are likely to be ignored by most of the people who probably know how to help. There are a few kind souls who make a habit of reading those, dog bless em. [I'm not one of them, I only read this by accident.] That said, there is definitely less traffic these days. I assume it's a continuation the gradual abandonment of usenet/email in favor of various almost-entirely-useless web "forums". -- Grant -- https://mail.python.org/mailman/listinfo/python-list From PythonList at DancesWithMice.info Fri Jul 17 20:16:35 2020 From: PythonList at DancesWithMice.info (dn) Date: Sat, 18 Jul 2020 12:16:35 +1200 Subject: Python pandas Excel In-Reply-To: <6lb4hflqs79c66bv0jmcpo44edo6ljoavr@4ax.com> References: <42ba64c1-6e3d-50f4-2b52-48ee1cae4833@inpe.br> <6lb4hflqs79c66bv0jmcpo44edo6ljoavr@4ax.com> Message-ID: On 18/07/20 11:06 AM, Dennis Lee Bieber wrote: > On Sat, 18 Jul 2020 09:08:50 +1200, dn via Python-list > declaimed the following: > >> Assuming the import produces a string, are you able to "slice" the >> string into the requisite components? > > Given the OP's stated output -- I would suspect they are being > imported/parsed as DateTime objects. Which is quite likely also what the > column is defined to be in Excel. Agreed, but the lack of 'how' information reduces us to guessing... TBH in this mode, I tend to reduce a DateTime to a string and deal with it that way; whereas the 'official' answer is likely to use DateTime methods to extract the requisite sub-items. (I've not stopped to perform a speed-comparison, so it's as basic as what I 'see' as the more simple option) More importantly, if that lack indicates that the OP hasn't ascertained such details, the earlier questions must be answered before the finer-details. -- Regards =dn From hcasti13 at calstatela.edu Fri Jul 17 21:53:44 2020 From: hcasti13 at calstatela.edu (Castillo, Herbert S) Date: Sat, 18 Jul 2020 01:53:44 +0000 Subject: help Message-ID: Hi, I downloaded python not to long ago, and today when I opened Python on Windows it gave me a modify setup prompt. I have tried to click on modify , repair and even uninstalled and installed it back, but when I try to open Python up again, I keep on getting the same modify setup prompt. I am not sure of what to do? Thank you in advance. [cid:image002.jpg at 01D65C6B.97D73D90] Herbert S. Castillo Graduate Student, CSULA hcasti13 at calstatela.edu C: 310-462-6269 From robertvstepp at gmail.com Fri Jul 17 22:42:47 2020 From: robertvstepp at gmail.com (boB Stepp) Date: Fri, 17 Jul 2020 21:42:47 -0500 Subject: help In-Reply-To: References: Message-ID: On Fri, Jul 17, 2020 at 9:00 PM Castillo, Herbert S wrote: > I downloaded python not to long ago, and today when I opened Python on Windows it gave me a modify setup prompt. I have tried to click on modify , repair and even uninstalled and installed it back, but when I try to open Python up again, I keep on getting the same modify setup prompt. I am not sure of what to do? Thank you in advance. It sounds like you are just rerunning the python installer. Instead, open a command prompt or Powershell and type "py". That will bring up the Python interactive environment where you can type Python commands. Or, probably better, open IDLE -- the provided Python editing environment -- by pressing your Windows key which brings up the list of available programs/program folders, find Python, expand that if needed by clicking on it and then clicking on "IDLE". That will bring up the Python interactive prompt as well. You can also create a new Python file using the provided "File" menu, etc. BTW, I am doing this from memory. I don't have a Windows PC handy, but hopefully it is enough to get you over the hump. BTW, there is a Python Tutor mailing list designed for those learning Python. Also, the main Python website has documentation, lists of resources, tutorial, etc., to also help jumpstart your learning. Have fun! HTH! -- boB From PythonList at DancesWithMice.info Fri Jul 17 22:46:45 2020 From: PythonList at DancesWithMice.info (dn) Date: Sat, 18 Jul 2020 14:46:45 +1200 Subject: help In-Reply-To: References: Message-ID: On 18/07/20 1:53 PM, Castillo, Herbert S wrote: > I downloaded python not to long ago, and today when I opened Python on Windows it gave me a modify setup prompt. I have tried to click on modify , repair and even uninstalled and installed it back, but when I try to open Python up again, I keep on getting the same modify setup prompt. I am not sure of what to do? Thank you in advance. Regret that this mailing list does not support graphics attachments. Which part of https://docs.python.org/dev/using/windows.html failed? -- Regards =dn From PythonList at DancesWithMice.info Fri Jul 17 22:47:44 2020 From: PythonList at DancesWithMice.info (dn) Date: Sat, 18 Jul 2020 14:47:44 +1200 Subject: Issues in downloading python In-Reply-To: References: Message-ID: <3c8bcd76-4d26-f210-f323-62f39c83808c@DancesWithMice.info> On 17/07/20 7:22 PM, Shanmika Sugavaneswaran wrote: > Though I install the setup , I couldn?t find Python in my system . I don?t know what cause the problem. Please help me! Please advise if the answer is not already covered in https://docs.python.org/dev/using/windows.html -- Regards =dn From PythonList at DancesWithMice.info Fri Jul 17 22:52:55 2020 From: PythonList at DancesWithMice.info (dn) Date: Sat, 18 Jul 2020 14:52:55 +1200 Subject: excel (multiple sheets) to yml file for each sheet In-Reply-To: <3167d667-7954-452b-855f-23a6f50f7882o@googlegroups.com> References: <3167d667-7954-452b-855f-23a6f50f7882o@googlegroups.com> Message-ID: <38614479-23a9-b553-e781-8688d1bd2abe@DancesWithMice.info> On 18/07/20 12:04 PM, stack flow wrote: > help please. > > On Thursday, July 16, 2020 at 10:38:23 PM UTC-4, stack flow wrote: >> Hi, >> >> I have excel file with multiple sheets and need output as yml file for each sheet. could someone help me with python code? following is an example: >> >> aep sheet: >> >> aep aep_description infra_vlan >> test_AEP test aep no >> >> aeps_to_domain sheet: >> >> aep domain domain_type >> test_AEP test_PHY_DOM phys >> test1_AEP test1_PHY_DOM l3dom >> >> >> scription should output two files: >> >> aeps-vars.yml: >> >> aeps: >> - aep: test_AEP >> aep_description: test aep >> infra_vlan: no >> >> >> aeps_to_domain-vars.yml: >> >> aeps_to_domain: >> - aep: test_AEP >> domain: test_PHY_DOM >> domain_type: phys >> - aep: test_AEP >> domain: test_L3O_DOM >> domain_type: l3dom Please show us the Python code which you've completed, and ask a specific question about the situation which is challenging you. Be advised that the members of this list are volunteers. That said, if you want to pay someone to code for you, perhaps mention your budget... -- Regards =dn From robertvstepp at gmail.com Fri Jul 17 23:29:21 2020 From: robertvstepp at gmail.com (boB Stepp) Date: Fri, 17 Jul 2020 22:29:21 -0500 Subject: A Python installation help doc much more friendly to newcomers? [Was Re: help] In-Reply-To: References: Message-ID: On Fri, Jul 17, 2020 at 9:48 PM dn via Python-list wrote: > > On 18/07/20 1:53 PM, Castillo, Herbert S wrote: > > I downloaded python not to long ago, and today when I opened Python on Windows it gave me a modify setup prompt. I have tried to click on modify , repair and even uninstalled and installed it back, but when I try to open Python up again, I keep on getting the same modify setup prompt. I am not sure of what to do? Thank you in advance. > > > Regret that this mailing list does not support graphics attachments. > > Which part of https://docs.python.org/dev/using/windows.html failed? Just for grins I just now glanced at the link dn provided. Yes, this is a very thorough, very accurate, very *technical* help resource. But if I were a person who had never seen a shell, cmd.exe or Powershell window, never programmed before, had no clue about how to truly use my OS, etc., I don't think I would understand a bit of this "help" document, and, at best, would find it very intimidating. If this community does wish to cater to those who are totally new to the world of programming and learning how to really use their PC at any depth, then I think a different approach or set of documents is needed. And an easier way for those playing with the idea of learning programming and Python to connect with such documentation. I think that we take a lot for granted that is second nature to most of us. Also, most of us have the mindset that even when all of this programming stuff was new to us (If we can even truly remember that anymore.), we would have the problem-solving chops to get over these hurdles. Many don't have these native inclinations. Searching online for technical solutions is completely foreign to many. Even searching for anything may be more challenging than we suspect for some. I am just a Python hobbyist/dabbler, not a pro like most of you, but I have taught kids through adults various subjects in the past, helped seniors, etc., and a lot of what we take for granted is *not* easy for many. But I believe that almost everyone that can get to the point of believing that they can perhaps learn programming, can do so, but may need some encouragement to get to that point of "self-belief". Sure, some people are just too lazy and want to be spoon-fed, but I truly believe that is a minority. Can we make this easier for those who really would like to try? Just some thoughts that I hope will be constructively received. -- boB From Gronicus at SGA.Ninja Sat Jul 18 00:32:12 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sat, 18 Jul 2020 00:32:12 -0400 Subject: Seeking to convert a py timer app for my Moto E6 Message-ID: <00b401d65cbc$68ec1e00$3ac45a00$@SGA.Ninja> I am looking for an app for my Moto e6 android phone that will accept a number of hours and then count down. Once the hours have been executed, it will quietly beep every minute until I cancel the app. This is to remind me (and keep on reminding me) when to take my insulin. It has been written in python but I do not know how to convert it to an app. I wonder how much of the python code will still apply. When I was into this in the past, I installed Kivy and was able to finally generate a "Hello World" app and managed to get it to my phone. Then life called me back to reality and I lost track of what I was doing for a few years. )-: I doubt I can go through that installation and learning curve again. It works on my computer but I have projects that interfere with the alarm. This is why I would prefer to have it on my phone. I appreciate any assistance you can provide. Steve I attached the py code but wonder if it will carry with the message. It is about 100 lines of code but that includes a few ops and whistles that are probably not needed in the app. -------------------------------------------------------------------------------------------- There's 99 bugs in the code, in the code. 99 bugs in the code. Take one down and patch it all around. Now there's 117 bugs in the code. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: 4Timer.py URL: From PythonList at DancesWithMice.info Sat Jul 18 00:36:44 2020 From: PythonList at DancesWithMice.info (dn) Date: Sat, 18 Jul 2020 16:36:44 +1200 Subject: A Python installation help doc much more friendly to newcomers? [Was Re: help] In-Reply-To: References: Message-ID: <423596c5-602c-03ae-fadd-a6e394348d91@DancesWithMice.info> On 18/07/20 3:29 PM, boB Stepp wrote: > On Fri, Jul 17, 2020 at 9:48 PM dn via Python-list > wrote: >> >> On 18/07/20 1:53 PM, Castillo, Herbert S wrote: >>> I downloaded python not to long ago, and today when I opened Python on Windows it gave me a modify setup prompt. I have tried to click on modify , repair and even uninstalled and installed it back, but when I try to open Python up again, I keep on getting the same modify setup prompt. I am not sure of what to do? Thank you in advance. >> >> >> Regret that this mailing list does not support graphics attachments. >> >> Which part of https://docs.python.org/dev/using/windows.html failed? > > Just for grins I just now glanced at the link dn provided. Yes, this > is a very thorough, very accurate, very *technical* help resource. > But if I were a person who had never seen a shell, cmd.exe or > Powershell window, never programmed before, had no clue about how to > truly use my OS, etc., I don't think I would understand a bit of this > "help" document, and, at best, would find it very intimidating. If > this community does wish to cater to those who are totally new to the > world of programming and learning how to really use their PC at any > depth, then I think a different approach or set of documents is > needed. And an easier way for those playing with the idea of learning > programming and Python to connect with such documentation. > > I think that we take a lot for granted that is second nature to most > of us. Also, most of us have the mindset that even when all of this > programming stuff was new to us (If we can even truly remember that > anymore.), we would have the problem-solving chops to get over these > hurdles. Many don't have these native inclinations. Searching online > for technical solutions is completely foreign to many. Even searching > for anything may be more challenging than we suspect for some. > > I am just a Python hobbyist/dabbler, not a pro like most of you, but I > have taught kids through adults various subjects in the past, helped > seniors, etc., and a lot of what we take for granted is *not* easy for > many. But I believe that almost everyone that can get to the point of > believing that they can perhaps learn programming, can do so, but may > need some encouragement to get to that point of "self-belief". > > Sure, some people are just too lazy and want to be spoon-fed, but I > truly believe that is a minority. Can we make this easier for those > who really would like to try? > > Just some thoughts that I hope will be constructively received. There is also THE Python Tutorial - the opening action is two?three pages 'in'. Is that suitably less-technical and more usable to a 'beginner'? https://docs.python.org/3/tutorial/index.html -- Regards =dn From miked at dewhirst.com.au Sat Jul 18 01:36:15 2020 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Sat, 18 Jul 2020 15:36:15 +1000 Subject: Fake news Detect In-Reply-To: References: <39p3hflda843mucd7rkojara3aufl8jgu5@4ax.com> Message-ID: <1262fb6a-5452-3c18-8d37-5b47bbe0ac88@dewhirst.com.au> On 18/07/2020 6:16 am, Grant Edwards wrote: > On 2020-07-17, Dennis Lee Bieber wrote: >> On Fri, 17 Jul 2020 16:02:15 -0000 (UTC), Gazu declaimed >> the following: >> >>> Hey Guys I am new to python and i am building a fake news detection >>> system ... >> I suspect that, if anyone had done this already, it would likely be >> found on some source code archive (github?) -- and you'd just be >> duplicating the effort. >> >> Essentially, since the core of this functionality depends upon the >> algorithm, YOU will have to develop the algorithm. > Or he could do something easier like eliminating hunger, war and > Covid-19. Or like changing culture to give more weight to education, integrity etc. We need systems to automatically identify fake news and educate believers. News consumers have to do it. News consumers need a system where they can go to check news items to see if they are credible. Without the cooperation of news conduits - to label news items with the source - that will be difficult. However, that doesn't mean the crowd can't check credibility. So, culture change is needed. No-one wants to be outed as a fake news source. Here's a project. Build an automatic news aggregation site which collects all news in two pages per news item. Page 1 for the item and page 2 for the crowd credibility assessment and naming of the apparent source. Should work somewhat like Wikipedia. Except editors for page 2 would need a threshold score for being correct. Everyone can criticise but you lose points for being on the wrong side of history. That'll be 2 cents Mike > > -- > Grant > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From songofacandy at gmail.com Sat Jul 18 04:02:28 2020 From: songofacandy at gmail.com (Inada Naoki) Date: Sat, 18 Jul 2020 17:02:28 +0900 Subject: frozendict: an experiment In-Reply-To: References: Message-ID: On Sat, Jul 18, 2020 at 7:05 AM Marco Sulla wrote: > > > > > But when frozendicts are merged? > > I think there is a very little chance. > > frozendicts could be used for kwargs: > > f(a=1, b=2) > # some code > f(a=1, b=2) > > For what I know, CPython uses PyDictObject for kwargs. Since dicts are > mutable, it's a problem to cache them properly. > On caller side, Python doesn't use dict at all. On callee side, dict is used for `**kwargs`. But changing it to frozendict is backward incompatible change. > On Fri, 17 Jul 2020 at 04:13, Inada Naoki wrote: > > I'm OK to all combined dict for frozen dict. But I think key-sharing is still > > interesting optimization for frozen dict. And supporting key-sharing dict > > is much easier for frozendict than for mutable dict. > > Yes, I think the same. > > On Fri, 17 Jul 2020 at 04:13, Inada Naoki wrote: > > Then, there is no reason to not support the view for frozendict? > > I didn't say to not support views... I said that "real objects", that > implement the dictview API, could be returned by frozendict.keys() > etc. It will cause performance penalty. Currently, `for k,v in d.items()` doesn't create temporary list or set-like. I think using "real object" is not good performance optimization. Regards, -- Inada Naoki From __peter__ at web.de Sat Jul 18 04:20:56 2020 From: __peter__ at web.de (Peter Otten) Date: Sat, 18 Jul 2020 10:20:56 +0200 Subject: Python pandas Excel References: <42ba64c1-6e3d-50f4-2b52-48ee1cae4833@inpe.br> Message-ID: J Conrado wrote: > > > > > > > > > > > > HI, > > > I have an excel file with several columns, the first day/month,/year and > hour: > > > Data > 01/11/2017 00:00 > 01/11/2017 03:00 > 01/11/2017 06:00 > 01/11/2017 09:00 > 01/11/2017 12:00 > 01/11/2017 15:00 > 01/11/2017 18:00 > 01/11/2017 21:00 > 02/11/2017 00:00 > 02/11/2017 03:00 > 02/11/2017 06:00 > 02/11/2017 09:00 > 02/11/2017 12:00 > 02/11/2017 15:00 > 02/11/2017 18:00 > 02/11/2017 21:00 > 03/11/2017 00:00 > 03/11/2017 03:00 > 03/11/2017 06:00 > 03/11/2017 09:00 > 03/11/2017 12:00 > 03/11/2017 15:00 > 03/11/2017 18:00 > 03/11/2017 21:00 > 04/11/2017 00:00 > 04/11/2017 03:00 > 04/11/2017 06:00 > 04/11/2017 09:00 > 04/11/2017 12:00 > 04/11/2017 15:00 > 04/11/2017 18:00 > 04/11/2017 21:00 > 05/11/2017 00:00 > 05/11/2017 03:00 > 05/11/2017 06:00 > 05/11/2017 09:00 > 05/11/2017 12:00 > 05/11/2017 15:00 > 05/11/2017 18:00 > 05/11/2017 21:00 > 06/11/2017 00:00 > 06/11/2017 03:00 > 06/11/2017 06:00 > 06/11/2017 09:00 > 06/11/2017 12:00 > 06/11/2017 15:00 > 06/11/2017 18:00 > 06/11/2017 21:00 > 07/11/2017 00:00 > 07/11/2017 03:00 > 07/11/2017 06:00 > 07/11/2017 09:00 > 07/11/2017 12:00 > 07/11/2017 15:00 > 07/11/2017 18:00 > 07/11/2017 21:00 > 08/11/2017 00:00 > 08/11/2017 03:00 > 08/11/2017 06:00 > 08/11/2017 09:00 > 08/11/2017 12:00 > 08/11/2017 15:00 > 08/11/2017 21:00 > 09/11/2017 00:00 > 09/11/2017 03:00 > 09/11/2017 06:00 > 09/11/2017 09:00 > 09/11/2017 12:00 > 09/11/2017 15:00 > 09/11/2017 18:00 > 09/11/2017 21:00 > 10/11/2017 00:00 > 10/11/2017 03:00 > 10/11/2017 06:00 > 10/11/2017 09:00 > 10/11/2017 12:00 > 10/11/2017 15:00 > 10/11/2017 18:00 > 10/11/2017 21:00 > 11/11/2017 00:00 > 11/11/2017 03:00 > 11/11/2017 06:00 > 11/11/2017 09:00 > 11/11/2017 12:00 > 11/11/2017 15:00 > 11/11/2017 18:00 > 11/11/2017 21:00 > 12/11/2017 00:00 > 12/11/2017 03:00 > 12/11/2017 06:00 > 12/11/2017 09:00 > 12/11/2017 12:00 > 12/11/2017 15:00 > 12/11/2017 18:00 > 12/11/2017 21:00 > 13/11/2017 00:00 > 13/11/2017 03:00 > 13/11/2017 06:00 > 13/11/2017 09:00 > 13/11/2017 12:00 > 13/11/2017 15:00 > 13/11/2017 18:00 > 13/11/2017 21:00 > 14/11/2017 00:00 > 14/11/2017 03:00 > 14/11/2017 06:00 > 14/11/2017 09:00 > 14/11/2017 12:00 > 14/11/2017 15:00 > 14/11/2017 18:00 > 14/11/2017 21:00 > 15/11/2017 00:00 > 15/11/2017 03:00 > 15/11/2017 06:00 > 15/11/2017 09:00 > 15/11/2017 12:00 > 15/11/2017 15:00 > 15/11/2017 18:00 > 15/11/2017 21:00 > 16/11/2017 00:00 > 16/11/2017 03:00 > 16/11/2017 06:00 > 16/11/2017 09:00 > 16/11/2017 12:00 > 16/11/2017 15:00 > 16/11/2017 18:00 > 16/11/2017 21:00 > 17/11/2017 00:00 > 17/11/2017 03:00 > 17/11/2017 06:00 > 17/11/2017 09:00 > 17/11/2017 12:00 > 17/11/2017 15:00 > 17/11/2017 18:00 > 18/11/2017 00:00 > 18/11/2017 03:00 > 18/11/2017 06:00 > 18/11/2017 09:00 > 18/11/2017 12:00 > 18/11/2017 15:00 > 18/11/2017 18:00 > 18/11/2017 21:00 > 19/11/2017 00:00 > 19/11/2017 03:00 > 19/11/2017 06:00 > 19/11/2017 09:00 > 19/11/2017 12:00 > 19/11/2017 15:00 > 19/11/2017 18:00 > 19/11/2017 21:00 > 20/11/2017 00:00 > 20/11/2017 03:00 > 20/11/2017 06:00 > 20/11/2017 09:00 > 20/11/2017 12:00 > 20/11/2017 15:00 > 20/11/2017 18:00 > 20/11/2017 21:00 > 21/11/2017 00:00 > 21/11/2017 03:00 > 21/11/2017 06:00 > 21/11/2017 09:00 > 21/11/2017 12:00 > 21/11/2017 15:00 > 21/11/2017 18:00 > 22/11/2017 03:00 > 22/11/2017 06:00 > 22/11/2017 09:00 > 22/11/2017 12:00 > 22/11/2017 15:00 > 22/11/2017 18:00 > 22/11/2017 21:00 > 23/11/2017 00:00 > 23/11/2017 03:00 > 23/11/2017 06:00 > 23/11/2017 09:00 > 23/11/2017 12:00 > 23/11/2017 15:00 > 23/11/2017 18:00 > 23/11/2017 21:00 > 24/11/2017 00:00 > 24/11/2017 03:00 > 24/11/2017 06:00 > 24/11/2017 09:00 > 24/11/2017 12:00 > 24/11/2017 15:00 > 24/11/2017 18:00 > 24/11/2017 21:00 > 25/11/2017 00:00 > 25/11/2017 03:00 > 25/11/2017 06:00 > 25/11/2017 09:00 > 25/11/2017 12:00 > 25/11/2017 15:00 > 25/11/2017 18:00 > 25/11/2017 21:00 > 26/11/2017 00:00 > 26/11/2017 03:00 > 26/11/2017 06:00 > 26/11/2017 09:00 > 26/11/2017 12:00 > 26/11/2017 15:00 > 26/11/2017 18:00 > 26/11/2017 21:00 > 27/11/2017 03:00 > 27/11/2017 06:00 > 27/11/2017 09:00 > 27/11/2017 12:00 > 27/11/2017 15:00 > 27/11/2017 18:00 > 27/11/2017 21:00 > 28/11/2017 06:00 > 28/11/2017 09:00 > 28/11/2017 12:00 > 28/11/2017 15:00 > 28/11/2017 18:00 > 28/11/2017 21:00 > 29/11/2017 00:00 > 29/11/2017 03:00 > 29/11/2017 06:00 > 29/11/2017 09:00 > 29/11/2017 12:00 > 29/11/2017 15:00 > 29/11/2017 18:00 > 29/11/2017 21:00 > 30/11/2017 00:00 > 30/11/2017 03:00 > 30/11/2017 06:00 > 30/11/2017 09:00 > 30/11/2017 12:00 > 30/11/2017 15:00 > 30/11/2017 18:00 > 30/11/2017 21:00 > > > This is the value tha a have using pandas: > > > print(data) > > > 0 2017-01-11 00:00:00 > 1 2017-01-11 03:00:00 > 2 2017-01-11 06:00:00 > 3 2017-01-11 09:00:00 > 4 2017-01-11 12:00:00 > ... > 228 2017-11-30 09:00:00 > 229 2017-11-30 12:00:00 > 230 2017-11-30 15:00:00 > 231 2017-11-30 18:00:00 > 232 2017-11-30 21:00:00 > > Please, how can I get four arrays for day, month, year and hour this > column of my excel. df["year"] = df["timestamp"].apply(lambda ts: ts.year) A self-contained demonstration: $ cat tmp.py import pandas as pd import operator # Create sample data. df = pd.DataFrame({ "timestamp": pd.date_range("2020-01-01 01:00", periods=5) }) print(df) # Extract "year" etc. attributes from the "timestamp" column # into the year etc. columns. for name in "year month day hour".split(): df[name] = df["timestamp"].apply(operator.attrgetter(name)) # Remove "timestamp" column. del df["timestamp"] print(df) $ python3 tmp.py timestamp 0 2020-01-01 01:00:00 1 2020-01-02 01:00:00 2 2020-01-03 01:00:00 3 2020-01-04 01:00:00 4 2020-01-05 01:00:00 [5 rows x 1 columns] year month day hour 0 2020 1 1 1 1 2020 1 2 1 2 2020 1 3 1 3 2020 1 4 1 4 2020 1 5 1 [5 rows x 4 columns] $ From oscar.j.benjamin at gmail.com Sat Jul 18 07:48:57 2020 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 18 Jul 2020 12:48:57 +0100 Subject: A Python installation help doc much more friendly to newcomers? [Was Re: help] In-Reply-To: <423596c5-602c-03ae-fadd-a6e394348d91@DancesWithMice.info> References: <423596c5-602c-03ae-fadd-a6e394348d91@DancesWithMice.info> Message-ID: On Sat, 18 Jul 2020 at 05:39, dn via Python-list wrote: > > On 18/07/20 3:29 PM, boB Stepp wrote: > > On Fri, Jul 17, 2020 at 9:48 PM dn via Python-list > > wrote: > >> > >> On 18/07/20 1:53 PM, Castillo, Herbert S wrote: > >>> I downloaded python not to long ago, and today when I opened Python on Windows it gave me a modify setup prompt. I have tried to click on modify , repair and even uninstalled and installed it back, but when I try to open Python up again, I keep on getting the same modify setup prompt. I am not sure of what to do? Thank you in advance. > >> > >> > >> Regret that this mailing list does not support graphics attachments. > >> > >> Which part of https://docs.python.org/dev/using/windows.html failed? > > > > Just for grins I just now glanced at the link dn provided. Yes, this > > is a very thorough, very accurate, very *technical* help resource. > > But if I were a person who had never seen a shell, cmd.exe or > > Powershell window, never programmed before, had no clue about how to > > truly use my OS, etc., I don't think I would understand a bit of this > > "help" document, and, at best, would find it very intimidating. If > > this community does wish to cater to those who are totally new to the > > world of programming and learning how to really use their PC at any > > depth, then I think a different approach or set of documents is > > needed. And an easier way for those playing with the idea of learning > > programming and Python to connect with such documentation. > > [snip] > > There is also THE Python Tutorial - the opening action is two?three > pages 'in'. Is that suitably less-technical and more usable to a 'beginner'? > https://docs.python.org/3/tutorial/index.html I would say that the official tutorial is not targeted at the total novice. I think it used to be described as the tutorial for people with experience of programming in other languages but I might be misremembering. The main python.org page links to a "beginners guide" well actually there are two beginners guides... https://www.python.org/ Under "get started" there is a link to this beginners guide: https://www.python.org/about/gettingstarted/ You can also hover over documentation and choose beginners guide to get this one: https://wiki.python.org/moin/BeginnersGuide The former starts by asking whether you are new to programming and if so suggests this page: https://wiki.python.org/moin/BeginnersGuide/NonProgrammers It also has an "installing" section which links to here: https://wiki.python.org/moin/BeginnersGuide/Download All of these have lots of information and many links to other pages. I'm not sure how you'd find the page dn linked to which is at least more direct about how to install: https://docs.python.org/dev/using/windows.html Certainly I don't see it if I go straight to the download pages: https://www.python.org/downloads/ https://www.python.org/downloads/windows/ I think if I was new to programming or installing software in general I would find all of this quite bewildering. My experience of teaching total novice programmers is that you really can't shirk the fundamental question: how should I install this thing and start using it *before* I have any idea what I'm doing? Novices don't need to be told that there are 100 ways to do it: they need to be told exactly how to do it in a way that will work for them. If I was writing the tutorial but aiming at total novices I would probably begin by suggesting to use an online shell: https://www.python.org/shell/ There could be a short guide there that explains very clearly how to do simple commands in that online shell. At that point you are ready to test the examples from page 3 of the official tutorial but I think it is still not pitched at novices: https://docs.python.org/3/tutorial/introduction.html Then after a few examples and some familiarity it could be time to suggest installing locally. That should be with a no nonsense explanation that makes no reference to terminals, PATH, etc because those are just intimidating distractions to a novice at that point in time. The sympy docs have a lot of room for improvement but one of the things that is very useful for beginners there is the "Run code block in sympy live" button which means that you can follow the tutorial/docs and try things out before having anything installed locally: https://docs.sympy.org/latest/tutorial/intro.html#introduction -- Oscar From vincent at vincentdavis.net Sat Jul 18 08:53:08 2020 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 18 Jul 2020 06:53:08 -0600 Subject: Fake news Detect In-Reply-To: <1262fb6a-5452-3c18-8d37-5b47bbe0ac88@dewhirst.com.au> References: <39p3hflda843mucd7rkojara3aufl8jgu5@4ax.com> <1262fb6a-5452-3c18-8d37-5b47bbe0ac88@dewhirst.com.au> Message-ID: Data Sceptic has a couple podcast and some of the code is open source. https://dataskeptic.com/blog/episodes/2018/algorithmic-detection-of-fake-news Thanks Vincent Davis 720-301-3003 *Want to get a hold of me?* *SMS: awesome.phone: ok...* *email: bad!* On Fri, Jul 17, 2020 at 11:39 PM Mike Dewhirst wrote: > On 18/07/2020 6:16 am, Grant Edwards wrote: > > On 2020-07-17, Dennis Lee Bieber wrote: > >> On Fri, 17 Jul 2020 16:02:15 -0000 (UTC), Gazu > declaimed > >> the following: > >> > >>> Hey Guys I am new to python and i am building a fake news detection > >>> system ... > >> I suspect that, if anyone had done this already, it would likely be > >> found on some source code archive (github?) -- and you'd just be > >> duplicating the effort. > >> > >> Essentially, since the core of this functionality depends upon the > >> algorithm, YOU will have to develop the algorithm. > > Or he could do something easier like eliminating hunger, war and > > Covid-19. > > Or like changing culture to give more weight to education, integrity > etc. We need systems to automatically identify fake news and educate > believers. News consumers have to do it. > > News consumers need a system where they can go to check news items to > see if they are credible. Without the cooperation of news conduits - to > label news items with the source - that will be difficult. > > However, that doesn't mean the crowd can't check credibility. So, > culture change is needed. No-one wants to be outed as a fake news source. > > Here's a project. Build an automatic news aggregation site which > collects all news in two pages per news item. Page 1 for the item and > page 2 for the crowd credibility assessment and naming of the apparent > source. Should work somewhat like Wikipedia. Except editors for page 2 > would need a threshold score for being correct. Everyone can criticise > but you lose points for being on the wrong side of history. > > That'll be 2 cents > > Mike > > > > > -- > > Grant > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From hcasti13 at calstatela.edu Sat Jul 18 13:32:00 2020 From: hcasti13 at calstatela.edu (Castillo, Herbert S) Date: Sat, 18 Jul 2020 17:32:00 +0000 Subject: help In-Reply-To: References: Message-ID: Thank you, boB! Yes, I kept on opening the installer. Your directions were great from memory, and I will look into the Python tutor mailing list. Thanks again. Herbert -----Original Message----- From: boB Stepp Sent: Friday, July 17, 2020 7:43 PM To: Castillo, Herbert S Cc: python-list at python.org Subject: Re: help On Fri, Jul 17, 2020 at 9:00 PM Castillo, Herbert S wrote: > I downloaded python not to long ago, and today when I opened Python on Windows it gave me a modify setup prompt. I have tried to click on modify , repair and even uninstalled and installed it back, but when I try to open Python up again, I keep on getting the same modify setup prompt. I am not sure of what to do? Thank you in advance. It sounds like you are just rerunning the python installer. Instead, open a command prompt or Powershell and type "py". That will bring up the Python interactive environment where you can type Python commands. Or, probably better, open IDLE -- the provided Python editing environment -- by pressing your Windows key which brings up the list of available programs/program folders, find Python, expand that if needed by clicking on it and then clicking on "IDLE". That will bring up the Python interactive prompt as well. You can also create a new Python file using the provided "File" menu, etc. BTW, I am doing this from memory. I don't have a Windows PC handy, but hopefully it is enough to get you over the hump. BTW, there is a Python Tutor mailing list designed for those learning Python. Also, the main Python website has documentation, lists of resources, tutorial, etc., to also help jumpstart your learning. Have fun! HTH! -- boB From Marco.Sulla.Python at gmail.com Sat Jul 18 17:18:24 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Sat, 18 Jul 2020 23:18:24 +0200 Subject: Iterating over dict is slower than iterating over iter(dict)? Message-ID: I noticed that iterating over a dictionary seems quite slower than creating an iterator and iterating over it. Maybe I miss something? marco at buzz:~/sources/cpython$ ./python dict_bench.py Name: `for x in dict`; Size: 8; Time: 1.091e-07 Name: `for x in dict`; Size: 1000; Time: 1.008e-05 Name: `for x in iter(dict)`; Size: 8; Time: 1.845e-08 Name: `for x in iter(dict)`; Size: 1000; Time: 1.844e-08 Name: `iter(dict)`; Size: 8; Time: 5.260e-08 Name: `iter(dict)`; Size: 1000; Time: 5.262e-08 Environment: marco at buzz:~/sources/cpython$ ./python -VV Python 3.10.0a0 (heads/master:64053c31a4, Jul 18 2020, 20:14:48) [GCC 10.1.1 20200718] dict_bench.py: import timeit from string import Template def autorange(stmt, setup="pass", repeat=5): if setup == None: setup = "pass" t = timeit.Timer(stmt=stmt, setup=setup) a = t.autorange() number = a[0] return min(*t.repeat(number=number, repeat=repeat), a[1]) / number dict_sizes = (8, 1000) benchmarks = ( {"name": "for x in dict", "stmt": "for x in it: pass", "setup": """ o = {k:k for k in range($size)} it = o """}, {"name": "for x in iter(dict)", "stmt": "for x in it: pass", "setup": """ o = {k:k for k in range($size)} it = iter(o) """}, {"name": "iter(dict)", "stmt": "iter(o)", "setup": """ o = {k:k for k in range($size)} """}, ) for benchmark in benchmarks: for dict_size in dict_sizes: setup_tpl = benchmark.get("setup") if setup_tpl == None: setup = setup_tpl else: setup = Template(setup_tpl).substitute(size=dict_size) print("Name: {: <25} Size: {: >4}; Time: {:.3e}".format( "`{}`;".format(benchmark["name"]), dict_size, autorange(stmt=benchmark["stmt"], setup=setup) )) From rosuav at gmail.com Sat Jul 18 17:28:38 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Jul 2020 07:28:38 +1000 Subject: Iterating over dict is slower than iterating over iter(dict)? In-Reply-To: References: Message-ID: On Sun, Jul 19, 2020 at 7:20 AM Marco Sulla wrote: > > I noticed that iterating over a dictionary seems quite slower than creating > an iterator and iterating over it. Maybe I miss something? Welcome to microbenchmarks, where the tiniest change suddenly makes the entire benchmark meaningless :) > benchmarks = ( > {"name": "for x in dict", "stmt": "for x in it: pass", "setup": """ > o = {k:k for k in range($size)} > it = o > """}, > {"name": "for x in iter(dict)", "stmt": "for x in it: pass", "setup": > """ > o = {k:k for k in range($size)} > it = iter(o) > """}, > {"name": "iter(dict)", "stmt": "iter(o)", "setup": """ > o = {k:k for k in range($size)} > """}, > ) You're creating an iterator once and then iterating over it lots of times. In other words, after the first timing test, all the rest are iterating over an empty collection. Unsurprisingly, that's faster than actually looping :) ChrisA From Marco.Sulla.Python at gmail.com Sat Jul 18 17:38:14 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Sat, 18 Jul 2020 23:38:14 +0200 Subject: frozendict: an experiment In-Reply-To: References: Message-ID: On Sat, 18 Jul 2020 at 10:02, Inada Naoki wrote: > On Sat, Jul 18, 2020 at 7:05 AM Marco Sulla > wrote: > > For what I know, CPython uses PyDictObject for kwargs. Since dicts are > > mutable, it's a problem to cache them properly. > > On caller side, Python doesn't use dict at all. > On callee side, dict is used for `**kwargs`. But changing it to > frozendict is > backward incompatible change. > Not sure of what you mean with caller and callee. If you're talking about Python, I agree, kwargs must be dicts. But I was talking about CPython and PyDictObject, that is used internally for kwargs. On Sat, 18 Jul 2020 at 10:02, Inada Naoki wrote: > Currently, `for k,v in d.items()` > doesn't create > temporary list or set-like. > I think using "real object" is not good performance optimization. > Well, this is true... but they create view objects that are quite slow. From Marco.Sulla.Python at gmail.com Sat Jul 18 18:55:50 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Sun, 19 Jul 2020 00:55:50 +0200 Subject: Iterating over dict is slower than iterating over iter(dict)? In-Reply-To: References: Message-ID: ... oh my ... Sure, thank you. Thinking positive, I wasted a lot of hours, but I discovered timeit.Timer.autorange On Sat, 18 Jul 2020 at 23:30, Chris Angelico wrote: > On Sun, Jul 19, 2020 at 7:20 AM Marco Sulla > wrote: > > > > I noticed that iterating over a dictionary seems quite slower than > creating > > an iterator and iterating over it. Maybe I miss something? > > Welcome to microbenchmarks, where the tiniest change suddenly makes > the entire benchmark meaningless :) > > > benchmarks = ( > > {"name": "for x in dict", "stmt": "for x in it: pass", "setup": """ > > o = {k:k for k in range($size)} > > it = o > > """}, > > {"name": "for x in iter(dict)", "stmt": "for x in it: pass", "setup": > > """ > > o = {k:k for k in range($size)} > > it = iter(o) > > """}, > > {"name": "iter(dict)", "stmt": "iter(o)", "setup": """ > > o = {k:k for k in range($size)} > > """}, > > ) > > You're creating an iterator once and then iterating over it lots of > times. In other words, after the first timing test, all the rest are > iterating over an empty collection. Unsurprisingly, that's faster than > actually looping :) > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sat Jul 18 19:05:55 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Jul 2020 09:05:55 +1000 Subject: Iterating over dict is slower than iterating over iter(dict)? In-Reply-To: References: Message-ID: On Sun, Jul 19, 2020 at 8:56 AM Marco Sulla wrote: > > ... oh my ... Sure, thank you. > Thinking positive, I wasted a lot of hours, but I discovered timeit.Timer.autorange > Nah... You *spent* a lot of hours, almost certainly enjoyably, and along the way, you learned things! That's not wasted time! :) ChrisA From PythonList at DancesWithMice.info Sat Jul 18 19:02:25 2020 From: PythonList at DancesWithMice.info (dn) Date: Sun, 19 Jul 2020 11:02:25 +1200 Subject: A Python installation help doc much more friendly to newcomers? [Was Re: help] In-Reply-To: References: <423596c5-602c-03ae-fadd-a6e394348d91@DancesWithMice.info> Message-ID: <285c8bb3-bfef-3000-10e6-173a54c04b66@DancesWithMice.info> On 18/07/20 11:48 PM, Oscar Benjamin wrote: > On Sat, 18 Jul 2020 at 05:39, dn via Python-list wrote: >> >> On 18/07/20 3:29 PM, boB Stepp wrote: >>> On Fri, Jul 17, 2020 at 9:48 PM dn via Python-list >>> wrote: >>>> >>>> On 18/07/20 1:53 PM, Castillo, Herbert S wrote: >>>>> I downloaded python not to long ago, and today when I opened Python on Windows it gave me a modify setup prompt. I have tried to click on modify , repair and even uninstalled and installed it back, but when I try to open Python up again, I keep on getting the same modify setup prompt. I am not sure of what to do? Thank you in advance. >>> Just for grins I just now glanced at the link dn provided. Yes, this >>> is a very thorough, very accurate, very *technical* help resource. >>> But if I were a person who had never seen a shell, cmd.exe or >>> Powershell window, never programmed before, had no clue about how to >>> truly use my OS, etc., I don't think I would understand a bit of this >>> "help" document, and, at best, would find it very intimidating. If >>> this community does wish to cater to those who are totally new to the >>> world of programming and learning how to really use their PC at any >>> depth, then I think a different approach or set of documents is >>> needed. And an easier way for those playing with the idea of learning >>> programming and Python to connect with such documentation. >>> > [snip] >> >> There is also THE Python Tutorial - the opening action is two?three >> pages 'in'. Is that suitably less-technical and more usable to a 'beginner'? >> https://docs.python.org/3/tutorial/index.html > > I would say that the official tutorial is not targeted at the total > novice. I think it used to be described as the tutorial for people > with experience of programming in other languages but I might be > misremembering. > > The main python.org page links to a "beginners guide" well actually > there are two beginners guides... > https://www.python.org/ ... > Certainly I don't see it if I go straight to the download pages: > https://www.python.org/downloads/ > https://www.python.org/downloads/windows/ > > I think if I was new to programming or installing software in general > I would find all of this quite bewildering. > > My experience of teaching total novice programmers is that you really > can't shirk the fundamental question: how should I install this thing > and start using it *before* I have any idea what I'm doing? Novices > don't need to be told that there are 100 ways to do it: they need to > be told exactly how to do it in a way that will work for them. ... +1, well written! For grins (as boB would say) I scanned Oracle's intro pages to Java programming (JDK), and they have a logical progression from installation instructions to "proving" the installation with the ubiquitous Hello-World first-program. Whereas the MySQL web site requires one to select the appropriate download and then remember (!) to keep reading. Whereupon the manual offers advice about testing the server, etc. Whereas those are decades old and well-established, in case of comparison the 'younger' MongoDB's documentation was more complicated. The installation of the server was not followed by a link to information about running the client, to be able to assure the system and understand the most basic (debugging?) linkage. None of these are suited to the 'smart phone' world, where software is selected from an 'app store' and once installed, 'it just works'. Is that where these neophyte users' troubles start - a disconnect between such expectations and the Python reality? (it's all very alien to my Linux world/memories of MS-Win .msi files with a check-box at the end which invited a start-up or display of suitable help files) Yes, the observation that we have folk who are quite probably downloading a command-line program(me) for the first time in their lives, but is that a valid excuse? What I've run out of time to compare-and-contrast is the advantage of pointing users at a Python-environment distribution, eg Anaconda. If 'we' are less interested in caring for beginners and their basic needs, should we point them at others who are? Observations (further to/underlining @Oscar's points): - the requirements of a beginner installing for the first time (and maybe his/her first programming language) are totally different to someone wanting to install a new version of Python or on a new machine. (ie done-it-all-before/want it to be quick-and-easy/don't bother me with loads of docs) - most docs seem to try to be 'all things to all people', whereas the differences between platforms inevitably make the writing complicated and the reading difficult to follow. Thus, consider separating entries by OpSys and/or installation method. - a reference manual is not 'the place' for beginners, who require a more tutorial/hand-holding approach - a beginners' installation tutorial should include a first program(me) and thus run through the command-line/editor/execute/REPL etc philosophies. This may be opening yet another 'door', given the range of editors (I don't think that Idle is part of the Python download for all OpSys, any more)... -- Regards =dn From songofacandy at gmail.com Sat Jul 18 21:17:50 2020 From: songofacandy at gmail.com (Inada Naoki) Date: Sun, 19 Jul 2020 10:17:50 +0900 Subject: frozendict: an experiment In-Reply-To: References: Message-ID: On Sun, Jul 19, 2020 at 6:38 AM Marco Sulla wrote: > > On Sat, 18 Jul 2020 at 10:02, Inada Naoki wrote: >> >> On Sat, Jul 18, 2020 at 7:05 AM Marco Sulla >> wrote: >> > For what I know, CPython uses PyDictObject for kwargs. Since dicts are >> > mutable, it's a problem to cache them properly. >> >> On caller side, Python doesn't use dict at all. >> On callee side, dict is used for `**kwargs`. But changing it to frozendict is >> backward incompatible change. > > > Not sure of what you mean with caller and callee. If you're talking about Python, I agree, kwargs must be dicts. But I was talking about CPython and PyDictObject, that is used internally for kwargs. > I am talking about CPython VM. Caller is code calling Python. Callee is the function called. Look at the caller side first: # x.py foo(a=1, b=2) $ python3 -m dis x.py 1 0 LOAD_NAME 0 (foo) 2 LOAD_CONST 0 (1) 4 LOAD_CONST 1 (2) 6 LOAD_CONST 2 (('a', 'b')) 8 CALL_FUNCTION_KW 2 10 POP_TOP 12 LOAD_CONST 3 (None) 14 RETURN_VALUE As you can see, dict is not created during calling a function. On the other hand, if callee is defined as: def foo(a, b): ... CPython VM doesn't create a dict at all. If callee is defined as: def foo(**kwargs): ... The kwargs is dict, of course. And changing it to frozendict is not backward compatible. C function is similar. If the C function is defined using METH_KEYWORDS, keyword arguments are passed as dict. If the C function is defined using METH_FASTCALL, keyword arguments are passed as C array. > On Sat, 18 Jul 2020 at 10:02, Inada Naoki wrote: >> >> Currently, `for k,v in d.items()` >> doesn't create >> temporary list or set-like. >> I think using "real object" is not good performance optimization. > > > Well, this is true... but they create view objects that are quite slow. Is it really slow? It is just a thin wrapper object. How is it slow compared iter(list)? Iterator is just a thin wrapper too. Regards, -- Inada Naoki From vjp2.at at at.BioStrategist.dot.dot.com Sun Jul 19 03:36:52 2020 From: vjp2.at at at.BioStrategist.dot.dot.com (vjp2.at at at.BioStrategist.dot.dot.com) Date: Sun, 19 Jul 2020 07:36:52 +0000 (UTC) Subject: Jython but portable? Message-ID: How do you use Jython Standalone Jar? Do you have to "Intall"? I usually use most standalone jars directly without intalling. And I want to use this thing in Portable Apps, so I din't want to install anything. Because it might end up in my Windows system and I won't know until I try it at another computer (whish is hard during apandemic). I've got a lot of java jars in protable apps that work fine. i'm trying to use RDKit thru a call like Java RDKIT.jar;jython.jar -Djava.library.path=/lib/ I probably should post this here, but I've outstayed my welcome on the java ng asking very stupid questions - = - Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus blog: panix.com/~vjp2/ruminatn.htm - = - web: panix.com/~vjp2/vasos.htm facebook.com/vasjpan2 - linkedin.com/in/vasjpan02 - biostrategist.com ---{Nothing herein constitutes advice. Everything fully disclaimed.}--- From Gronicus at SGA.Ninja Sun Jul 19 03:46:12 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sun, 19 Jul 2020 03:46:12 -0400 Subject: Seeking to convert a py timer app for my Moto E6 In-Reply-To: References: <00b401d65cbc$68ec1e00$3ac45a00$@SGA.Ninja> Message-ID: <000c01d65da0$ad125a60$07370f20$@SGA.Ninja> Interesting "Declaimed"? (-: I am still trying to see how this system works. I do not recall receiving that comment nor do I recall receiving a copy of the original message as I did with the second one. Whatever... That first message did have a suggestion. I will check it out. Thanks.... FootNote: If money does not grow on trees, then why do banks have branches? -----Original Message----- From: Python-list On Behalf Of Dennis Lee Bieber Sent: Saturday, July 18, 2020 12:04 PM To: python-list at python.org Subject: Re: Seeking to convert a py timer app for my Moto E6 On Sat, 18 Jul 2020 00:32:12 -0400, "Steve" declaimed the following: I have nothing new to add to your inquiry other than to confirm that I distinctly saw the first time you posted it, about a week ago, and that you did get a response at that time. https://groups.google.com/forum/#!topic/comp.lang.python/lCJtqyg0tps -- Wulfraed Dennis Lee Bieber AF6VN wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ -- https://mail.python.org/mailman/listinfo/python-list From mats at python.org Sun Jul 19 09:49:54 2020 From: mats at python.org (Mats Wichmann) Date: Sun, 19 Jul 2020 07:49:54 -0600 Subject: A Python installation help doc much more friendly to newcomers? [Was Re: help] In-Reply-To: <285c8bb3-bfef-3000-10e6-173a54c04b66@DancesWithMice.info> References: <423596c5-602c-03ae-fadd-a6e394348d91@DancesWithMice.info> <285c8bb3-bfef-3000-10e6-173a54c04b66@DancesWithMice.info> Message-ID: <7568e431-d6da-10bb-3145-62192ba81807@python.org> On 7/18/20 5:02 PM, dn via Python-list wrote: > - most docs seem to try to be 'all things to all people', whereas the > differences between platforms inevitably make the writing complicated > and the reading difficult to follow. Thus, consider separating entries > by OpSys and/or installation method. Like https://docs.python.org/3/using/index.html ? From duncan at invalid.invalid Sun Jul 19 10:54:26 2020 From: duncan at invalid.invalid (duncan smith) Date: Sun, 19 Jul 2020 15:54:26 +0100 Subject: Confused about np.polyfit() In-Reply-To: References: Message-ID: On 19/07/2020 11:19, Dino wrote: > > Hi, I am looking at someone else's code trying to understand their use > of numpy.polyfit. > > My understanding was that you can use it to fit polynomials, but > apparently, the original author has used it for logarithmic and > exponential curves as well this way: > > Logarithmic > > ??? def fit_model(self): > ??????? self.coefficients = np.polyfit(np.log(self.x), self.y, 1) > > Exponential > > ??? def fit_model(self): > ??????? self.coefficients = np.polyfit(self.x, np.log(self.y), 1) > > is this an ok use of np.polyfit? Will it yield the expected result. > > Thanks It depends on what you expect the result to be. There's nothing inherently wrong with transforming variables before using least squares fitting. Whether it gives you the "best" estimates for the coefficients is a different issue. Duncan From narenchunduri at gmail.com Sun Jul 19 10:03:23 2020 From: narenchunduri at gmail.com (narenchunduri at gmail.com) Date: Sun, 19 Jul 2020 07:03:23 -0700 (PDT) Subject: Need a Dynamic vlookup using python In-Reply-To: References: <2f3cfd9b-7008-4d11-89e1-9733eab72fefo@googlegroups.com> <206bf286-f039-b98f-f476-cacfc80f6125@DancesWithMice.info> Message-ID: Any solution possible for this. Please let me know From ed at walseranalyticsconsulting.com Sun Jul 19 10:46:04 2020 From: ed at walseranalyticsconsulting.com (Ed Walser) Date: Sun, 19 Jul 2020 10:46:04 -0400 Subject: Request help w/pip install jq Message-ID: Hi all, I've tried installing jq several times in my local environment, but it fails, saying it can't find a file that pip downloads. Here is the entire pip output: (base) C:\Users\edwal>pip install jq Collecting jq Downloading jq-1.0.2.tar.gz (57 kB) |????????????????????????????????| 57 kB 703 kB/s Installing build dependencies ... done Getting requirements to build wheel ... done Preparing wheel metadata ... done Building wheels for collected packages: jq Building wheel for jq (PEP 517) ... error ERROR: Command errored out with exit status 1: command: 'C:\Users\edwal\anaconda3\envs\planet1\python.exe' 'C:\Users\edwal\anaconda3\envs\planet1\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\edwal\AppData\Local\Temp\tmpd0skcxv2' cwd: C:\Users\edwal\AppData\Local\Temp\pip-install-bwgrrs8c\jq Complete output (7 lines): running bdist_wheel running build running build_ext Downloading https://github.com/kkos/oniguruma/releases/download/v6.9.4/onig-6.9.4.tar.gz Downloaded https://github.com/kkos/oniguruma/releases/download/v6.9.4/onig-6.9.4.tar.gz Executing: ./configure CFLAGS=-fPIC --prefix=C:\Users\edwal\AppData\Local\Temp\pip-install-bwgrrs8c\jq\_deps\onig-install-6.9.4 error: [WinError 2] The system cannot find the file specified ---------------------------------------- ERROR: Failed building wheel for jq Failed to build jq ERROR: Could not build wheels for jq which use PEP 517 and cannot be installed directly -- Ed Walser ed at WalserAnalyticsConsulting.com 571.364.9618 From python at mrabarnett.plus.com Sun Jul 19 11:55:52 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 19 Jul 2020 16:55:52 +0100 Subject: Request help w/pip install jq In-Reply-To: References: Message-ID: <1ac1f51f-9883-30d7-77dd-70931338d3b2@mrabarnett.plus.com> On 2020-07-19 15:46, Ed Walser wrote: > Hi all, > > I've tried installing jq several times in my local environment, but it > fails, saying it can't find a file that pip downloads. Here is the entire > pip output: > > (base) C:\Users\edwal>pip install jq > > Collecting jq > > Downloading jq-1.0.2.tar.gz (57 kB) > > |????????????????????????????????| 57 kB 703 kB/s > > Installing build dependencies ... done > > Getting requirements to build wheel ... done > > Preparing wheel metadata ... done > > Building wheels for collected packages: jq > > Building wheel for jq (PEP 517) ... error > > ERROR: Command errored out with exit status 1: > > command: 'C:\Users\edwal\anaconda3\envs\planet1\python.exe' > 'C:\Users\edwal\anaconda3\envs\planet1\lib\site-packages\pip\_vendor\pep517\_in_process.py' > build_wheel 'C:\Users\edwal\AppData\Local\Temp\tmpd0skcxv2' > > cwd: C:\Users\edwal\AppData\Local\Temp\pip-install-bwgrrs8c\jq > > Complete output (7 lines): > > running bdist_wheel > > running build > > running build_ext > > Downloading > https://github.com/kkos/oniguruma/releases/download/v6.9.4/onig-6.9.4.tar.gz > > Downloaded > https://github.com/kkos/oniguruma/releases/download/v6.9.4/onig-6.9.4.tar.gz > > Executing: ./configure CFLAGS=-fPIC > --prefix=C:\Users\edwal\AppData\Local\Temp\pip-install-bwgrrs8c\jq\_deps\onig-install-6.9.4 > > error: [WinError 2] The system cannot find the file specified > > ---------------------------------------- > > ERROR: Failed building wheel for jq > > Failed to build jq > > ERROR: Could not build wheels for jq which use PEP 517 and cannot be > installed directly > I notice a mention of Anaconda in the traceback. Are you using Anaconda instead of the standard Python from python.org? If so, try using "conda" instead of "pip". From Richard at Damon-Family.org Sun Jul 19 12:21:31 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 19 Jul 2020 12:21:31 -0400 Subject: Confused about np.polyfit() In-Reply-To: References: Message-ID: <348a4482-368d-d005-07ff-924c5c6e3c4b@Damon-Family.org> On 7/19/20 10:54 AM, duncan smith wrote: > On 19/07/2020 11:19, Dino wrote: >> Hi, I am looking at someone else's code trying to understand their use >> of numpy.polyfit. >> >> My understanding was that you can use it to fit polynomials, but >> apparently, the original author has used it for logarithmic and >> exponential curves as well this way: >> >> Logarithmic >> >> ??? def fit_model(self): >> ??????? self.coefficients = np.polyfit(np.log(self.x), self.y, 1) >> >> Exponential >> >> ??? def fit_model(self): >> ??????? self.coefficients = np.polyfit(self.x, np.log(self.y), 1) >> >> is this an ok use of np.polyfit? Will it yield the expected result. >> >> Thanks > It depends on what you expect the result to be. There's nothing > inherently wrong with transforming variables before using least squares > fitting. Whether it gives you the "best" estimates for the coefficients > is a different issue. > > Duncan Or, to state the results a bit more precisely, the 'Least Squres' fit is defined as finding the values of the adjustable values that minimizes the error between the provided 'measured' data, and the fitted curve, where the error is defined as the (possbily weighted) sum of the square of the difference between measured value and predicted value. One very useful property of least squares fitting to a polynomial is that you can get a closed form set of equations to solve to find the 'optimal' values. The primary effect of transforming the data before doing the fit is the error is now defined in terms of the difference of the transformed values, not the original values. In many cases, this is actually a reasonable way to define your error, so it works. -- Richard Damon From mats at python.org Sun Jul 19 12:39:09 2020 From: mats at python.org (Mats Wichmann) Date: Sun, 19 Jul 2020 10:39:09 -0600 Subject: Request help w/pip install jq In-Reply-To: References: Message-ID: On 7/19/20 8:46 AM, Ed Walser wrote: > Hi all, > > I've tried installing jq several times in my local environment, but it > fails, saying it can't find a file that pip downloads. Here is the entire > pip output: > > (base) C:\Users\edwal>pip install jq Don't install that way, do: python -m pip install jq or, since you seem to be on Windows, if you use the Python Launcher, do: py -m pip install jq That won't help your problem, though. Which is: > Building wheels for collected packages: jq > > Building wheel for jq (PEP 517) ... error pip tries to install a wheel first, if it didn't find a suitable one, it gets the source package (generally called an sdist) and tried to build it. This usually fails on Windows, because Windows doesn't come with compilers by default, and even if installed, often goes awry anyway because the setups never seem to match. If people want you to build for Windows yourself, there will usually be a detailed description of how to get it set up the right way. That's the general story. Now the bad news: https://pypi.org/project/jq/#files there are in fact no wheels for Windows here. And on the main page https://pypi.org/project/jq/ there is no mention of Windows at all, so the guess would be it's not supported. You might search if someone has gotten this working / packaged it for Anaconda, since you seem to be using that. If so, you'll want to install it with the conda command, not pip. See suitable instructions within the Anaconda website. From duncan at invalid.invalid Sun Jul 19 12:39:03 2020 From: duncan at invalid.invalid (duncan smith) Date: Sun, 19 Jul 2020 17:39:03 +0100 Subject: Confused about np.polyfit() In-Reply-To: References: Message-ID: On 19/07/2020 16:11, Dino wrote: > On 7/19/2020 4:54 PM, duncan smith wrote: >> >> It depends on what you expect the result to be. There's nothing >> inherently wrong with transforming variables before using least squares >> fitting. Whether it gives you the "best" estimates for the coefficients >> is a different issue. > > Thanks a lot for this, Duncan. I guess I have to follow-up questions at > this point: > > 1) in which ways is this approach sub-optimal? > > 2) what's the "right" way to do it? > > Thank you > You'll have to read up a bit on ordinary least squares (e.g. https://en.wikipedia.org/wiki/Ordinary_least_squares). It is based on assumptions that might not necessarily hold for a given model / dataset. Depending on which assumptions are violated the estimates can be affected in different ways. It is usual to fit the model, then check the residuals to see if the assumptions (approximately) hold. If not, it might indicate a poor model fit or suggest fitting a transformed model (to estimate the same coefficients while satisfying the assumptions). e.g. For the latter case, Y = a + bX has the same coefficients as Y/X = a * 1/X + b but the latter regression might satisfy the assumption of constant variance for the errors. Regression analysis is a bit of an art, and it's a long time since I did any. Ordinary least squares is optimal in a certain sense when the assumptions hold. When they don't there's no single answer to what the best alternative is (unless it's employ a good statistician). Duncan From python at mrabarnett.plus.com Sun Jul 19 13:34:53 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 19 Jul 2020 18:34:53 +0100 Subject: Request help w/pip install jq In-Reply-To: References: Message-ID: <968738c6-5f21-415e-f9bf-89f2d7cccbff@mrabarnett.plus.com> On 2020-07-19 17:39, Mats Wichmann wrote: > On 7/19/20 8:46 AM, Ed Walser wrote: >> Hi all, >> >> I've tried installing jq several times in my local environment, but it >> fails, saying it can't find a file that pip downloads. Here is the entire >> pip output: >> >> (base) C:\Users\edwal>pip install jq > > Don't install that way, do: > > python -m pip install jq > > or, since you seem to be on Windows, if you use the Python Launcher, do: > > py -m pip install jq > > That won't help your problem, though. Which is: > >> Building wheels for collected packages: jq >> >> Building wheel for jq (PEP 517) ... error > > pip tries to install a wheel first, if it didn't find a suitable one, it > gets the source package (generally called an sdist) and tried to build > it. This usually fails on Windows, because Windows doesn't come with > compilers by default, and even if installed, often goes awry anyway > because the setups never seem to match. If people want you to build for > Windows yourself, there will usually be a detailed description of how to > get it set up the right way. > > That's the general story. > > Now the bad news: > > https://pypi.org/project/jq/#files > > there are in fact no wheels for Windows here. > > And on the main page > > https://pypi.org/project/jq/ > > there is no mention of Windows at all, so the guess would be it's not > supported. > > You might search if someone has gotten this working / packaged it for > Anaconda, since you seem to be using that. If so, you'll want to > install it with the conda command, not pip. See suitable instructions > within the Anaconda website. > This page mentions Windows: https://stedolan.github.io/jq/download/ From mats at python.org Sun Jul 19 15:03:13 2020 From: mats at python.org (Mats Wichmann) Date: Sun, 19 Jul 2020 13:03:13 -0600 Subject: Request help w/pip install jq In-Reply-To: <0909hfpsg74d69nfnnrqsvcvcdd4v40qur@4ax.com> References: <0909hfpsg74d69nfnnrqsvcvcdd4v40qur@4ax.com> Message-ID: On 7/19/20 11:42 AM, Dennis Lee Bieber wrote: > On Sun, 19 Jul 2020 10:39:09 -0600, Mats Wichmann > declaimed the following: > >> there is no mention of Windows at all, so the guess would be it's not >> supported. >> > There is a whole open "issue" for that... > > https://github.com/mwilliamson/jq.py/issues/20 > > and given that the last entry was two years ago, by someone asking if > there'd been any progress... I wouldn't hold out much hope for a > pre-packaged solution. > > I also have some problem believing that the install of a different > package manager allowed an install/build, but it does show up on > https://chocolatey.org/packages/jq and is a fairly recent version (last > September). > choco is a fine and useful tool, I use it lots. but I think what's there is the base jq package, not the Python bindings which would presumably the topic of interest in a Python mailing list. From mal at europython.eu Mon Jul 20 09:06:22 2020 From: mal at europython.eu (M.-A. Lemburg) Date: Mon, 20 Jul 2020 15:06:22 +0200 Subject: EuroPython 2020: Introducing our Diamond Sponsor Bloomberg Message-ID: We are very pleased to have Bloomberg as Diamond Sponsor for EuroPython 2020. Without sponsors like Bloomberg, we wouldn't be able to make the event affordable. You will be able to visit their sponsor exhibit rooms and take the opportunity to chat with their staff to learn more about the large Python eco-system they have built internally and how they are collaborating with the Python community. Please read a hosted blog post from Bloomberg on our blog with full detail: https://blog.europython.eu/post/624164489818980352/europython-2020-introducing-our-diamond-sponsor Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/post/624164489818980352/europython-2020-introducing-our-diamond-sponsor Tweet: https://twitter.com/europython/status/1285198014060154882 Thanks, -- EuroPython 2020 Team https://ep2020.europython.eu/ https://www.europython-society.org/ From jgossage at gmail.com Mon Jul 20 09:31:14 2020 From: jgossage at gmail.com (Jonathan Gossage) Date: Mon, 20 Jul 2020 09:31:14 -0400 Subject: Typing modules Message-ID: I have the following code and I would like to type the variable *contents*: contents: something = importlib._import_module(name) I have been unable to find out what *something* should be. -- Jonathan Gossage From stephan.lukits at gmail.com Mon Jul 20 12:13:09 2020 From: stephan.lukits at gmail.com (Stephan Lukits) Date: Mon, 20 Jul 2020 19:13:09 +0300 Subject: Typing modules In-Reply-To: References: Message-ID: <22B7A73B-C7F9-4410-9C52-7BD087C2F19D@gmail.com> > On 20 Jul 2020, at 16:31, Jonathan Gossage wrote: > > I have the following code and I would like to type the variable *contents*: > > contents: something = importlib._import_module(name) > > > I have been unable to find out what *something* should be. types.ModuleType > > -- > Jonathan Gossage > -- > https://mail.python.org/mailman/listinfo/python-list From lukasz at langa.pl Mon Jul 20 15:32:09 2020 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Mon, 20 Jul 2020 21:32:09 +0200 Subject: [RELEASE] Python 3.8.5 released as a security hotfix. 3.9.0b5, the last beta before 3.9.0, also available Message-ID: <1E8C372C-5FD4-41AF-A4DD-FA6609BA6C62@langa.pl> This is a combined release of Python 3.8.5 and 3.9.0b5. Both are significant but for different reasons. Let?s dig in! Security content in 3.8.5 We decided to release 3.8.5 ahead of schedule due to a number of security-related fixes. All details can be found in the change log but the gist is: CVE-2019-20907 : infinite loop in a maliciously created .tar file BPO-41288 : segmentation fault during unpickling of objects using a crafted NEWOBJ_EX opcode BPO-39603 : HTTP headers could be injected through a maliciously crafter method parameter in http.client the original fix for CVE-2020-15801 caused a regression in 3.8.4 (see: BPO-41304 ) A small number of other urgent regression fixes and quality-of-life improvements are also present in the release. Get the release here: https://www.python.org/downloads/release/python-385/ Maintenance releases for the 3.8 series will continue at the regular bi-monthly calendar, with 3.8.6 planned for mid-September 2020. The last beta of Python 3.9.0 now also available Python 3.9 is still in development. This release, 3.9.0b5, is the last of five planned beta release previews. Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their projects to support the new feature release. You can get 3.9.0b5 here: https://www.python.org/downloads/release/python-390b5/ The next pre-release, the first release candidate of Python 3.9.0, will be 3.9.0rc1. It is currently scheduled for 2020-08-10. Call to action We strongly encourage maintainers of third-party Python projects to test with 3.9 during the beta phase and report issues found to the Python bug tracker as soon as possible. While the release is planned to be feature complete entering the beta phase, it is possible that features may be modified or, in rare cases, deleted up until the start of the release candidate phase (2020-08-10). Our goal is have no ABI changes after beta 5 and as few code changes as possible after 3.9.0rc1, the first release candidate. To achieve that, it will be extremely important to get as much exposure for 3.9 as possible during the beta phase. Please keep in mind that this is a preview release and its use is not recommended for production environments. A reminder for core developers To help make Python 3.9.0 the best possible release, our Development Cycle section of the Python Developer?s Guide documents that: A branch preparing for an RC release can only have bugfixes applied that have been reviewed by other core developers. Generally, these issues must be severe enough (e.g. crashes) that they deserve fixing before the final release. All other issues should be deferred to the next development cycle, since stability is the strongest concern at this point. You cannot skip the peer review during an RC, no matter how small! Even if it is a simple copy-and-paste change, everything requires peer review from a core developer. Major new features of the 3.9 series, compared to 3.8 Some of the new major new features and changes in Python 3.9 are: PEP 584 , Union Operators in dict PEP 585 , Type Hinting Generics In Standard Collections PEP 593 , Flexible function and variable annotations PEP 602 , Python adopts a stable annual release cadence PEP 615 , Support for the IANA Time Zone Database in the Standard Library PEP 616 , String methods to remove prefixes and suffixes PEP 617 , New PEG parser for CPython BPO 38379 , garbage collection does not block on resurrected objects; BPO 38692 , os.pidfd_open added that allows process management without races and signals; BPO 39926 , Unicode support updated to version 13.0.0; BPO 1635741 , when Python is initialized multiple times in the same process, it does not leak memory anymore; A number of Python builtins (range, tuple, set, frozenset, list, dict) are now sped up using PEP 590 vectorcall; A number of Python modules (_abc, audioop, _bz2, _codecs, _contextvars, _crypt, _functools, _json, _locale, operator, resource, time, _weakref) now use multiphase initialization as defined by PEP 489 ; A number of standard library modules (audioop, ast, grp, _hashlib, pwd, _posixsubprocess, random, select, struct, termios, zlib) are now using the stable ABI defined by PEP 384 . (Hey, fellow core developer, if a feature you find important is missing from this list, let ?ukasz know .) We hope you enjoy the new releases! Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. Your friendly release team, Ned Deily @nad Steve Dower @steve.dower ?ukasz Langa @ambv From elbarbun at gmail.com Mon Jul 20 16:07:07 2020 From: elbarbun at gmail.com (Marco Sulla) Date: Mon, 20 Jul 2020 22:07:07 +0200 Subject: frozendict: an experiment Message-ID: I just finished to improve the performance of frozendict creation. The result is very promising. The speedup is about 30% for small dicts (8 items). For large dicts (1k items) is about 38% for dicts with only integers as keys and values, and 45% for dicts with only strings. There's also a little speedup in iteration. Here's the code: https://github.com/Marco-Sulla/cpython/commit/8d6c7f727a55d9d922c8a3a755fcb6c68ed26197 The benchmark output: Name: `constructor(d)`; Size: 8; Keys: int; Type: dict; Time: 2.956e-07 Name: `constructor(d)`; Size: 8; Keys: int; Type: frozendict; Time: 2.100e-07 //////////////////////////////////////////////////////////////////////////////// Name: `constructor(d)`; Size: 8; Keys: str; Type: dict; Time: 2.922e-07 Name: `constructor(d)`; Size: 8; Keys: str; Type: frozendict; Time: 2.095e-07 //////////////////////////////////////////////////////////////////////////////// Name: `constructor(d)`; Size: 1000; Keys: int; Type: dict; Time: 2.401e-05 Name: `constructor(d)`; Size: 1000; Keys: int; Type: frozendict; Time: 1.309e-05 //////////////////////////////////////////////////////////////////////////////// Name: `constructor(d)`; Size: 1000; Keys: str; Type: dict; Time: 1.822e-05 Name: `constructor(d)`; Size: 1000; Keys: str; Type: frozendict; Time: 1.115e-05 You can find the tests and the benchmark code here: https://github.com/Marco-Sulla/cpython/tree/master/frozendict/test Here is the entire output of the benchmark: https://github.com/Marco-Sulla/cpython/blob/master/frozendict/test/bench.txt Notice that d[key] and the constructor(pairs_sequence) is a little slower. I didn't touch them, so probably this is because I changed frozendict to a split dict. So I suppose there's a lot of room for other improvements. Equality check can be improved too, since the object address can be checked first. I think the major speedup is due the fact I implemented the solution with a split dict, as suggested by Inada. Even if some of the improvements could be applied to dict too, combined dicts could be more efficient and easy to use for sorting, insertion and deletion. From songofacandy at gmail.com Tue Jul 21 00:01:09 2020 From: songofacandy at gmail.com (Inada Naoki) Date: Tue, 21 Jul 2020 13:01:09 +0900 Subject: frozendict: an experiment In-Reply-To: References: Message-ID: On Tue, Jul 21, 2020 at 5:07 AM Marco Sulla wrote: > > I just finished to improve the performance of frozendict creation. The result is very promising. > > The speedup is about 30% for small dicts (8 items). For large dicts (1k items) is about 38% for dicts with only integers as keys and values, and 45% for dicts with only strings. Do you mean `frozendict(d)` where d is frozendict? If so, you don't need to create a new dict. You can just incref the d and return it. That is what we do in tuple and frozenset. > I think the major speedup is due the fact I implemented the solution with a split dict, as suggested by Inada. Even if some of the improvements could be applied to dict too, combined dicts could be more efficient and easy to use for sorting, insertion and deletion. > Oh, I don't recommend split dict until you find use case that you can share many keys. In general, combined dict is little faster and much efficient. -- Inada Naoki From elbarbun at gmail.com Tue Jul 21 04:28:06 2020 From: elbarbun at gmail.com (Marco Sulla) Date: Tue, 21 Jul 2020 10:28:06 +0200 Subject: frozendict: an experiment In-Reply-To: References: Message-ID: On Tue, 21 Jul 2020 at 06:01, Inada Naoki wrote: > On Tue, Jul 21, 2020 at 5:07 AM Marco Sulla wrote: > > > > I just finished to improve the performance of frozendict creation. The > result is very promising. > > > > The speedup is about 30% for small dicts (8 items). For large dicts (1k > items) is about 38% for dicts with only integers as keys and values, and > 45% for dicts with only strings. > > Do you mean `frozendict(d)` where d is frozendict? > No, I mean a dictionary. From mal at europython.eu Tue Jul 21 05:02:24 2020 From: mal at europython.eu (M.-A. Lemburg) Date: Tue, 21 Jul 2020 11:02:24 +0200 Subject: EuroPython 2020: Presenting our Conference Booklet Message-ID: Our designer Jessica has created a beautiful conference booklet for you to use during the conference and keep as a memory afterwards. It provides all details, schedule, keynotes, sponsor listings, etc. in a single PDF. * EuroPython 2020 Conference Booklet * https://ep2020.europython.eu/events/conference-booklet/ We'd normally give out the booklet as part of the conference bag, but since we?re running the event online, we?ve put up the PDF of the booklet instead for your to enjoy. If you feel like there something in our program which you may benefit from or you just want to get a feeling for what a EuroPython conference is like, please consider joining the event. Tickets still available ----------------------- Even though we have surpassed the 900 tickets mark already, we still have tickets available, both in form of the paid conference & sprint tickets as well as the free sprints-only tickets. Please head over to our registration page to book your tickets: https://ep2020.europython.eu/registration/buy-tickets/ Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/post/624240002899066880/europython-2020-presenting-our-conference-booklet Tweet: https://twitter.com/europython/status/1285498603360923656 Thanks, -- EuroPython 2020 Team https://ep2020.europython.eu/ https://www.europython-society.org/ From ksikor14 at yahoo.com Tue Jul 21 09:38:55 2020 From: ksikor14 at yahoo.com (ksikor14 at yahoo.com) Date: Tue, 21 Jul 2020 06:38:55 -0700 (PDT) Subject: Python Program Help Message-ID: <1df3b7cf-de3b-4803-ac87-75d1621b9738o@googlegroups.com> I can't seem to figure out what I am doing wrong. I have tried everything. This is what it is supposed to do: (1) Prompt the user for a title for data. Output the title. (1 pt) Ex: Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored (2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt) Ex: Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels You entered: Number of novels (3) Prompt the user for data points. Data points must be in this format: string, int. Store the information before the comma into a string variable and the information after the comma into an integer. The user will enter -1 when they have finished entering data points. Output the data points. Store the string components of the data points in a list of strings. Store the integer components of the data points in a list of integers. (4 pts) Ex: Enter a data point (-1 to stop input): Jane Austen, 6 Data string: Jane Austen Data integer: 6 (4) Perform error checking for the data point entries. If any of the following errors occurs, output the appropriate error message and prompt again for a valid data point. If entry has no comma Output: Error: No comma in string. (1 pt) If entry has more than one comma Output: Error: Too many commas in input. (1 pt) If entry after the comma is not an integer Output: Error: Comma not followed by an integer. (2 pts) Ex: Enter a data point (-1 to stop input): Ernest Hemingway 9 Error: No comma in string. Enter a data point (-1 to stop input): Ernest, Hemingway, 9 Error: Too many commas in input. Enter a data point (-1 to stop input): Ernest Hemingway, nine Error: Comma not followed by an integer. Enter a data point (-1 to stop input): Ernest Hemingway, 9 Data string: Ernest Hemingway Data integer: 9 (5) Output the information in a formatted table. The title is right justified with a minimum field width value of 33. Column 1 has a minimum field width value of 20. Column 2 has a minimum field width value of 23. (3 pts) Ex: Number of Novels Authored Author name | Number of novels -------------------------------------------- Jane Austen | 6 Charles Dickens | 20 Ernest Hemingway | 9 Jack Kerouac | 22 F. Scott Fitzgerald | 8 Mary Shelley | 7 Charlotte Bronte | 5 Mark Twain | 11 Agatha Christie | 73 Ian Flemming | 14 J.K. Rowling | 14 Stephen King | 54 Oscar Wilde | 1 (6) Output the information as a formatted histogram. Each name is right justified with a minimum field width value of 20. (4 pts) Ex: Jane Austen ****** Charles Dickens ******************** Ernest Hemingway ********* Jack Kerouac ********************** F. Scott Fitzgerald ******** Mary Shelley ******* Charlotte Bronte ***** Mark Twain *********** Agatha Christie ************************************************************************* Ian Flemming ************** J.K. Rowling ************** Stephen King ****************************************************** Oscar Wilde * Here is my code: data_title = input("Enter a title for the data:\n") print("You entered:", data_title) h1 = input("\nEnter the column 1 header:\n") print("You entered:", h1) h2 = input("\nEnter the column 2 header:\n") print("You entered:", h2) point = input("\nEnter a data point (-1 to stop input):\n") data = [] while point != "-1": words = point.split(",") if len(words) == 1: print("Error: No comma in string.") elif len(words) > 2: print("Error: Too many commas in input. ") else: try: author = words[0] num_novels = int(words[1]) print("Author:", author) print("Number of Novel(s):", num_novels) data.append((author, num_novels)) except ValueError: print("Error: Comma not followed by an integer.") point = input("\nEnter a data point (-1 to stop input):\n") print("%33s" % data_title) print("%-20s|%23s" % (h1, h2)) print("-" * 44) for item in data: print("%-20s|%23d" % (item[0], item[1])) for item in data: print("%20s %s" % (item[0], '*' * item[1])) I get this error: Traceback (most recent call last): File "main.py", line 1, in data_title = input("Enter a title for the data:\n") EOFError: EOF when reading a line And can't seem to figure out how to correct it any help would be greatly appreciated. From python at mrabarnett.plus.com Tue Jul 21 11:08:41 2020 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 21 Jul 2020 16:08:41 +0100 Subject: Python Program Help In-Reply-To: <1df3b7cf-de3b-4803-ac87-75d1621b9738o@googlegroups.com> References: <1df3b7cf-de3b-4803-ac87-75d1621b9738o@googlegroups.com> Message-ID: <27d38725-a695-1012-eb39-31b6b08d798e@mrabarnett.plus.com> On 2020-07-21 14:38, ksikor14--- via Python-list wrote: > I can't seem to figure out what I am doing wrong. I have tried everything. This is what it is supposed to do: > > (1) Prompt the user for a title for data. Output the title. (1 pt) > > Ex: > > Enter a title for the data: > Number of Novels Authored > You entered: Number of Novels Authored > [snip] > > Here is my code: > > data_title = input("Enter a title for the data:\n") > print("You entered:", data_title) > h1 = input("\nEnter the column 1 header:\n") > print("You entered:", h1) > h2 = input("\nEnter the column 2 header:\n") > print("You entered:", h2) > point = input("\nEnter a data point (-1 to stop input):\n") > > data = [] > while point != "-1": > words = point.split(",") > if len(words) == 1: > print("Error: No comma in string.") > elif len(words) > 2: > print("Error: Too many commas in input. ") > else: > try: > author = words[0] > num_novels = int(words[1]) > print("Author:", author) > print("Number of Novel(s):", num_novels) > data.append((author, num_novels)) > except ValueError: > print("Error: Comma not followed by an integer.") > point = input("\nEnter a data point (-1 to stop input):\n") > > print("%33s" % data_title) > print("%-20s|%23s" % (h1, h2)) > print("-" * 44) > for item in data: > print("%-20s|%23d" % (item[0], item[1])) > for item in data: > print("%20s %s" % (item[0], '*' * item[1])) > > I get this error: > > Traceback (most recent call last): > File "main.py", line 1, in > data_title = input("Enter a title for the data:\n") > EOFError: EOF when reading a line > > And can't seem to figure out how to correct it any help would be greatly appreciated. > How are you running it? At a system prompt with: py main.py or similar? From hjp-python at hjp.at Tue Jul 21 13:25:06 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 21 Jul 2020 19:25:06 +0200 Subject: Friday Finking: Limiting parameters In-Reply-To: <74d1c5a1-cdf6-fc5c-17a4-89104b4c9e4d@DancesWithMice.info> References: <20200711201319.GA959@hjp.at> <74d1c5a1-cdf6-fc5c-17a4-89104b4c9e4d@DancesWithMice.info> Message-ID: <20200721172506.GA13397@hjp.at> On 2020-07-12 08:56:47 +1200, DL Neil via Python-list wrote: > On 12/07/20 8:13 AM, Peter J. Holzer wrote: > > On 2020-07-11 09:54:33 +1200, dn via Python-list wrote: > > > Questions: > > > > > > Is the idea of limiting the number of parameters passed across an interface > > > a real concern or somewhat an affectation? > > > > > > Is three, five, seven, ... a valid limit (or warning-signal)? > > > > > > Do you have a personal or corporate style or 'standard' to limit parameter > > > lists to seven parameters, or some other number? > > > > > > Given that Python enables labeled arguments ("keyword arguments"), does the > > > concern really only apply to 'us' in terms of numbers of "positional > > > arguments"? > > > > Keyword arguments greatly ameliorate the problems I have with long > > parameter lists. While I think that calling a function with 7 positional > > parameters is pretty much unreadable, with 7 named parameters (or maybe > > 2 positional and 5 named parameters) it doesn't bother me much. The > > definition of the function might have even more parameters, as long as > > most of them are optional and have sensible defaults (subprocess.Popen > > with 20 parameters (if I counted correctly) is pushing it, though). > > Do you think, then, that the maxima should be applied to the number of > arguments that will appear in the 'expected usage' of the routine? (cf the > def's parameter-list) After all, calling Popen would rarely require all-20 > arguments be stated, given the acceptability of the defaults and the > irrelevance of many 'special cases'. Yes, pretty much. For typical usage, only a few parameters are needed, and therefore those are the only ones a programmer has to remember. For the others ... When reading code which uses an unfamiliar named parameter, looking it up is straightforward, so no big deal. When writing code, the programmer has to remember (or at least suspect) that the function can do something to be able to look it up - so with a large number of parameters there is a certain risk that the doesn't even think of checking the docs. So a function with a large number of rarely used parameters is still harder to use correctly than one with fewer parameters, but not much. > Alternately/additionally, do you feel that the power and readability of > Python's keyword-arguments + default-values, requires a modification of the > advice to only limit the number of positional-arguments? Depends on the advice :-). But yes, I think the advice for a language which supports named parameters should be different than than for a language which doesn't. > Another discussion-point (which may be difficult because 'the answer' may > vary according to implementation-requirements): rather than one do-it-all > 'Swiss Army Knife' of a routine with dozens of parameters, might it be > better-practice to code a number of methods/functions to take care of the > special-cases, with a single 'core function' to carry-out the basic > operations-required? (in a class environment: sub-classes maybe) I think this depends a lot on the situation. If you have clearly distinguished scenarios where you would have to use a specific set of parameters, a set of functions (or methods, or subclasses) may help to provide "the obvious way to do it". If that's not so clear or if that would prevent some (legitimate) use-cases, the swiss army knife is probably better. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From hjp-python at hjp.at Tue Jul 21 13:37:26 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 21 Jul 2020 19:37:26 +0200 Subject: Friday Finking: Limiting parameters In-Reply-To: <3b0af018-73f3-df41-9042-687eed5a4a63@DancesWithMice.info> References: <617af290-3ffd-4cad-a992-49a70ecfc9e6@DancesWithMice.info> <65D21327-CAAC-4D3A-B5E2-859D170FB8EC@barrys-emacs.org> <3b0af018-73f3-df41-9042-687eed5a4a63@DancesWithMice.info> Message-ID: <20200721173726.GB13397@hjp.at> On 2020-07-13 17:21:40 +1200, dn via Python-list wrote: > On 12/07/20 10:10 PM, Barry Scott wrote: > > I'd expect to see something like this: > > > > def mail_label( person, address ): > > first_name = person.first_name > > # or if you want a function interface > > first_line_of_address = address.get_first_line() > > Does this idea move whole objects across the interface? (see earlier in the > thread) Assigning an object in Python only copies a pointer (and may adjust some house-keeping info, like a reference count). So it doesn't matter whether the object has 5 fields or 50. The function will only access those it knows about and ignore the rest. One might argue that mail_label should be a method of the person object because it depends on the person (e.g., depending on the ethnicity of the person the name might be written "first_name last_name" or "last_name firstname"). OTOH a person may have many addresses (and an address shared by many people), so a function which combines a person and address (which therefore can't be a method of either person or address) may be better. Maybe that should be treated as a model-view relationship: You have two models (person and address) and a view (which combines some aspects of both while ignoring others). hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From peter.slizik at gmail.com Tue Jul 21 05:32:59 2020 From: peter.slizik at gmail.com (=?UTF-8?B?UGV0ZXIgU2zDrcW+aWs=?=) Date: Tue, 21 Jul 2020 11:32:59 +0200 Subject: Iterators, iterables and special objects Message-ID: Hi list, two related questions: 1. Why do functions used to iterate over collections or dict members return specialized objects like type(dict.keys()) -> class 'dict_keys' type(dict.values()) -> class 'dict_values' type(dict.items()) -> class 'dict_items' type(filter(..., ...)) -> class 'filter' type(map(..., ...)) -> class 'map' type(enumerate(...)) -> class 'enumerate' instead of returning some more general 'iterable' and 'view' objects? Are those returned objects really that different from one another that it makes sense to have individual implementations? 2. Why do these functions return iterators instead of iterables? First, I find it confusing - to me, it is the loop's job to create an iterator from the supplied iterable, and not the object that is being iterated over. And second, with this design, iterators are required to be iterables too, which is confusing as hell (at least for people coming from other languages in which the distinction is strict). Thanks, Peter From cs at kls-system.de Tue Jul 21 07:40:05 2020 From: cs at kls-system.de (Christian SCHEIBER / KLS GmbH) Date: Tue, 21 Jul 2020 13:40:05 +0200 Subject: Upgrade from Python 3.6 to 3.8 and cx-freeze is not available more In-Reply-To: <000001d65d75$a8105dd0$f8311970$@kls-system.de> References: <000001d65d75$a8105dd0$f8311970$@kls-system.de> Message-ID: <015401d65f53$adecf440$09c6dcc0$@kls-system.de> I?d like to do exe files, so the pythin interpreter has not tob e installed. That?s why I use cx-freeze, but installing Python 3.8 after using Python 3.6 does not work. Can you tell me how I can make cx-freeze in Python 3.8 or how I can produce exe files for Windows 7 32 / 64 Bit and Win10? Thanx in advance Mit freundlichen Gr??en Christian Scheiber From wasdeq68 at gmail.com Tue Jul 21 09:37:13 2020 From: wasdeq68 at gmail.com (Wasdeq68) Date: Tue, 21 Jul 2020 14:37:13 +0100 Subject: Python Scripts Message-ID: im having problems when running python scripts When running the scripts it always closes immediately From David.Raymond at tomtom.com Tue Jul 21 14:35:23 2020 From: David.Raymond at tomtom.com (David Raymond) Date: Tue, 21 Jul 2020 18:35:23 +0000 Subject: Python Scripts In-Reply-To: References: Message-ID: > im having problems when running python scripts > > When running the scripts it always closes immediately If you're running it in Windows, and running it by double clicking on a .py file, then it will pop up a console window while it's running, and then immediately close that window when the script is complete. So if the script is failing immediately or even succeeding quickly, then the window with all the output is closing immediately too. If this is what's going on with you, you can open the console first and run the scripts from there. That way all their output will still be there for you to see when it's complete. Alternatively as a temporary debugging solution you could surround the main part (or all) of the script in a try statement and in the except clause have a "hit enter to continue" bit to freeze it before it closes the window. import traceback try: stuff except: traceback.print_exc() raise finally: input("Hit Enter to close") From tjreedy at udel.edu Tue Jul 21 15:25:42 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 21 Jul 2020 15:25:42 -0400 Subject: Python Program Help In-Reply-To: <27d38725-a695-1012-eb39-31b6b08d798e@mrabarnett.plus.com> References: <1df3b7cf-de3b-4803-ac87-75d1621b9738o@googlegroups.com> <27d38725-a695-1012-eb39-31b6b08d798e@mrabarnett.plus.com> Message-ID: On 7/21/2020 11:08 AM, MRAB wrote: > On 2020-07-21 14:38, ksikor14--- via Python-list wrote: >> I can't seem to figure out what I am doing wrong.? I have tried >> everything.? This is what it is supposed to do: [snip] >> I get this error: >> >> Traceback (most recent call last): >> ?? File "main.py", line 1, in >> ???? data_title = input("Enter a title for the data:\n") >> EOFError: EOF when reading a line The only way I discovered to get that error, on Windows, is to hit control-D in response to the prompt. This is not a bug in your program, but part of standard interactive program on *nix, copied by Python on Windows also. If the user who hits ^D does not mean to stop the program, then it is a user bug. >> And can't seem to figure out how to correct it any help would be >> greatly appreciated. >> > How are you running it? At a system prompt with: > > py main.py > > or similar? And what OS and what response did you make as the 'user'? -- Terry Jan Reedy From David.Raymond at tomtom.com Tue Jul 21 15:48:40 2020 From: David.Raymond at tomtom.com (David Raymond) Date: Tue, 21 Jul 2020 19:48:40 +0000 Subject: Python Scripts In-Reply-To: References: Message-ID: Remember to reply-all, so that python-list is included and can still see responses and offer help. If Python won't open them, then how do you know the scripts work? They work on someone else's computer you mean? Please provide the basics then so we can try to help out. What OS are you using? How are you trying to start Python/run the scripts? Are there any exceptions, error messages, etc when you try to run it? Can you successfully run any other Python script, or is it just this one that's a problem? What is in the script? (can be a summary to start with if the script is long) What version of Python are you using? Etc... > no the scripts work but python wont open them > >> im having problems when running python scripts >> >> When running the scripts it always closes immediately From tjreedy at udel.edu Tue Jul 21 15:54:10 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 21 Jul 2020 15:54:10 -0400 Subject: Iterators, iterables and special objects In-Reply-To: References: Message-ID: On 7/21/2020 5:32 AM, Peter Sl??ik wrote: > Hi list, two related questions: > > 1. Why do functions used to iterate over collections or dict members return > specialized objects like > > type(dict.keys()) -> class 'dict_keys' > type(dict.values()) -> class 'dict_values' > type(dict.items()) -> class 'dict_items' > type(filter(..., ...)) -> class 'filter' > type(map(..., ...)) -> class 'map' > type(enumerate(...)) -> class 'enumerate' > > instead of returning some more general 'iterable' and 'view' objects? Are > those returned objects really that different from one another that it makes > sense to have individual implementations? Yes. The dict views have to know how the dict is implemented to extract the keys, values, or pairs thereof. The transformers each have different code. I suppose that each could instead pass a function to a generic 'transformer' class, but the indirection would just make execution slower and hide the specific info as to what the iterator is doing. > 2. Why do these functions return iterators instead of iterables? The view are iterables. They can be iterated more than once and used in other operations. The transformers should be once-through iterators because they can be passed once-through interators. I suppose one could make them iterables and add an attribute 'pristine' set to True in __init__ and False in __iter__, but why have 2 objects instead of 1 when there is not gain in function? > First, I > find it confusing - to me, it is the loop's job to create an iterator from > the supplied iterable, and not the object that is being iterated over. Python's design that iter(iterator) is iterator is extremely handy. Note that iterators can be driven directly with next(), and not only indirectly with for... Suppose line iterator 'file' has a header line with field names and multiple data lines. One can do it = iter(file) fields = next(file) for line in it: Yes, one can add a flag variable 'first = True' and inside the loop if first: first = False fields = line but the 3 extra boilerplate lines add nothing. And > second, with this design, iterators are required to be iterables too, which > is confusing as hell (at least for people coming from other languages in > which the distinction is strict). I guess I was fortunate to not have to unlearn anything ;-). -- Terry Jan Reedy From PythonList at DancesWithMice.info Tue Jul 21 16:58:19 2020 From: PythonList at DancesWithMice.info (dn) Date: Wed, 22 Jul 2020 08:58:19 +1200 Subject: Python Program Help In-Reply-To: References: <1df3b7cf-de3b-4803-ac87-75d1621b9738o@googlegroups.com> Message-ID: On 7/22/20 7:16 AM, Dennis Lee Bieber wrote: > On Tue, 21 Jul 2020 06:38:55 -0700 (PDT), ksikor14--- via Python-list > declaimed the following: > Since this is apparently a homework assignment, I'm not going to > provide fixes -- just some comments. Logic error? (not entirely poking-fun: is a good learning opportunity for OP!) >> (3) Prompt the user for data points. Data points must be in this format: string, int. Store the information before the comma into a string variable and the information after the comma into an integer. The user will enter -1 when they have finished entering data points. Output the data points. Store the string components of the data points in a list of strings. Store the integer components of the data points in a list of integers. (4 pts) > > Ugh! Forgive my bluntness but WHO created that "enter -1" to signal the > end of the data input, especially when the input format is a string > followed by an integer, using a comma to differentiate the fields. Python > makes it so easy to use an /empty input line/ to signal end of data. Am fairly sure that I've seen this question before - likely requiring implementation in another language. (FORTRAN, BASIC-Plus on a VAX or RSTS-machine c.1970s?) Agreed, poor form old-chap - just not cricket, wot! >> (4) Perform error checking for the data point entries. If any of the following errors occurs, output the appropriate error message and prompt again for a valid data point. >> >> If entry has no comma >> Output: Error: No comma in string. (1 pt) >> If entry has more than one comma >> Output: Error: Too many commas in input. (1 pt) >> If entry after the comma is not an integer >> Output: Error: Comma not followed by an integer. (2 pts) > Personally -- besides that I'd use an empty record to end input, I processing- Despite the fact that it would be an easy mistake for a user to make - pressing Enter? Would it not be better to require an active decision/action? > would NOT use "...:\n" in the prompt strings. To me it is much cleaner to > use "...: " as the prompt, which puts the input data on the same line. +1 User Experience accounts for a significant proportion of the definition of 'success', for any project! > This coding style requires duplicating code... It also is relying on ... > That makes two places that need to be edited if a change is made to the > code. Especially if you try to sanitize the termination input. It is +1 >> words = point.split(",") >> if len(words) == 1: >> print("Error: No comma in string.") >> elif len(words) > 2: >> print("Error: Too many commas in input. ") > > Personally, I'd consider this an overly strict requirement -- I'd be > expecting the /last/ ", stuff" to be the integer, and anything prior to be > part of the author name ("Alexandre Dumas, Senior, 238") Disagree - and one of the points of the exercise: Librarians have tomes inches-thick which discuss 'cataloging rules' - including where commas may, and may-not, be used! Your point valid though, only the comma has significance... (at this time!) > It is apparent that no test is made to ensure names output are > shortened to the report format... One "improvement" would be to retain the > maximum name length (and maximum count) and adjust the output formatting to > fit those maximums. Data should not be 'thrown away'! If the report-specification 'shortens' the data-field, then isn't that the purpose of output-formatting? Given all the 'pretty', I'd suggest that the learning-objectives* include Python's string formatting language! * um, er, given earlier comment about age/language, perhaps the words "should have" should have appeared in that sentence? -- Regards =dn From PythonList at DancesWithMice.info Tue Jul 21 18:34:15 2020 From: PythonList at DancesWithMice.info (dn) Date: Wed, 22 Jul 2020 10:34:15 +1200 Subject: Iterators, iterables and special objects In-Reply-To: References: Message-ID: On 7/21/20 9:32 PM, Peter Sl??ik wrote: > Hi list, two related questions: > > 1. Why do functions used to iterate over collections or dict members return > specialized objects like > > type(dict.keys()) -> class 'dict_keys' > type(dict.values()) -> class 'dict_values' > type(dict.items()) -> class 'dict_items' > type(filter(..., ...)) -> class 'filter' > type(map(..., ...)) -> class 'map' > type(enumerate(...)) -> class 'enumerate' > > instead of returning some more general 'iterable' and 'view' objects? Are > those returned objects really that different from one another that it makes > sense to have individual implementations? The key-word here is "light-weight"! (or is that two, words?) These do not duplicate the keys/values in the dict (example), and thus have no (real) storage requirements (think thousands of values). We could think of them as an access channel or 'pipe' - they are a "view" of the data if you follow the database-terminology. Another analogy is to "generators". A generator will yield successive data items, but will not compute or take storage resources for all of the values it will return, instead performing in a 'lazy' fashion or JiT (Just-in-time) delivery. Similarly, once a generator is "exhausted", it terminates. It cannot be re-used, without being re-computed. For your reading pleasure: PEP 3106 -- Revamping dict.keys(), .values() and .items() https://www.python.org/dev/peps/pep-3106/ > 2. Why do these functions return iterators instead of iterables? First, I > find it confusing - to me, it is the loop's job to create an iterator from > the supplied iterable, and not the object that is being iterated over. And > second, with this design, iterators are required to be iterables too, which > is confusing as hell (at least for people coming from other languages in > which the distinction is strict). This is a great question. (even if I'm motivated to say-so because it puzzled me too!) However, may I caution you not to expect that just because one language 'thinks' in a certain manner, that another/every-other language must do the same, eg in English we say "blue ball" but in other spoken-languages it may be expressed in the sequence "ball, blue". Which is correct? ...more correct? (well, 'mine', of course! Cue Frank Sinatra: "I did it my way...") Some more reading, which also under-pins and expands the above web.ref: https://docs.python.org/3/library/stdtypes.html If 'everything' in Python is an "object", then some objects will contain multiple values. One would expect that these multiple values would be "iterable" (one could "iterate" over them). However, does the object provide a method to perform this iteration-function? If it does, then that object is also an "iterator"! However, as @Terry explained, there is *no requirement* that a multi-valued object provide such a method. Per above, the "return iterators instead of iterables" decision comes back to 'weight'. No 'copy' of the iterable object is made, only iterator functionality is provided, eg to a for-loop. It is also an example of Python's "we're all adults here" laissez-faire and dynamic philosophy: there is no rule that iterable <==> iterator! A final thought for your consideration, is that Python considers functions (and methods) "first-class objects". Which means that they can be passed as arguments/parameters, for example. In some ways then, it may be helpful to think of an iterator (or generator) method as a function being passed to the for-loop's 'control function'. (others may dislike this picture, so don't tell anyone I said-so...) Further tutorials you may find helpful: https://towardsdatascience.com/python-basics-iteration-and-looping-6ca63b30835c https://www.w3schools.com/python/gloss_python_iterator_vs_iterable.asp https://www.tutorialspoint.com/difference-between-python-iterable-and-iterator https://www.python-course.eu/python3_iterable_iterator.php -- Regards =dn From python.list at tim.thechases.com Tue Jul 21 20:38:27 2020 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 21 Jul 2020 19:38:27 -0500 Subject: True is True / False is False? Message-ID: <20200721193827.6182114f@bigbox.attlocal.net> I know for ints, cpython caches something like -127 to 255 where `is` works by happenstance based on the implementation but not the spec (so I don't use `is` for comparison there because it's not guaranteed by the language spec). On the other hand, I know that None is a single object that can (and often *should*) be compared using `is`. However I spent some time reading through the language specs and didn't encounter anything about booleans returned from comparisons-operators, guaranteeing that they always return The One True and The One False. x = 3 == 3 # some boolean expression evaluating to True/False y = 4 > 0 # another boolean expression if x is y: print("cool, same as always") else: print("is this ever possible?") Is there some theoretical world in which that `else` branch could ever be hit because the True referenced by x is not the same True referenced by y? (assuming non-pathological overriding of dunder methods to return true-ish or false-ish values; or at least assuming any dunder-overriding is pure standard-library) In the big picture, this is likely irrelevant and I should just use "==" instead, but I got the question stuck in my head and ended up bothered that I couldn't disinter an answer from docs. Thanks, -tkc From rosuav at gmail.com Tue Jul 21 21:09:43 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jul 2020 11:09:43 +1000 Subject: True is True / False is False? In-Reply-To: <20200721193827.6182114f@bigbox.attlocal.net> References: <20200721193827.6182114f@bigbox.attlocal.net> Message-ID: On Wed, Jul 22, 2020 at 11:04 AM Tim Chase wrote: > > I know for ints, cpython caches something like -127 to 255 where `is` > works by happenstance based on the implementation but not the spec > (so I don't use `is` for comparison there because it's not > guaranteed by the language spec). On the other hand, I know that None > is a single object that can (and often *should*) be compared using > `is`. However I spent some time reading through the language specs and > didn't encounter anything about booleans returned from > comparisons-operators, guaranteeing that they always return The One > True and The One False. class bool(int) | bool(x) -> bool | | Returns True when the argument x is true, False otherwise. | The builtins True and False are the only two instances of the class bool. | The class bool is a subclass of the class int, and cannot be subclassed. The docstring (shown here in "help(bool)") says clearly that you'll only ever have those two instances and no others, so yes, it's a language guarantee that you'll always get the exact same objects. That said, though, a comparison isn't required to return a bool. If it *does* return a bool, it has to be one of those exact two, but it could return anything it chooses. But for built-in types and most user-defined types, you will indeed get a bool. ChrisA From macrakis at alum.mit.edu Tue Jul 21 21:31:35 2020 From: macrakis at alum.mit.edu (Stavros Macrakis) Date: Tue, 21 Jul 2020 21:31:35 -0400 Subject: How to limit *length* of PrettyPrinter Message-ID: I see how to limit the *depth* in pretty-printing: import pprint pprint.PrettyPrinter(depth=2).pprint(((11,12,13),(21,22,23,(241,242,243),25,26,27))) ((11, 12, 13), (21, 22, 23, (...), 25, 26, 27)) But I would also like to limit the *length, *something like this: pprint.PrettyPrinter(depth=2,length=4 ).pprint(((11,12,13),(21,22,23,(241,242,243),25,26,27))) ((11, 12, 13), (21, 22, 23, (...), ...)) # Only show first 4 elements How can I do that? Thanks, -s -------------------------- This is inspired by Lisp's *print-length*, e.g.: (setq *print-level* 2 *print-length* 4) '((11 12 13) (21 22 23 (241 242 243) 25 26 27)) ((11 12 13) (21 22 23 # ...)) From PythonList at DancesWithMice.info Tue Jul 21 22:37:54 2020 From: PythonList at DancesWithMice.info (dn) Date: Wed, 22 Jul 2020 14:37:54 +1200 Subject: How to limit *length* of PrettyPrinter In-Reply-To: References: Message-ID: On 7/22/20 1:31 PM, Stavros Macrakis wrote: > I see how to limit the *depth* in pretty-printing: > > import pprint > pprint.PrettyPrinter(depth=2).pprint(((11,12,13),(21,22,23,(241,242,243),25,26,27))) > ((11, 12, 13), > (21, 22, 23, (...), 25, 26, 27)) > > But I would also like to limit the *length, *something like this: > > pprint.PrettyPrinter(depth=2,length=4 > ).pprint(((11,12,13),(21,22,23,(241,242,243),25,26,27))) > ((11, 12, 13), > (21, 22, 23, (...), ...)) # Only show first 4 elements > > How can I do that? That's 'a bit of an ask' given that the four elements could be of any data-type (object)! Secondly, I'm having difficulty working-out how you wish to define "element". 1 Limit the input: If you know the input, in the example it is nested tuple, then it would be trivial to slice the collection *before* passing to pprint, eg >>> t = ( 1, 2, 3, 4 ) >>> t[ :2 ] (1, 2) >>> pprint.pprint( t[ :2 ] ) (1, 2) However, if the second element were an embedded collection, then that idea suffers a similar short-coming to the existing depth parameter! 1a That said, if you also know the hierarchy, you could get really clever with a recursive function which 'pops' the first element from any given hierarchical construct, to the required number of elements. Sounds like a 'fun' (ie dastardly) project to assign coding trainees! (this list doesn't accept graphic attachments otherwise I'd demonstrate my vicious grin...) PS should you try this, would welcome a copy (off-list). 2 Limit the output: Remember that the signature is: class pprint.PrettyPrinter(indent=1, width=80, depth=None, stream=None, *, compact=False, sort_dicts=True) How about capturing the stream output? Could you then post-process that by counting commas! NB I have never tried capturing the stream o/p! - or if you really want to 'go nuts', dust-off your polish notation and count opening and closing parentheses as well... 2a One has to wonder though, why not grab the output stream and print only the first n-characters? (on the grounds that 'close-enough is good-enough'. However, it's your spec...) -- Regards =dn From mathiarmymech at gmail.com Wed Jul 22 00:46:37 2020 From: mathiarmymech at gmail.com (Mathiyazhagan S) Date: Wed, 22 Jul 2020 10:16:37 +0530 Subject: "OSError: [Errno 9] Bad file descriptor" When I try to Install the library in conda prompt Message-ID: Dear Sir/Madam, I'm new to the python program. I'm trying to install the "numby" or anything to add into the library by using the windows command prompt I'm getting some error please find the attachment. So please help me to resolve this issue. Thank you From PythonList at DancesWithMice.info Wed Jul 22 01:35:28 2020 From: PythonList at DancesWithMice.info (dn) Date: Wed, 22 Jul 2020 17:35:28 +1200 Subject: "OSError: [Errno 9] Bad file descriptor" When I try to Install the library in conda prompt In-Reply-To: References: Message-ID: <88e9ae8f-c43b-d627-5c79-1e943b541d6b@DancesWithMice.info> On 7/22/20 4:46 PM, Mathiyazhagan S wrote: > Dear Sir/Madam, > I'm new to the python program. > > I'm trying to install the "numby" or anything to add into the library by > using the windows command prompt I'm getting some error please find the > attachment. > > So please help me to resolve this issue. Unfortunately, this list does not accept non-text attachments. Please copy-paste the relevant messages directly into the email message. Please add information about your machine's OpSys, the Python version, etc. Do you mean "numpy"? Have you read the Conda instructions, Python docs, and the NumPy docs (if relevant)? -- Regards =dn From mal at europython.eu Wed Jul 22 05:22:47 2020 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 22 Jul 2020 11:22:47 +0200 Subject: EuroPython 2020: Data Science Track Message-ID: <9d6bdb49-c416-67ae-0110-fe1b77269f59@europython.eu> We are excited to announce a complete two day data science track at EuroPython 2020 Online, happening on Thursday and Friday (July 23 - 24). Yes, that?s starting tomorrow. Sorry for the short notice :-) * Data Science @ EuroPython 2020 * https://ep2020.europython.eu/events/data-science/ The data science track is part of EuroPython 2020, so you won?t need to buy an extra ticket to attend. We will have a two day track featuring more than 20 keynotes, full-length talks and posters: - Keynotes in the Microsoft Room - Talks in the Parrot Room - Posters in the Poster Rooms The full program is available on our data science page: https://ep2020.europython.eu/events/data-science/ If you?d like to attend the data science track at EuroPython 2020, please register for EuroPython 2020 soon. Dates and Registration ---------------------- EuroPython 2020 will be held online from July 23-26 2020. You can register on our website: https://ep2020.europython.eu/registration/buy-tickets/ If you want to learn more about the online setup, please check the Setup section on our website: https://ep2020.europython.eu/setup/online-conference/ After buying a ticket, please register on our Discord server, following the instructions in the order confirmation email. You will even be able to buy tickets on the days themselves, however, please be aware that this may cause delays in your Discord signup. Please see our website for more information. Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/post/624331411913146368/europython-2020-data-science-track Tweet: https://twitter.com/europython/status/1285864453511294976 Thanks, -- EuroPython 2020 Team https://ep2020.europython.eu/ https://www.europython-society.org/ From oscar.j.benjamin at gmail.com Wed Jul 22 06:54:30 2020 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 22 Jul 2020 11:54:30 +0100 Subject: True is True / False is False? In-Reply-To: References: <20200721193827.6182114f@bigbox.attlocal.net> Message-ID: On Wed, 22 Jul 2020 at 02:12, Chris Angelico wrote: > > On Wed, Jul 22, 2020 at 11:04 AM Tim Chase > wrote: > > > > I know for ints, cpython caches something like -127 to 255 where `is` > > works by happenstance based on the implementation but not the spec > > (so I don't use `is` for comparison there because it's not > > guaranteed by the language spec). On the other hand, I know that None > > is a single object that can (and often *should*) be compared using > > `is`. However I spent some time reading through the language specs and > > didn't encounter anything about booleans returned from > > comparisons-operators, guaranteeing that they always return The One > > True and The One False. ... > > That said, though, a comparison isn't required to return a bool. If it > *does* return a bool, it has to be one of those exact two, but it > could return anything it chooses. But for built-in types and most > user-defined types, you will indeed get a bool. I'm not sure if this is relevant to the question but thought I'd mention concrete examples. A numpy array will return non-bool for both of the mentioned operators: In [2]: import numpy as np In [3]: a = np.array([2, 2, 2]) In [4]: a == a Out[4]: array([ True, True, True]) In [5]: a > 4 Out[5]: array([False, False, False]) With sympy expressions == will strictly always return a bool but inequality operators can return instances of Relational. When they can be evaluated those will give sympy's Booleans rather than bool. In [6]: import sympy as sym In [7]: x = sym.Symbol('x') In [8]: x > 0 Out[8]: x > 0 In [9]: type(_) Out[9]: sympy.core.relational.StrictGreaterThan In [10]: (x > 0).subs(x, 2) Out[10]: True In [11]: type(_) Out[11]: sympy.logic.boolalg.BooleanTrue -- Oscar From christian at python.org Wed Jul 22 09:00:11 2020 From: christian at python.org (Christian Heimes) Date: Wed, 22 Jul 2020 15:00:11 +0200 Subject: Spam, bacon, sausage and Spam (was: EuroPython 2020: Data Science Track) In-Reply-To: <9d6bdb49-c416-67ae-0110-fe1b77269f59@europython.eu> References: <9d6bdb49-c416-67ae-0110-fe1b77269f59@europython.eu> Message-ID: Hi MAL, would it be possible to reduce the amount of EuroPython spam on @python.org mailing lists to a sensible level? This mailing list is a general discussion list for the Python programming language. It's not a conference advertisement list. Something between 1 to 3 mails per conference and year (!) sounds sensible to me. You have posted 21 new threads about EP 2020 since January on this list, thereof 5 threads this month. In comparison I could only find two ads for other conferences in the last 12 month (FlaskCon, PyCon TZ). Christian From souvik.viksou at gmail.com Wed Jul 22 10:49:16 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Wed, 22 Jul 2020 20:19:16 +0530 Subject: Upgrade from Python 3.6 to 3.8 and cx-freeze is not available more In-Reply-To: <015401d65f53$adecf440$09c6dcc0$@kls-system.de> References: <000001d65d75$a8105dd0$f8311970$@kls-system.de> <015401d65f53$adecf440$09c6dcc0$@kls-system.de> Message-ID: Py2exe might help in making .exe files On Tue, Jul 21, 2020, 11:42 PM Christian SCHEIBER / KLS GmbH < cs at kls-system.de> wrote: > > > I?d like to do exe files, so the pythin interpreter has not tob e > installed. > > That?s why I use cx-freeze, but installing Python 3.8 after using Python > 3.6 > does not work. > > > > Can you tell me how I can make cx-freeze in Python 3.8 or how I can produce > exe files for Windows 7 32 / 64 Bit and Win10? > > Thanx in advance > > > > > > Mit freundlichen Gr??en > > > > Christian Scheiber > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From k.d.jantzen at mailbox.org Wed Jul 22 06:20:09 2020 From: k.d.jantzen at mailbox.org (Klaus Jantzen) Date: Wed, 22 Jul 2020 12:20:09 +0200 Subject: Installing Python 3.8.3 with tkinter Message-ID: Hi, Trying to install Python 3.8.3 with tkinter I run configure with the following options ./configure --enable-optimizations --with-ssl-default-suites=openssl --with-openssl=/usr/local --enable-loadable-sqlite-extensions --with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6' --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include' Running Python gives the following information Python 3.8.3 (default, Jul 22 2020, 11:52:15) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> import tkinter Traceback (most recent call last): ? File "", line 1, in ? File "/usr/local/lib/python3.8/tkinter/__init__.py", line 36, in ??? import _tkinter # If this fails your Python may not be configured for Tk ModuleNotFoundError: No module named '_tkinter' >>> Obviously there is something wrong with my configure options. How do that correctly? Thanks for any help. K.D.J. From efotinis at gmail.com Wed Jul 22 07:44:14 2020 From: efotinis at gmail.com (Elias Fotinis) Date: Wed, 22 Jul 2020 14:44:14 +0300 Subject: Python Program Help In-Reply-To: References: <1df3b7cf-de3b-4803-ac87-75d1621b9738o@googlegroups.com> <27d38725-a695-1012-eb39-31b6b08d798e@mrabarnett.plus.com> Message-ID: On 21/07/2020 22:25, Terry Reedy wrote: > The only way I discovered to get that error, on Windows, is to hit > control-D in response to the prompt. Slight correction: On Windows, EOF is signaled with Ctrl-Z. This is the same as hitting F6 in the legacy console (can't check with Win10 at the moment, but I believe it's the same there). Ctrl-D (the Unixy EOF) is returned simply as '\x04' on Windows. From python.list at tim.thechases.com Wed Jul 22 14:54:39 2020 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 22 Jul 2020 13:54:39 -0500 Subject: True is True / False is False? In-Reply-To: References: <20200721193827.6182114f@bigbox.attlocal.net> Message-ID: <20200722135439.4911e0d4@bigbox.attlocal.net> On 2020-07-22 11:54, Oscar Benjamin wrote: >> On Wed, Jul 22, 2020 at 11:04 AM Tim Chase wrote: >>> reading through the language specs and didn't encounter >>> anything about booleans returned from comparisons-operators, >>> guaranteeing that they always return The One True and The One >>> False. >> >> That said, though, a comparison isn't required to return a bool. >> If it *does* return a bool, it has to be one of those exact two, >> but it could return anything it chooses. But for built-in types >> and most user-defined types, you will indeed get a bool. > > I'm not sure if this is relevant to the question but thought I'd > mention concrete examples. A numpy array will return non-bool for > both of the mentioned operators that is indeed a helpful data-point. Do you know of any similar example in the standard library of things where comparison-operators return something other than True or False (or None)? Thanks, -tkc From rosuav at gmail.com Wed Jul 22 16:00:54 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jul 2020 06:00:54 +1000 Subject: True is True / False is False? In-Reply-To: <20200722135439.4911e0d4@bigbox.attlocal.net> References: <20200721193827.6182114f@bigbox.attlocal.net> <20200722135439.4911e0d4@bigbox.attlocal.net> Message-ID: On Thu, Jul 23, 2020 at 5:51 AM Tim Chase wrote: > > On 2020-07-22 11:54, Oscar Benjamin wrote: > >> On Wed, Jul 22, 2020 at 11:04 AM Tim Chase wrote: > >>> reading through the language specs and didn't encounter > >>> anything about booleans returned from comparisons-operators, > >>> guaranteeing that they always return The One True and The One > >>> False. > >> > >> That said, though, a comparison isn't required to return a bool. > >> If it *does* return a bool, it has to be one of those exact two, > >> but it could return anything it chooses. But for built-in types > >> and most user-defined types, you will indeed get a bool. > > > > I'm not sure if this is relevant to the question but thought I'd > > mention concrete examples. A numpy array will return non-bool for > > both of the mentioned operators > > that is indeed a helpful data-point. Do you know of any similar > example in the standard library of things where comparison-operators > return something other than True or False (or None)? > Can't think of any (although that doesn't disprove it). Also, nothing returns None from a comparison, to my knowledge. ChrisA From nad at python.org Wed Jul 22 17:05:53 2020 From: nad at python.org (Ned Deily) Date: Wed, 22 Jul 2020 17:05:53 -0400 Subject: Installing Python 3.8.3 with tkinter In-Reply-To: References: Message-ID: On 2020-07-22 06:20, Klaus Jantzen wrote: > Trying to install Python 3.8.3 with tkinter I run configure with the > following options > > ./configure --enable-optimizations --with-ssl-default-suites=openssl > --with-openssl=/usr/local --enable-loadable-sqlite-extensions > --with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6' > --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include' > > Running Python gives the following information [...] > How do that correctly? Try --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib -ltcl8.6 -ltk8.6' From jeff.linahan at gmail.com Wed Jul 22 17:57:28 2020 From: jeff.linahan at gmail.com (Jeff Linahan) Date: Wed, 22 Jul 2020 17:57:28 -0400 Subject: Fwd: [BUG] missing ')' causes syntax error on next line In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Jeff Linahan Date: Wed, Jul 22, 2020, 5:23 PM Subject: Fwd: [BUG] missing ')' causes syntax error on next line To: Subscribing to the mailing list as per the bot's request and resending. ---------- Forwarded message --------- From: Jeff Linahan Date: Wed, Jul 22, 2020, 5:20 PM Subject: [BUG] missing ')' causes syntax error on next line To: See attached image. Would be nice if it printed "SyntaxError: unbalanced parens" as it can difficult to see the problem if code like this is run in an environment that only prints the problematic line, which in this case the compiler is confused and one line off. From rosuav at gmail.com Wed Jul 22 18:33:12 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jul 2020 08:33:12 +1000 Subject: [BUG] missing ')' causes syntax error on next line In-Reply-To: References: Message-ID: On Thu, Jul 23, 2020 at 8:30 AM Jeff Linahan wrote: > > ---------- Forwarded message --------- > From: Jeff Linahan > Date: Wed, Jul 22, 2020, 5:23 PM > Subject: Fwd: [BUG] missing ')' causes syntax error on next line > To: > > > Subscribing to the mailing list as per the bot's request and resending. > > ---------- Forwarded message --------- > From: Jeff Linahan > Date: Wed, Jul 22, 2020, 5:20 PM > Subject: [BUG] missing ')' causes syntax error on next line > To: > > > See attached image. Would be nice if it printed "SyntaxError: unbalanced > parens" as it can difficult to see the problem if code like this is run in > an environment that only prints the problematic line, which in this case > the compiler is confused and one line off. The image doesn't get attached. Use text in future. Thing is, the syntax error isn't the unbalanced parenthesis, because you can quite happily span multiple lines: x = func( a, b, c, ) But if you have a keyword inside there, it won't work: x = func( a, b, def foo(): pass The parser can't figure out which one is wrong, so it simply reports the error at the point where it finds it. As a general rule, if you're pointed to a line that looks fine, try looking above it. (And that's not just for Python - many many programming languages exhibit this same behaviour, for the same reason.) ChrisA From ethan at stoneleaf.us Wed Jul 22 18:46:15 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 22 Jul 2020 15:46:15 -0700 Subject: Fwd: [BUG] missing ')' causes syntax error on next line In-Reply-To: References: Message-ID: <71aad8e9-b157-4ebf-f7bc-77fc33d67d8a@stoneleaf.us> On 7/22/20 2:57 PM, Jeff Linahan wrote: > Subscribing to the mailing list as per the bot's request and resending. *beep* *whirrrrr* WE ARE NOT *click* *whirrrr* A BOT. *bzzzt* WE ARE *bzzzt* *click* ADVANCED LIFE *whirrrr* FORMS *click* *beep* . -- ~eTHAN~ pYTHON lIST mODERATOR NoT a BoT (i ThInK...) From pfeiffer at cs.nmsu.edu Wed Jul 22 18:48:21 2020 From: pfeiffer at cs.nmsu.edu (Joe Pfeiffer) Date: Wed, 22 Jul 2020 16:48:21 -0600 Subject: Fwd: [BUG] missing ')' causes syntax error on next line References: Message-ID: <1by2nbtbd6.fsf@pfeifferfamily.net> Jeff Linahan writes: > > See attached image. Would be nice if it printed "SyntaxError: unbalanced > parens" as it can difficult to see the problem if code like this is run in > an environment that only prints the problematic line, which in this case > the compiler is confused and one line off. It would be indeed be nice, but it's reporting the error when it finds it. Suppose you were typing the program in at the console -- how could it possibly go back and report the error on the previous line? Given python's syntax, does the error even really exist yet on that previous line? From aeros167 at gmail.com Wed Jul 22 18:50:57 2020 From: aeros167 at gmail.com (Kyle Stanley) Date: Wed, 22 Jul 2020 18:50:57 -0400 Subject: Fwd: [BUG] missing ')' causes syntax error on next line In-Reply-To: <71aad8e9-b157-4ebf-f7bc-77fc33d67d8a@stoneleaf.us> References: <71aad8e9-b157-4ebf-f7bc-77fc33d67d8a@stoneleaf.us> Message-ID: > > *beep* *whirrrrr* > > WE ARE NOT > > *click* *whirrrr* > > A BOT. *dial up noises* SPEAK FOR YOURSELF On Wed, Jul 22, 2020 at 6:46 PM Ethan Furman wrote: > On 7/22/20 2:57 PM, Jeff Linahan wrote: > > > Subscribing to the mailing list as per the bot's request and resending. > > *beep* *whirrrrr* > > WE ARE NOT > > *click* *whirrrr* > > A BOT. > > *bzzzt* > > WE ARE > > *bzzzt* *click* > > ADVANCED LIFE > > *whirrrr* > > FORMS > > *click* > > *beep* > > . > > -- > ~eTHAN~ > pYTHON lIST mODERATOR > NoT a BoT (i ThInK...) > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Wed Jul 22 19:10:33 2020 From: PythonList at DancesWithMice.info (dn) Date: Thu, 23 Jul 2020 11:10:33 +1200 Subject: [BUG] missing ')' causes syntax error on next line In-Reply-To: References: Message-ID: On 23/07/2020 10:33, Chris Angelico wrote: >> ---------- Forwarded message --------- >> From: Jeff Linahan >> See attached image. Would be nice if it printed "SyntaxError: unbalanced >> parens" as it can difficult to see the problem if code like this is run in >> an environment that only prints the problematic line, which in this case >> the compiler is confused and one line off. > > Thing is, the syntax error isn't the unbalanced parenthesis, because > you can quite happily span multiple lines: > But if you have a keyword inside there, it won't work: > The parser can't figure out which one is wrong, so it simply reports > the error at the point where it finds it. As a general rule, if you're > pointed to a line that looks fine, try looking above it. (And that's > not just for Python - many many programming languages exhibit this > same behaviour, for the same reason.) This may change when the new PEG-parser brings us Python 3.9 (https://www.python.org/dev/peps/pep-0617/) I'm looking forward to seeing how this change will impact/improve the quality of feedback/traces/err.msgs... OP: you may be interested in SuperHELP - Help for Humans! https://github.com/grantps/superhelp -- Regards =dn From PythonList at DancesWithMice.info Wed Jul 22 19:15:22 2020 From: PythonList at DancesWithMice.info (dn) Date: Thu, 23 Jul 2020 11:15:22 +1200 Subject: Fwd: [BUG] missing ')' causes syntax error on next line In-Reply-To: <71aad8e9-b157-4ebf-f7bc-77fc33d67d8a@stoneleaf.us> References: <71aad8e9-b157-4ebf-f7bc-77fc33d67d8a@stoneleaf.us> Message-ID: On 23/07/2020 10:46, Ethan Furman wrote: > On 7/22/20 2:57 PM, Jeff Linahan wrote: > >> Subscribing to the mailing list as per the bot's request and resending. > > *beep* *whirrrrr* > > WE ARE NOT > > *click* *whirrrr* > > A BOT. > > *bzzzt* > > WE ARE > > *bzzzt* *click* > > ADVANCED LIFE > > *whirrrr* > > FORMS > > *click* > > *beep* > > . > > -- > ~eTHAN~ > pYTHON lIST mODERATOR > NoT a BoT? (i ThInK...) Enjoyed the joke! (and thanks for all the efforts you exert on our behalf) However, questions remain:- Robot: any machine or mechanical device that operates automatically with humanlike skill See also, Turing Machine (https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/turing-machine/one.html) -- Regards =dn From rosuav at gmail.com Wed Jul 22 19:51:42 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jul 2020 09:51:42 +1000 Subject: Fwd: [BUG] missing ')' causes syntax error on next line In-Reply-To: References: <71aad8e9-b157-4ebf-f7bc-77fc33d67d8a@stoneleaf.us> Message-ID: On Thu, Jul 23, 2020 at 9:17 AM dn via Python-list wrote: > However, questions remain:- > > Robot: any machine or mechanical device that operates automatically with > humanlike skill > What about a human that operates mechanically with merely robot-like skill? I'm pretty sure I've spoken to them on the phone many times. ChrisA From cs at cskk.id.au Wed Jul 22 20:12:14 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 23 Jul 2020 10:12:14 +1000 Subject: Spam, bacon, sausage and Spam (was: EuroPython 2020: Data Science Track) In-Reply-To: References: Message-ID: <20200723001214.GA38672@cskk.homeip.net> On 22Jul2020 15:00, Christian Heimes wrote: >Hi MAL, > >would it be possible to reduce the amount of EuroPython spam on >@python.org mailing lists to a sensible level? This mailing list is a >general discussion list for the Python programming language. It's not a >conference advertisement list. > >Something between 1 to 3 mails per conference and year (!) sounds >sensible to me. [...] I, OTOH, am unperturbed. Things have been much in flux this year, and a last minute short notice thing like this post needs wide dissemination. Normally a conference needs few posts, but this year everything is different and plans have changed a lot, on the fly. I have never attended EuroPython and probably never will (I'm on the other side of the planet) but I'm still interested. Rather than subscribe to every conference thing, getting them here is very convenient. As with all posters and topics, a truly annoying one can always be blocked at your personal discretion with a filter rule, eg to discard "europython". I know that advice verges on the spammers' claim that "you can always opt out" but for me this stuff isn't spam. Cheers, Cameron Simpson (formerly cs at zip.com.au) From PythonList at DancesWithMice.info Wed Jul 22 20:23:08 2020 From: PythonList at DancesWithMice.info (dn) Date: Thu, 23 Jul 2020 12:23:08 +1200 Subject: Fwd: [BUG] missing ')' causes syntax error on next line In-Reply-To: References: <71aad8e9-b157-4ebf-f7bc-77fc33d67d8a@stoneleaf.us> Message-ID: On 23/07/2020 11:51, Chris Angelico wrote: > On Thu, Jul 23, 2020 at 9:17 AM dn via Python-list > wrote: >> However, questions remain:- >> >> Robot: any machine or mechanical device that operates automatically with >> humanlike skill >> > > What about a human that operates mechanically with merely robot-like > skill? I'm pretty sure I've spoken to them on the phone many times. Can't say - I've never tried to speak with @Ethan over the phone. ...and what do you call the robot which can't/won't operate by phone, and takes a week to respond to your email - and then often by asking for information previously provided, eg a certain book-seller's "Mr Neil would you please confirm that your voucher number is 12345?" However, on the Turing machine side, I recall creating an abbreviated version for a University Open Day - way back in the seventies and when VDU-terminals were a novelty and thus curiosities. The program worked in similar manner to the famous "Eliza" (https://en.wikipedia.org/wiki/ELIZA) - attempting to give an illusion of understanding and conversation. It stored a mere top-twenty phrases. When the user entered some text, it would randomly select one of these and 'reply'. The user was invited to give feedback, ie whether it was a good reply or not. These were used to score/grade the phrases. Then the user's data-entry was added to the 'database of phrases' in place of the existing phrase with the lowest score. Thus the conversation continued. 'On the day', many of our visitors were convinced that either the computer was capable of holding a conversation (? la Turing), or that there was a person hidden-away somewhere, providing the 'answers'. Most telling, reviewing the 'database' at the end, showed twenty of the most innocuous phrases in English conversation - those which were so multi-purpose that they could be used in almost any situation (phatic phrases: https://en.wikipedia.org/wiki/Phatic_expression). You be sure to have a nice day, now! -- Regards =dn From gheskett at shentel.net Wed Jul 22 20:12:04 2020 From: gheskett at shentel.net (Gene Heskett) Date: Wed, 22 Jul 2020 20:12:04 -0400 Subject: Fwd: [BUG] missing ')' causes syntax error on next line In-Reply-To: References: Message-ID: <202007222012.04909.gheskett@shentel.net> On Wednesday 22 July 2020 19:51:42 Chris Angelico wrote: > On Thu, Jul 23, 2020 at 9:17 AM dn via Python-list > > wrote: > > However, questions remain:- > > > > Robot: any machine or mechanical device that operates automatically > > with humanlike skill > > What about a human that operates mechanically with merely robot-like > skill? I'm pretty sure I've spoken to them on the phone many times. > > ChrisA Thats more common than you might think Chris. Whats nice is that you can often take over that robot and use his or her hands to troubleshoot an off the air tv transmitter from a thousand miles away. That was my field of expertise for 60 years. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From rosuav at gmail.com Wed Jul 22 20:45:50 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jul 2020 10:45:50 +1000 Subject: Fwd: [BUG] missing ')' causes syntax error on next line In-Reply-To: <202007222012.04909.gheskett@shentel.net> References: <202007222012.04909.gheskett@shentel.net> Message-ID: On Thu, Jul 23, 2020 at 10:30 AM Gene Heskett wrote: > > On Wednesday 22 July 2020 19:51:42 Chris Angelico wrote: > > > On Thu, Jul 23, 2020 at 9:17 AM dn via Python-list > > > > wrote: > > > However, questions remain:- > > > > > > Robot: any machine or mechanical device that operates automatically > > > with humanlike skill > > > > What about a human that operates mechanically with merely robot-like > > skill? I'm pretty sure I've spoken to them on the phone many times. > > > > ChrisA > > Thats more common than you might think Chris. Whats nice is that you can > often take over that robot and use his or her hands to troubleshoot an > off the air tv transmitter from a thousand miles away. That was my > field of expertise for 60 years. > Ah yes. I was more thinking of the ones you get when you call for support. "Have you rebooted your computer and router?" "THERE IS NO ADSL SYNC. Rebooting my computer is not going to change that." ChrisA From k.d.jantzen at mailbox.org Thu Jul 23 00:30:24 2020 From: k.d.jantzen at mailbox.org (Klaus Jantzen) Date: Thu, 23 Jul 2020 06:30:24 +0200 Subject: Installing Python 3.8.3 with tkinter In-Reply-To: References: Message-ID: On 7/22/20 11:05 PM, Ned Deily wrote: > On 2020-07-22 06:20, Klaus Jantzen wrote: >> Trying to install Python 3.8.3 with tkinter I run configure with the >> following options >> >> ./configure --enable-optimizations --with-ssl-default-suites=openssl >> --with-openssl=/usr/local --enable-loadable-sqlite-extensions >> --with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6' >> --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include' >> >> Running Python gives the following information > [...] >> How do that correctly? > Try --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib -ltcl8.6 -ltk8.6' > > Thank you for your suggestion; unfortunately it did not help. From PythonList at DancesWithMice.info Thu Jul 23 01:20:48 2020 From: PythonList at DancesWithMice.info (dn) Date: Thu, 23 Jul 2020 17:20:48 +1200 Subject: Friday Finking: Limiting parameters In-Reply-To: <20200721173726.GB13397@hjp.at> References: <617af290-3ffd-4cad-a992-49a70ecfc9e6@DancesWithMice.info> <65D21327-CAAC-4D3A-B5E2-859D170FB8EC@barrys-emacs.org> <3b0af018-73f3-df41-9042-687eed5a4a63@DancesWithMice.info> <20200721173726.GB13397@hjp.at> Message-ID: <8b473958-9bf1-25f4-5cdc-827e97ef9237@DancesWithMice.info> On 22/07/2020 05:37, Peter J. Holzer wrote: > On 2020-07-13 17:21:40 +1200, dn via Python-list wrote: >> On 12/07/20 10:10 PM, Barry Scott wrote: >>> I'd expect to see something like this: >>> >>> def mail_label( person, address ): >>> first_name = person.first_name >>> # or if you want a function interface >>> first_line_of_address = address.get_first_line() >> >> Does this idea move whole objects across the interface? (see earlier in the >> thread) > > Assigning an object in Python only copies a pointer (and may adjust some > house-keeping info, like a reference count). So it doesn't matter > whether the object has 5 fields or 50. The function will only access > those it knows about and ignore the rest. Yes, poor choice of words in "move". Perhaps (he says rather weakly), think in terms of move-ing control - from the object to the function. Is this the best idea? The point being that the function needs to 'know things' about the object, ie 'I want to make the identification line of the address so I must retrieve title, first-initial, family-name, ... all names which exist inside the object. In our example, the example-object has been person, so it's not big deal. What happens if in-future we develop a mailing-list for companies? The mail-label function now appears to be requiring that the company object use exactly the same attribute-names as person! The obvious alternative might be to pass all three data-values (in the example). Now the function only needs to know what it intends to call the three parameters - nothing more. However, our argument-count increases again... Another alternative would be to pass a method which will retrieve those fields from the object, delivering them in the form[at] expected by the function. In this case, the object provides the interface and the mail-label routine can get-on with what it knows best, without needing to know the who/what/where/how of data held by 'whatever is out-there'. (also, counts as only one argument!) > One might argue that mail_label should be a method of the person object > because it depends on the person (e.g., depending on the ethnicity of > the person the name might be written "first_name last_name" or > "last_name firstname"). OTOH a person may have many addresses (and an > address shared by many people), so a function which combines a person > and address (which therefore can't be a method of either person or > address) may be better. > > Maybe that should be treated as a model-view relationship: You have two > models (person and address) and a view (which combines some aspects of > both while ignoring others). So, would this be merely "has-a" composition, or is it where other languages would use "interfaces"? (and if-so, what is the pythonic solution?) -- Regards =dn From peter.slizik at gmail.com Thu Jul 23 03:54:12 2020 From: peter.slizik at gmail.com (=?UTF-8?B?UGV0ZXIgU2zDrcW+aWs=?=) Date: Thu, 23 Jul 2020 09:54:12 +0200 Subject: Iterators, iterables and special objects In-Reply-To: References: Message-ID: > The view are iterables. They can be iterated more than once and used in > other operations. > > The transformers should be once-through iterators because they can be > passed once-through interators. This is important, thank you for pointing it out. > Python's design that iter(iterator) is iterator is extremely handy. > Yes, but it has the unfortunate consequence that an iterator is expected to define def __iter__(self): return self which I saw people *not* doing, supposedly because the official documentation says that it needs to be done, but does not explain why (and the interpreter does not enforce it, and the code works anyway). Moreover, some tutorial authors make it even more difficult with using the terms iterator and iterable interchangeably. A notorious example is this wiki: https://wiki.python.org/moin/Iterator It says: *Here is an *iterator* that returns a random number of 1's: * class RandomIterable: def __iter__(self): return self I remember the time when I started to look into iterators, and frankly, with this wiki article, it took me ages to understand,why do iterables return self in their *__iter__* method. But I think I'm getting off-topic... Again, thanks guys, @Terry and @dn for your explanations, you've made the situation clear. Peter From peter.slizik at gmail.com Thu Jul 23 04:03:27 2020 From: peter.slizik at gmail.com (=?UTF-8?B?UGV0ZXIgU2zDrcW+aWs=?=) Date: Thu, 23 Jul 2020 10:03:27 +0200 Subject: True is True / False is False? In-Reply-To: <20200721193827.6182114f@bigbox.attlocal.net> References: <20200721193827.6182114f@bigbox.attlocal.net> Message-ID: Dear Tim, in Python 2, None is a keyword and True and False are just identifiers. In Python 3, all of them are keywords. There is an interesting article by Guido explaining the reason for their different implementations. http://python-history.blogspot.com/2013/11/story-of-none-true-false.html Just ignore the first few introductory paragraphs... probably jump to the article starting with *"So, after this long detour about built-ins vs. keywords, back to None."* Hope this helps, Peter On Wed, Jul 22, 2020 at 3:06 AM Tim Chase wrote: > I know for ints, cpython caches something like -127 to 255 where `is` > works by happenstance based on the implementation but not the spec > (so I don't use `is` for comparison there because it's not > guaranteed by the language spec). On the other hand, I know that None > is a single object that can (and often *should*) be compared using > `is`. However I spent some time reading through the language specs and > didn't encounter anything about booleans returned from > comparisons-operators, guaranteeing that they always return The One > True and The One False. > > x = 3 == 3 # some boolean expression evaluating to True/False > y = 4 > 0 # another boolean expression > if x is y: > print("cool, same as always") > else: > print("is this ever possible?") > > Is there some theoretical world in which that `else` branch could ever > be hit because the True referenced by x is not the same True > referenced by y? (assuming non-pathological overriding of dunder > methods to return true-ish or false-ish values; or at least assuming > any dunder-overriding is pure standard-library) > > In the big picture, this is likely irrelevant and I should just use > "==" instead, but I got the question stuck in my head and ended up > bothered that I couldn't disinter an answer from docs. > > Thanks, > > -tkc > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Thu Jul 23 04:37:32 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jul 2020 18:37:32 +1000 Subject: Iterators, iterables and special objects In-Reply-To: References: Message-ID: On Thu, Jul 23, 2020 at 5:55 PM Peter Sl??ik wrote: > > Python's design that iter(iterator) is iterator is extremely handy. > > > > Yes, but it has the unfortunate consequence that an iterator is expected > to define > > def __iter__(self): return self > > which I saw people *not* doing, supposedly because the official > documentation says that it needs to be done, but does not explain why (and > the interpreter does not enforce it, and the code works anyway). Works in what way? You can't use it in a 'for' loop if it doesn't define __iter__. > Moreover, some tutorial authors make it even more difficult with using the > terms iterator and iterable interchangeably. A notorious example is this > wiki: > https://wiki.python.org/moin/Iterator > > It says: > > *Here is an *iterator* that returns a random number of 1's: * > > class RandomIterable: def __iter__(self): return self Yes? It is indeed an iterator, since its iter method returns itself. It is also iterable, since it has an iter method. The article goes on to explain this. I don't think they're being used interchangeably here. > I remember the time when I started to look into iterators, and frankly, > with this wiki article, it took me ages to understand,why do iterables > return self in their *__iter__* method. It's so you can do things like this: def show_with_header(stuff): stuff = iter(stuff) hdr = next(stuff) print(hdr) for line in stuff: print(line) if new_page(): print(hdr) You can pass this any (non-empty) iterable and it'll work. If __iter__ didn't return self, both this function and the for loop inside it would need to check for an iterator and an iterable, and there'd be the possibility of a conflict. Having __iter__ return self is a pretty elegant way to handle it. I suppose the same thing could be signalled some other way (having it return None, for instance), but it wouldn't gain you anything. ChrisA From christian at python.org Thu Jul 23 04:39:13 2020 From: christian at python.org (Christian Heimes) Date: Thu, 23 Jul 2020 10:39:13 +0200 Subject: Spam, bacon, sausage and Spam (was: EuroPython 2020: Data Science Track) In-Reply-To: <20200723001214.GA38672@cskk.homeip.net> References: <20200723001214.GA38672@cskk.homeip.net> Message-ID: <93a3ebc3-42cb-3152-1b21-7b988cf4cce8@python.org> On 23/07/2020 02.12, Cameron Simpson wrote: > On 22Jul2020 15:00, Christian Heimes wrote: >> Hi MAL, >> >> would it be possible to reduce the amount of EuroPython spam on >> @python.org mailing lists to a sensible level? This mailing list is a >> general discussion list for the Python programming language. It's not a >> conference advertisement list. >> >> Something between 1 to 3 mails per conference and year (!) sounds >> sensible to me. [...] > > I, OTOH, am unperturbed. > > Things have been much in flux this year, and a last minute short notice > thing like this post needs wide dissemination. Normally a conference > needs few posts, but this year everything is different and plans have > changed a lot, on the fly. > > I have never attended EuroPython and probably never will (I'm on the > other side of the planet) but I'm still interested. Rather than > subscribe to every conference thing, getting them here is very > convenient. I have been to a lot of EuroPython conferences. EP 2003 in Charleroi/Belgium was my first Python conference. I have given several talks at EP in recent years and have participated in one panel discussion / AMA about Python core development. I'm not disputing the fact that a conference can use the generic Python users list for announcements. It's the fact that EP is literally spamming the list with threads like "Opening our merchandise shop", "Find a new job", "Introducing our diamond sponsor", and "Presenting our conference booklet". That's just spam to advertise for the conference or a company. Some EP announcements were cross-posted to multiple mailing lists like psf-community at python.org, too. python.org has a dedicated conference mailing list for conference related announcements. Additional to general conferences at python.org EuroPython has 2 (in words *TWO*) additional mailing lists for announcements and discussions (europython at python.org, europython-announce at python.org). > As with all posters and topics, a truly annoying one can always be > blocked at your personal discretion with a filter rule, eg to discard > "europython". I know that advice verges on the spammers' claim that "you > can always opt out" but for me this stuff isn't spam. See https://geekfeminism.wikia.org/wiki/Missing_stair Some people have replied to me in private because they did not dare to speak out against a prominent member of the Python community in public. At least one person has followed up with Code Of Conduct working group because they are annoyed by the spam. Christian From rosuav at gmail.com Thu Jul 23 04:41:16 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jul 2020 18:41:16 +1000 Subject: Iterators, iterables and special objects In-Reply-To: References: Message-ID: On Thu, Jul 23, 2020 at 5:55 PM Peter Sl??ik wrote: > Moreover, some tutorial authors make it even more difficult with using the > terms iterator and iterable interchangeably. A notorious example is this > wiki: > https://wiki.python.org/moin/Iterator > > It says: > > *Here is an *iterator* that returns a random number of 1's: * > > class RandomIterable: def __iter__(self): return self > BTW, that article had been written using the Python 2 syntax, with a "next" function rather than "__next__". I've now updated it, so the examples should work if copied and pasted into a current Python interpreter. ChrisA From rosuav at gmail.com Thu Jul 23 04:50:03 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jul 2020 18:50:03 +1000 Subject: Spam, bacon, sausage and Spam (was: EuroPython 2020: Data Science Track) In-Reply-To: <93a3ebc3-42cb-3152-1b21-7b988cf4cce8@python.org> References: <20200723001214.GA38672@cskk.homeip.net> <93a3ebc3-42cb-3152-1b21-7b988cf4cce8@python.org> Message-ID: On Thu, Jul 23, 2020 at 6:40 PM Christian Heimes wrote: > I'm not disputing the fact that a conference can use the generic Python > users list for announcements. It's the fact that EP is literally > spamming the list with threads like "Opening our merchandise shop", > "Find a new job", "Introducing our diamond sponsor", and "Presenting our > conference booklet". That's just spam to advertise for the conference or > a company. Some EP announcements were cross-posted to multiple mailing > lists like psf-community at python.org, too. Five threads in a month isn't THAT much spam. Yes, four of them arrived close together, but that's what happens when something is temporal in nature. We've had roughly the same number of threads saying "Python v3.x.y has been released" referencing small revisions to stable releases of Python, and those are equally irrelevant to people who don't need to update (for instance, 3.9.0b5 is irrelevant unless you're tracking the betas, and 3.7.8 doesn't make a lot of difference unless you need the very latest 3.7 and don't get it from a package manager). Is that a problem? I don't think so. These lists get a lot of traffic and the normal way to distinguish them is by their subject lines, and every one of these EuroPython threads has had that word in the subject. ChrisA From peter.slizik at gmail.com Thu Jul 23 05:14:35 2020 From: peter.slizik at gmail.com (=?UTF-8?B?UGV0ZXIgU2zDrcW+aWs=?=) Date: Thu, 23 Jul 2020 11:14:35 +0200 Subject: Iterators, iterables and special objects In-Reply-To: References: Message-ID: > Works in what way? You can't use it in a 'for' loop if it doesn't > define __iter__. > class Iterable: def __iter__(self): return Iterator(...) class Iterator: def __next__(self): return # No __iter__ here. # I've just forgotten to def it. With this setup, using for to iterate over Iterable *will* still work, though you cannot use the trick described below. > Yes? It is indeed an iterator, since its iter method returns itself. It is also iterable, since it has an iter method. Of course, you're right. But you're reading the article through the eyes of an experienced developer. > It's so you can do things like this: > > def show_with_header(stuff): > stuff = iter(stuff) > hdr = next(stuff) > print(hdr) > for line in stuff: > print(line) > if new_page(): print(hdr) > Yes, @Terry had given the same example. Frankly, I didn't know about it before, I somehow had the misconception that for always got a 'fresh' iterator... Peter From auriocus at gmx.de Thu Jul 23 13:36:46 2020 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 23 Jul 2020 19:36:46 +0200 Subject: Installing Python 3.8.3 with tkinter In-Reply-To: References: Message-ID: Am 23.07.20 um 06:30 schrieb Klaus Jantzen: > On 7/22/20 11:05 PM, Ned Deily wrote: >> On 2020-07-22 06:20, Klaus Jantzen wrote: >>> Trying to install Python 3.8.3 with tkinter I run configure with the >>> following options >>> >>> ./configure --enable-optimizations --with-ssl-default-suites=openssl >>> --with-openssl=/usr/local --enable-loadable-sqlite-extensions >>> --with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6' >>> --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include' >>> >>> Running Python gives the following information >> [...] >>> How do that correctly? >> Try --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib -ltcl8.6 -ltk8.6' >> >> > Thank you for your suggestion; unfortunately it did not help. > Does the configure process output something when checking for Tcl/Tk? Does it say "no"? THen you can analyse the config.log file what happened. In order to compile Tk extensions, you need X11 development headers. Maybe that is one problem. Christian From as at sci.fi Thu Jul 23 02:50:09 2020 From: as at sci.fi (Anssi Saari) Date: Thu, 23 Jul 2020 09:50:09 +0300 Subject: Installing Python 3.8.3 with tkinter References: Message-ID: Klaus Jantzen writes: > On 7/22/20 11:05 PM, Ned Deily wrote: >> On 2020-07-22 06:20, Klaus Jantzen wrote: >>> Trying to install Python 3.8.3 with tkinter I run configure with the >>> following options >>> >>> ./configure --enable-optimizations --with-ssl-default-suites=openssl >>> --with-openssl=/usr/local --enable-loadable-sqlite-extensions >>> --with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6' >>> --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include' >>> >>> Running Python gives the following information >> [...] >>> How do that correctly? >> Try --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib -ltcl8.6 -ltk8.6' >> >> > Thank you for your suggestion; unfortunately it did not help. Are you sure the libs you need (presumably libtcl8.6.so and libtk8.6.so) are both in /opt/ActiveTcl-8.6/lib/tcl8.6? Or where are they actually? Presumably not in /opt/ActiveTcl-8.6/lib since that didn't work. Could be something else too. You may need to dig into setup.py and the configure script. From nad at python.org Thu Jul 23 05:42:50 2020 From: nad at python.org (Ned Deily) Date: Thu, 23 Jul 2020 05:42:50 -0400 Subject: Installing Python 3.8.3 with tkinter In-Reply-To: References: Message-ID: On 2020-07-23 00:30, Klaus Jantzen wrote: > On 7/22/20 11:05 PM, Ned Deily wrote: >> On 2020-07-22 06:20, Klaus Jantzen wrote: >>> Trying to install Python 3.8.3 with tkinter I run configure with the >>> following options >>> >>> ./configure --enable-optimizations --with-ssl-default-suites=openssl >>> --with-openssl=/usr/local --enable-loadable-sqlite-extensions >>> --with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6' >>> --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include' >>> >>> Running Python gives the following information >> [...] >>> How do that correctly? >> Try --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib -ltcl8.6 -ltk8.6' >> >> > Thank you for your suggestion; unfortunately it did not help. Without knowing exactly how the /opt/ActiveTcl-8.6 directory is laid out, we can only guess at what the right options should be. The basic idea is that there needs to be one or more -I entries that covers the top-level directory(ies) with Tcl and Tk include files and for the libraries there needs to be a -L entry for the directory and a -l entry for the name of the shared library (minus the "lib" prefix), assuming Tcl and Tk were built with --enable-shared. Usually both libraries are installed into the same directory, in which case you only need one -L as above. If they do not have a common parent, you would need to specify each separately, like -L/libtclparent -l tcl8.6 -L/libtkparent -ltk8.6. If that doesn't help, you could display the show the contents of the include and directories here: ls -l /opt/ActiveTcl-8.6/include /opt/ActiveTcl-8.6/lib Also exactly what platform are you building on? And, btw, Python 3.8.5 is now current. From rosuav at gmail.com Thu Jul 23 14:07:24 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Jul 2020 04:07:24 +1000 Subject: Fwd: [BUG] missing ')' causes syntax error on next line In-Reply-To: <53jjhfpm7dn0ev7plbontqmogfs25m6ep4@4ax.com> References: <71aad8e9-b157-4ebf-f7bc-77fc33d67d8a@stoneleaf.us> <53jjhfpm7dn0ev7plbontqmogfs25m6ep4@4ax.com> Message-ID: On Fri, Jul 24, 2020 at 4:00 AM Dennis Lee Bieber wrote: > > On Thu, 23 Jul 2020 09:51:42 +1000, Chris Angelico > declaimed the following: > > >On Thu, Jul 23, 2020 at 9:17 AM dn via Python-list > > wrote: > >> However, questions remain:- > >> > >> Robot: any machine or mechanical device that operates automatically with > >> humanlike skill > >> > > > >What about a human that operates mechanically with merely robot-like > >skill? I'm pretty sure I've spoken to them on the phone many times. > > Would that be... a computer? > > > > Using the original meaning of "one who computes" > I suspect that even that is too generous for some of them. They merely follow instructions like good little automatons, until the caller gives up... ChrisA From PythonList at DancesWithMice.info Thu Jul 23 16:25:06 2020 From: PythonList at DancesWithMice.info (dn) Date: Fri, 24 Jul 2020 08:25:06 +1200 Subject: Spam, bacon, sausage and Spam In-Reply-To: <93a3ebc3-42cb-3152-1b21-7b988cf4cce8@python.org> References: <20200723001214.GA38672@cskk.homeip.net> <93a3ebc3-42cb-3152-1b21-7b988cf4cce8@python.org> Message-ID: <523b184b-7f9c-c5f4-45e1-133a41d583e4@DancesWithMice.info> On 23/07/2020 20:39, Christian Heimes wrote: > On 23/07/2020 02.12, Cameron Simpson wrote: >> On 22Jul2020 15:00, Christian Heimes wrote: ... >>> would it be possible to reduce the amount of EuroPython spam on >>> @python.org mailing lists to a sensible level? This mailing list is a >>> general discussion list for the Python programming language. It's not a >>> conference advertisement list. +1 (see later) >> I, OTOH, am unperturbed. +1 ... >> I have never attended EuroPython and probably never will (I'm on the >> other side of the planet) but I'm still interested. Rather than >> subscribe to every conference thing, getting them here is very >> convenient. +1 (and make a note to follow-up afterwards, because many PyCons post videos of the presentations - not as good as being-there, but less expensive than an RtW air-ticket!) ... > I'm not disputing the fact that a conference can use the generic Python > users list for announcements. It's the fact that EP is literally > spamming the list with threads like "Opening our merchandise shop", > "Find a new job", "Introducing our diamond sponsor", and "Presenting our > conference booklet". That's just spam to advertise for the conference or > a company. Some EP announcements were cross-posted to multiple mailing > lists like psf-community at python.org, too. Agreed: There is a difference between announcing conference details, and selling 'stuff' to attendees. (I don't know: but would a non-attendee buy the t-shirt?) > python.org has a dedicated conference mailing list for conference > related announcements. Additional to general conferences at python.org > EuroPython has 2 (in words *TWO*) additional mailing lists for > announcements and discussions (europython at python.org, > europython-announce at python.org). ... Agreed However, "This mailing list is a general discussion list for the Python programming language" and per earlier reply, advice of a conference holds general interest (as well) - and is an encouragement to other PyCons (organisers) around the world. Were we to ban EuroPython, would we also have to take a stand against beginners posting basic questions (given that there is a specific Tutor list)? "General" means nothing-specific (as anyone in the military can tell you)! In truth, I did delete many of these msgs after a cursory scan of their content (cf reading). > Some people have replied to me in private because they did not dare to > speak out against a prominent member of the Python community in public. > At least one person has followed up with Code Of Conduct working group > because they are annoyed by the spam. Like the decision to use vim or emacs, this topic can generate a lot of heat and emotion. Is there room for both? (and for 'modern IDEs') The "dare not speak out" is sad - both for the individuals and/or the organisation. Wither "inclusion" and "tolerance"? -- Regards =dn From cl at isbd.net Thu Jul 23 16:41:32 2020 From: cl at isbd.net (Chris Green) Date: Thu, 23 Jul 2020 21:41:32 +0100 Subject: Need to 'import gtk' on Ubuntu 20.04, what do I need? Message-ID: I have recently upgraded my desktop system from ubuntu 19.10 to ubuntu 20.04. I have some Oki printer/scanner driver software that is written in Python 2 and, although python 2 is still installed on my system it's no longer the default python and the Oki software no longer runs. The error I am getting is:- chris at esprimo$ ./scantool.py Traceback (most recent call last): File "./scantool.py", line 52, in import gtk ImportError: No module named gtk So what do I need to install on my Ubuntu 20.04 system to provide the gtk module? Alternatively (but much harder work) what is the Python 3 equivalent of the the Python 2 pygtk and gtk modules. -- Chris Green ? From PythonList at DancesWithMice.info Thu Jul 23 17:10:34 2020 From: PythonList at DancesWithMice.info (dn) Date: Fri, 24 Jul 2020 09:10:34 +1200 Subject: How to limit *length* of PrettyPrinter In-Reply-To: References: Message-ID: Redirected from Digest (see below) On 23/07/2020 11:59, Stavros Macrakis wrote: > Mousedancer, thanks! Yes, I even look like a (younger) Kevin Costner! (you believe me - right!?) > As a finger exercise, I thought I'd try implementing print-level and print-length as an object-to-object transformer (rather than a pretty printer). I know that has a bunch of limitations, but I thought I might learn something by trying. > > Here's a simple function that will copy nested lists while limiting their depth and length. When it encounters a non-iterable object, it treats it as atomic: > > scalartypes = list(map(type,(1,1.0,1j,True,'x',b'x',None))) > > def limit(obj,length=-2,depth=-2): > if type(obj) in scalartypes: > return obj > if depth==0: > return 'XXX' > lencnt = length > try: > new = type(obj).__new__(type(obj)) # empty object of same type > for i in obj: > lencnt = lencnt - 1 > if lencnt == -1: > new.append('...') # too long > break > else: > new.append(limit(i,length,depth-1)) > return new > except: # which exceptions? > return obj # not iterable/appendable > > limit( [1,2,[31,[321,[3221, 3222],323,324],33],4,5,6], 3,3) > > => [1, 2, [31, [321, 'XXX', 323, '...'], 33], '...'] > > > > This works fine for lists, but not for tuples (because they're immutable, so no *append*) or dictionaries (must use *for/in* *obj.items*, and there's no *append*). There must be some way to handle this generically so I don't have to special-case tuples (which are immutable, so don't have *append*) and dictionaries (where you have to iterate over *obj.items()*... and there's no *append*), but I'm stuck. Should I accumulate results in a list and then make the list into a tuple or dictionary or whatever at the end? But how do I do that? > > It's not clear how I could handle /arbitrary/ objects... but let's start with the standard ones. This looks like fun! BTW why are we doing it: is it some sort of 'homework assignment' or are you a dev 'scratching an itch'? May I suggest a review of the first few pages/chapters in the PSL docs (Python Standard Library): Built-in Functions, -Constants, -Types, and -Exceptions. Also, try typing into the REPL: pp.__builtins__.__dict__() (you will recognise the dict keys from the docs). These may give you a more authoritative basis for "scalartypes", etc. If you're not already familiar with isinstance() and type() then these (also) most definitely useful tools, and thus worth a read... With bottom-up prototyping it is wise to start with the 'standard' cases! (and to 'extend' one-bite at a time) Rather than handling objects (today's expansion on the previous), might I you refer back to the objective, which (I assume) requires the output of a 'screen-ready' string. Accordingly, as the data-structure/network is parsed/walked, each recognised-component could be recorded as a string, rather than kept/maintained?reproduced in its native form. Thus: - find a scalar, stringify it - find a list, the string is "[" - find a list, the string is "{" - find a tuple, the string is "(" etc The result then, is a series of strings. a) These could be accumulated, ready for output as a single string. This would make it easy to have a further control which limits the number of output characters. b) If the accumulator is a list, then accumulator.append( stringified_element ) works happily. Plus, the return statement can use a str.join() to produce a single accumulator-list as a string. (trouble is, if the values should be comma-separated, you don't want to separate a bracket (eg as a list's open/close) from the list-contents with a comma!) So, maybe that should be done at each layer of nesting? Can you spell FSM? (Finite State Machine) Next set of thoughts: I'm wondering if you mightn't glean a few ideas from reviewing the pprint source-code? (on my (Fedora-Linux) machine it is stored as /usr/lib64/python3.7/pprint.py) Indeed, with imperial ambitions of 'embrace and extend', might you be able to sub-class the pprint class and bend it to your will? Lastly, (and contrasting with your next comment) I became a little intrigued, so yesterday, whilst waiting for an on-line meeting's (rather rude, IMHO) aside to finish (and thus move-on to topics which involved me!), I had a little 'play' with the idea of a post-processor (per previous msg). What I built gives the impression that "quick and dirty" is a thoroughly-considered and well-designed methodology, but the prototype successfully shortens pprint-output to a requisite number of elements. Thus: source_data = [1,2,[31,[321,[3221, 3222],323,324],33],4,5,6] limit( source_data, 3 ) where the second argument (3) is the element-count/-limit; results in: [1,2,[31 ie the first three elements extracted from nested lists (tuples, sets, scalars, etc). (recall my earlier query about what constitutes an "element"?) > Sorry for the very basic questions! No such thing - what is "basic" to you, might seem 'advanced' so someone else, and v-v. Plus, you never know how many 'lurkers' (see below) might be quietly-benefiting from their observation of any discussion! PS on which subject, List Etiquette: There are many people who 'lurk' on the list - which is fine. Presumably they are able to read contributions and learn from what seems interesting. This behavior is (to me) a major justification for the digest service - not being 'bombarded' by many email msgs is how some voice their concerns/preference. However, once one asks a question, one's involvement is no longer passive ('lurking'). Hence: > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." ... > 16. Re: How to limit *length* of PrettyPrinter (dn) ... Further, many of us manage our email 'bombardment' through 'organisation' rather than 'limitation' (or 'condensation'?); and thus "threading" is important - most competent mail-clients offer this, as do GMail and many web-mail services. From a list perspective, this collects and maintains all parts of a conversation - your contributions and mine, in the 'same place'. Sadly, switching between the list-digest and single-messages breaks threading! Also, no-one (including the archiving software) looking at the archive (or the digest) would be able to detect any link between an earlier conversation called "How to limit *length* of PrettyPrinter" and one entitled "...Digest..."! -- Regards =dn -- Regards =dn From jeff.linahan at gmail.com Thu Jul 23 18:28:49 2020 From: jeff.linahan at gmail.com (Jeff Linahan) Date: Thu, 23 Jul 2020 18:28:49 -0400 Subject: Fwd: [BUG] missing ')' causes syntax error on next line In-Reply-To: References: <71aad8e9-b157-4ebf-f7bc-77fc33d67d8a@stoneleaf.us> <53jjhfpm7dn0ev7plbontqmogfs25m6ep4@4ax.com> Message-ID: Interesting PEG thing. C++ compilers are getting better at suggesting fixes for minor syntax errors (in 2011 on MSVC I remember seeing pages of errors for forgetting a semicolon after a struct.) but python seems to be lagging behind in this regard.. will check out superhelp, maybe it'll help me patiently wait for the day where the python compiler does machine learning on my specific style of mistakes to suggest fixes lol. On Thu, Jul 23, 2020, 2:09 PM Chris Angelico wrote: > On Fri, Jul 24, 2020 at 4:00 AM Dennis Lee Bieber > wrote: > > > > On Thu, 23 Jul 2020 09:51:42 +1000, Chris Angelico > > declaimed the following: > > > > >On Thu, Jul 23, 2020 at 9:17 AM dn via Python-list > > > wrote: > > >> However, questions remain:- > > >> > > >> Robot: any machine or mechanical device that operates automatically > with > > >> humanlike skill > > >> > > > > > >What about a human that operates mechanically with merely robot-like > > >skill? I'm pretty sure I've spoken to them on the phone many times. > > > > Would that be... a computer? > > > > > > > > Using the original meaning of "one who computes" > > > > I suspect that even that is too generous for some of them. They merely > follow instructions like good little automatons, until the caller > gives up... > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-l > > From cs at cskk.id.au Thu Jul 23 18:42:16 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 24 Jul 2020 08:42:16 +1000 Subject: Spam, bacon, sausage and Spam (was: EuroPython 2020: Data Science Track) In-Reply-To: <93a3ebc3-42cb-3152-1b21-7b988cf4cce8@python.org> References: <93a3ebc3-42cb-3152-1b21-7b988cf4cce8@python.org> Message-ID: <20200723224216.GA44979@cskk.homeip.net> On 23Jul2020 10:39, Christian Heimes wrote: >On 23/07/2020 02.12, Cameron Simpson wrote: >> I have never attended EuroPython and probably never will (I'm on the >> other side of the planet) but I'm still interested. Rather than >> subscribe to every conference thing, getting them here is very >> convenient. > >I have been to a lot of EuroPython conferences. [...] >I'm not disputing the fact that a conference can use the generic Python >users list for announcements. It's the fact that EP is literally >spamming the list with threads like "Opening our merchandise shop", >"Find a new job", "Introducing our diamond sponsor", and "Presenting our >conference booklet". That's just spam to advertise for the conference or >a company. Some EP announcements were cross-posted to multiple mailing >lists like psf-community at python.org, too. Hmm, yes. For these posts, colour me convinced. I'd be happy to see these dialed back - they arguably belong on a europython announcement list. Things like "conference rescheduled", "attendance arrangements changes due to the virus" etc seem worthy of the main list to me, by contrast. Thanks, Cameron Simpson From chidinmaejiofor6 at gmail.com Fri Jul 24 02:05:19 2020 From: chidinmaejiofor6 at gmail.com (Ejiofor Chidinma Peace) Date: Thu, 23 Jul 2020 23:05:19 -0700 Subject: Issues Download the Latest Version of Python Programming Language Message-ID: Dear Sir/Madam, I trust this email finds you well. I have been having issues downloading the latest version of Python programming Language on my PC (windows 10 operating system). Kindly assist in resolving this issue at your earliest convenience. Looking forward to hearing from you soon. Yours sincerely, Ejiofor, Chidinma Peace. From tjreedy at udel.edu Thu Jul 23 19:52:43 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 23 Jul 2020 19:52:43 -0400 Subject: Iterators, iterables and special objects In-Reply-To: References: Message-ID: On 7/23/2020 5:14 AM, Peter Sl??ik wrote: >> Works in what way? You can't use it in a 'for' loop if it doesn't >> define __iter__. >> > > class Iterable: > def __iter__(self): > return Iterator(...) > > class Iterator: > def __next__(self): > return > > # No __iter__ here. > # I've just forgotten to def it. Which means that an Iterator is not an iterator. > With this setup, using for to iterate over Iterable *will* still work, > though you cannot use the trick described below. > >> Yes? It is indeed an iterator, since its iter method returns itself. It > is also iterable, since it has an iter method. > Of course, you're right. But you're reading the article through the eyes of > an experienced developer. > > >> It's so you can do things like this: >> >> def show_with_header(stuff): >> stuff = iter(stuff) >> hdr = next(stuff) >> print(hdr) >> for line in stuff: >> print(line) >> if new_page(): print(hdr) >> > > Yes, @Terry had given the same example. Frankly, I didn't know about it > before, I somehow had the misconception that for always got a 'fresh' > iterator... The way 'for' gets its iterator is to call iter(iterable). If the iterable is an iterator, iter(iterator) returns iterator. Open files are *iterators*. >>> file.__iter__() is file True This means that one can do things like file = open(...) for line in file: # Section 1 of file. if separator(line): break process1(line) process_sep(line) # Special line that broke iteration. for line in file: # Section 2 of file. process2(line) One alternative is something like file = open(...) section = 1 for line in file: if section == 1: if separator(line): process_sep(line) section = 2 continue process1(line) continue else: process2(line) Another is to use while loops and explicit next(line) calls. The ':=' assignment operator makes this a bit easier. I used to commonly process files with multiple sections and different 'key' lines marking them. -- Terry Jan Reedy From akkana at shallowsky.com Thu Jul 23 21:39:09 2020 From: akkana at shallowsky.com (Akkana Peck) Date: Thu, 23 Jul 2020 19:39:09 -0600 Subject: Need to 'import gtk' on Ubuntu 20.04, what do I need? In-Reply-To: References: Message-ID: <20200724013909.GB1968@shallowsky.com> Chris Green writes: > I have recently upgraded my desktop system from ubuntu 19.10 to ubuntu > 20.04. [ ... ] > The error I am getting is:- [ ... ] > ImportError: No module named gtk > > So what do I need to install on my Ubuntu 20.04 system to provide the > gtk module? Ubuntu doesn't provide python-gtk any more at all. Which makes a number of programs rather difficult now ... > Alternatively (but much harder work) what is the Python 3 equivalent > of the the Python 2 pygtk and gtk modules. ... because there is no close equivalent. In Python 3, GTK is accessed via something called GObject Introspection (module "gi") which requires significant changes to code beyond the usual 2to3 Python migration. You might be able to get the program working using pygtkcompat. Try inserting these lines near the beginning of the program: from gi import pygtkcompat pygtkcompat.enable() pygtkcompat.enable_gtk(version='3.0') If that doesn't work, you might be able to get the old Python 2/GTK 2 packages working by installing these two files with dpkg -i. No warranty of safety or efficacy implied. http://mirrors.kernel.org/ubuntu/pool/universe/p/pygtk/python-gtk2_2.24.0-6_amd64.deb http://mirrors.kernel.org/ubuntu/pool/universe/g/gimp/gimp-python_2.10.8-2_amd64.deb Good luck! It was a nasty shock discovering that Ubuntu had removed python-gtk, especially since they kept lots of other python2 packages (I could have understood it if they'd removed python2 entirely). I don't know what the reasoning was for removing python-gtk while keeping python2. ...Akkana From mats at python.org Thu Jul 23 22:59:20 2020 From: mats at python.org (Mats Wichmann) Date: Thu, 23 Jul 2020 20:59:20 -0600 Subject: Issues Download the Latest Version of Python Programming Language In-Reply-To: References: Message-ID: <5e010392-6722-fd4e-6d2c-05269ecc4f06@python.org> On 7/24/20 12:05 AM, Ejiofor Chidinma Peace wrote: > Dear Sir/Madam, > I trust this email finds you well. > > I have been having issues downloading the latest version of Python > programming Language on my PC (windows 10 operating system). Kindly assist > in resolving this issue at your earliest convenience. > > Looking forward to hearing from you soon. Sorry to not be helpful, but you are going to have to be more descriptive. "Having issues downloading" tells us nothing that we can use to help you with. From cl at isbd.net Fri Jul 24 04:31:05 2020 From: cl at isbd.net (Chris Green) Date: Fri, 24 Jul 2020 09:31:05 +0100 Subject: Need to 'import gtk' on Ubuntu 20.04, what do I need? References: <20200724013909.GB1968@shallowsky.com> Message-ID: <9riqug-hjk5.ln1@esprimo.zbmc.eu> Akkana Peck wrote: > Chris Green writes: > > I have recently upgraded my desktop system from ubuntu 19.10 to ubuntu > > 20.04. [ ... ] > > The error I am getting is:- > [ ... ] > > ImportError: No module named gtk > > > > So what do I need to install on my Ubuntu 20.04 system to provide the > > gtk module? > > Ubuntu doesn't provide python-gtk any more at all. Which makes a > number of programs rather difficult now ... > Not quite true. Originally this program failed with "ImportError: No module named pygtk" so I fished around a bit (i.e. did some searches) and installed python-gobject, python-gobject-2 and python-gi. Doing this got me past the "No module named pygtk", but I get the "No module named gtk" still. So Python GTK is sort of half available. > > Alternatively (but much harder work) what is the Python 3 equivalent > > of the the Python 2 pygtk and gtk modules. > > ... because there is no close equivalent. In Python 3, GTK is > accessed via something called GObject Introspection (module "gi") > which requires significant changes to code beyond the usual 2to3 > Python migration. > So is that what I'm getting by installing the things noted above. I.e. 'import pygtk' is importing GObject things whereas 'import gtk' is after the older stuff. I'm a *fairly* competant Python programmer so, if I have to, I will consider converting from using the gtk module to using the gi module, are there any good tutorials which might help me down this road? > You might be able to get the program working using pygtkcompat. > Try inserting these lines near the beginning of the program: > > from gi import pygtkcompat > pygtkcompat.enable() > pygtkcompat.enable_gtk(version='3.0') > Ah, that sounds like it might be a reasonable path to try, I'll look for documentation on pygtkcompat, it sounds as if that might be useful. > If that doesn't work, you might be able to get the old Python 2/GTK 2 > packages working by installing these two files with dpkg -i. > No warranty of safety or efficacy implied. > > http://mirrors.kernel.org/ubuntu/pool/universe/p/pygtk/python-gtk2_2.24.0-6_amd64.deb > http://mirrors.kernel.org/ubuntu/pool/universe/g/gimp/gimp-python_2.10.8-2_amd64.deb > Yes, I found one thread on stackoverflow which went down this sort of route but it's not going to be a long term solution I suspect. I think modernising and maintaining my own version of the code is going to work better long term. > Good luck! It was a nasty shock discovering that Ubuntu had removed > python-gtk, especially since they kept lots of other python2 packages > (I could have understood it if they'd removed python2 entirely). > I don't know what the reasoning was for removing python-gtk while > keeping python2. > Yes, from my searches it seems to have bitten quite a few people. Thanks for all the help. -- Chris Green ? From random832 at fastmail.com Fri Jul 24 14:35:43 2020 From: random832 at fastmail.com (Random832) Date: Fri, 24 Jul 2020 14:35:43 -0400 Subject: Iterators, iterables and special objects In-Reply-To: References: Message-ID: <57ca6297-c330-4609-980f-51fa08df9ab5@www.fastmail.com> On Tue, Jul 21, 2020, at 15:54, Terry Reedy wrote: > The transformers should be once-through iterators because they can be > passed once-through interators. I suppose one could make them iterables > and add an attribute 'pristine' set to True in __init__ and False in > __iter__, but why have 2 objects instead of 1 when there is not gain in > function? Why not just allow them to be iterated multiple times, and the underlying iterator/iterable either handles that or doesn't as the case may be? We don't have a hard API distinction between iterables and iterators, all iterators are "iterable" in the sense that they have their own __iter__ method that returns self. i.e. the equivalent of class map: def __init__(self, func, obj): ... def __iter__(self): for x in iter(self.obj): yield self.func(x) That way if it is passed a once-through iterator, it is a once-through iterator with a couple extra steps, if passed an iterable it's an iterable. From rosuav at gmail.com Fri Jul 24 14:42:17 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jul 2020 04:42:17 +1000 Subject: Iterators, iterables and special objects In-Reply-To: <57ca6297-c330-4609-980f-51fa08df9ab5@www.fastmail.com> References: <57ca6297-c330-4609-980f-51fa08df9ab5@www.fastmail.com> Message-ID: On Sat, Jul 25, 2020 at 4:37 AM Random832 wrote: > > On Tue, Jul 21, 2020, at 15:54, Terry Reedy wrote: > > The transformers should be once-through iterators because they can be > > passed once-through interators. I suppose one could make them iterables > > and add an attribute 'pristine' set to True in __init__ and False in > > __iter__, but why have 2 objects instead of 1 when there is not gain in > > function? > > Why not just allow them to be iterated multiple times, and the underlying iterator/iterable either handles that or doesn't as the case may be? We don't have a hard API distinction between iterables and iterators, all iterators are "iterable" in the sense that they have their own __iter__ method that returns self. > > i.e. the equivalent of > > class map: > def __init__(self, func, obj): ... > def __iter__(self): for x in iter(self.obj): yield self.func(x) > > That way if it is passed a once-through iterator, it is a once-through iterator with a couple extra steps, if passed an iterable it's an iterable. > And then someone will ask why you can't subscript a map object if the underlying object could be subscripted, etc, etc, etc. It's not meant to be a transparent layer over the object; it's just an iterator - basically equivalent to: def map(func, *iters): try: while True: yield func(*(next(i) for i in iters)) except StopIteration: pass If you want a "MappedList" class, or a "MappedDict" class, or whatever, then build it - it isn't hard. ChrisA From random832 at fastmail.com Fri Jul 24 14:44:06 2020 From: random832 at fastmail.com (Random832) Date: Fri, 24 Jul 2020 14:44:06 -0400 Subject: Iterators, iterables and special objects In-Reply-To: References: Message-ID: <3552b6a7-112f-471f-8a64-403dc0cc195a@www.fastmail.com> On Thu, Jul 23, 2020, at 05:14, Peter Sl??ik wrote: > > Works in what way? You can't use it in a 'for' loop if it doesn't > > define __iter__. > > > > class Iterable: > def __iter__(self): > return Iterator(...) > > class Iterator: > def __next__(self): > return > > # No __iter__ here. > # I've just forgotten to def it. > > With this setup, using for to iterate over Iterable *will* still work, > though you cannot use the trick described below. Sure, but you can't use for to iterate over _Iterator itself_, or do anything else useful with it. >>> class Iterator: ... def __init__(self): self.done=False ... def __next__(self): ... if self.done: raise StopIteration ... self.done = True ... return 1 ... >>> [*Iterator()] >>> [*map(lambda x:x, Iterator())] >>> [*filter(lambda x:True, Iterator())] >>> for x in Iterator(): pass ... >>> [x for x in Iterator()] [all of the above have the exact same exception] Traceback (most recent call last): File "", line 1, in TypeError: 'Iterator' object is not iterable >>> def gen(): ... yield from Iterator() ... >>> [*gen()] Traceback (most recent call last): File "", line 1, in File "", line 2, in gen TypeError: 'Iterator' object is not iterable From random832 at fastmail.com Fri Jul 24 14:50:00 2020 From: random832 at fastmail.com (Random832) Date: Fri, 24 Jul 2020 14:50:00 -0400 Subject: Iterators, iterables and special objects In-Reply-To: References: <57ca6297-c330-4609-980f-51fa08df9ab5@www.fastmail.com> Message-ID: On Fri, Jul 24, 2020, at 14:42, Chris Angelico wrote: > And then someone will ask why you can't subscript a map object if the > underlying object could be subscripted, etc, etc, etc. It's not meant > to be a transparent layer over the object; it's just an iterator - > basically equivalent to: > > def map(func, *iters): > try: > while True: > yield func(*(next(i) for i in iters)) > except StopIteration: > pass > > If you want a "MappedList" class, or a "MappedDict" class, or > whatever, then build it - it isn't hard. Asking to be able to restart the iteration is hardly the same thing as asking to pass through subscripts etc... C#'s Linq functions do fine with restartable iterables and hardly ever expose Iterators [well, IEnumerators, as they're called] to the user at all. If the original IEnumerable was restartable, so are all the intervening steps if you put an arbitrarily long chain of Select, Where, etc, on them, since each one restarts the one under it. Obviously no-one should reasonably expect to be able to pass list subscripts through, say, a filter object, but restarting is a perfectly reasonable thing to do to *any* transformation of an iterable, whether or not it groups, splits, filters, interjects items or anything else you might imagine doing. From k.d.jantzen at mailbox.org Fri Jul 24 16:13:57 2020 From: k.d.jantzen at mailbox.org (Klaus Jantzen) Date: Fri, 24 Jul 2020 22:13:57 +0200 Subject: [SOLVED] Re: Installing Python 3.8.3 with tkinter In-Reply-To: References: Message-ID: <0f8cea93-df3d-2883-19d1-be87ff995c6d@mailbox.org> On 7/22/20 12:20 PM, Klaus Jantzen wrote: > Hi, > > Trying to install Python 3.8.3 with tkinter I run configure with the > following options > > ./configure --enable-optimizations --with-ssl-default-suites=openssl > --with-openssl=/usr/local --enable-loadable-sqlite-extensions > --with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6' > --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include' > > Running Python gives the following information > > Python 3.8.3 (default, Jul 22 2020, 11:52:15) > [GCC 8.3.0] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import sqlite3 > >>> import tkinter > Traceback (most recent call last): > ? File "", line 1, in > ? File "/usr/local/lib/python3.8/tkinter/__init__.py", line 36, in > > ??? import _tkinter # If this fails your Python may not be configured > for Tk > ModuleNotFoundError: No module named '_tkinter' > >>> > > Obviously there is something wrong with my configure options. > > How do that correctly? > > Thanks for any help. > > K.D.J. > > In my post I forgot to mention that I am running PY under Debian Buster. As suggested by Ned Deily I switched to PY 3.8.5 After some more research in the internet I found that the tcl/tk libraries have automaticalle been installed during the Buster installation. For automatically including tkinter during the PY installation one needs also the 'tk-dev toolkit'. With that I did not need the options '--with-tcltk-libs'/'--with-tcltk-includes' After the installation of PY 3.8.5 I can import tkinter. Thank you very much for your replies. K.D.J. From PythonList at DancesWithMice.info Fri Jul 24 16:30:26 2020 From: PythonList at DancesWithMice.info (dn) Date: Sat, 25 Jul 2020 08:30:26 +1200 Subject: Iterators, iterables and special objects In-Reply-To: <57ca6297-c330-4609-980f-51fa08df9ab5@www.fastmail.com> References: <57ca6297-c330-4609-980f-51fa08df9ab5@www.fastmail.com> Message-ID: On 25/07/2020 06:35, Random832 wrote: > On Tue, Jul 21, 2020, at 15:54, Terry Reedy wrote: >> The transformers should be once-through iterators because they can be >> passed once-through interators. I suppose one could make them iterables >> and add an attribute 'pristine' set to True in __init__ and False in >> __iter__, but why have 2 objects instead of 1 when there is not gain in >> function? > > Why not just allow them to be iterated multiple times, and the underlying iterator/iterable either handles that or doesn't as the case may be? We don't have a hard API distinction between iterables and iterators, all iterators are "iterable" in the sense that they have their own __iter__ method that returns self. > > i.e. the equivalent of > > class map: > def __init__(self, func, obj): ... > def __iter__(self): for x in iter(self.obj): yield self.func(x) > > That way if it is passed a once-through iterator, it is a once-through iterator with a couple extra steps, if passed an iterable it's an iterable. If the design calls for a single iteration of the contents of some container (for example), then need a signal to indicate 'end of data', ie StopIteration. Conversely, if prepared to iterate continuously, don't ever want to see that exception. How to differentiate? Solution already available: perhaps cycle() or chain() itertools ? Functions creating iterators for efficient looping https://docs.python.org/3/library/itertools.html -- Regards =dn From macrakis at alum.mit.edu Fri Jul 24 18:52:02 2020 From: macrakis at alum.mit.edu (Stavros Macrakis) Date: Fri, 24 Jul 2020 18:52:02 -0400 Subject: How to limit *length* of PrettyPrinter Message-ID: dn, Thanks again. For background, I come from C and Lisp hacking (one of the MIT developers of Macsyma /Maxima ) and also play with R, though I haven't been a professional developer for many years. I know better than to Reply to a Digest -- sorry about that, I was just being sloppy. The reason I wanted print-length limitation was that I wanted to get an overview of an object I'd created, which contains some very long lists. I expected that this was standard functionality that I simply couldn't find in the docs. I'm familiar with writing pretty-printer ("grind") functions with string output (from way back: see section II.I, p. 12 ), but I'm not at all familiar with Python's type/class system, which is why I'm trying to understand it by playing with it. I did try looking at the Python Standard Library docs, but I don't see where it mentions the superclasses of the numerics or of the collection types or the equivalent of *numberp*. If I use *type(4).__bases__*, I get just* (,)*, which isn't very helpful. I suspect that that isn't the correct way of finding a class's superclasses -- what is? BTW, where do I look to understand the difference between *dir(type(4)) *(which does not include *__bases__*) and *type(4).__dir__(type(4)) *(which does)? According to Martelli (2017, p. 127), *dir(*x*)* just calls *x.**__dir__()*; but *type(4).__dir__() *=> ERR for me. Has this changed since 3.5, or is Martelli just wrong? There's nothing else obvious in dir(0) or in dir(type(0)). After some looking around, I find that the base classes are not built-in, but need to be added with the *numbers* and *collections.abc *modules? That's a surprise! You suggested I try *pp.__builtins__.__dict__()* . I couldn't figure out what you meant by *pp* here (the module name *pprint*? the class *pprint.PrettyPrint*? the configured function *pprint.PrettyPrinter(width=20,indent=3).pprint*? none worked...). I finally figured out that you must have meant something like *pp=pprint.PrettyPrinter(width=80).print; pp(__builtins__.__dict__)*. Still not sure which attributes could be useful. With bottom-up prototyping it is wise to start with the 'standard' cases! (and to 'extend' one-bite at a time) Agreed! I started with lists, but couldn't figure out how to extend that to tuples and sets. I was thinking I could build a list then convert it to a tuple or set. The core recursive step looks something like this: CONVERT( map( lambda i: limit(i, length, depth-1) , obj[0:length] ) + ( [] if len(obj) <= length else ['...'] ) ) ... since map returns an iterator, not a collection of the same type as its input -- so how do I convert to the right result type (CONVERT)? After discovering that typ.__new__(typ,obj) doesn't work for mutables, and thrashing for a while, I tried this: def convert(typ,obj): newobj = typ.__new__(typ,obj) newobj.__init__(obj) return newobj which is pretty ugly, because the *__new__* initializer is magically ignored for a mutable (with no exception) and the *__init__* setter is magically ignored for an immutable (with no exception). But it seems to work.... Now, on to dictionaries! Bizarrely, the *list()* of a dictionary, and its iterator, return only the keys, not the key-value pairs. No problem! We'll create yet another special case, and use *set.items()* (which for some reason doesn't exist for other collection types). And *mirabile dictu*, *convert *works correctly for that!: dicttype = type({'a':1}) test = {'a':1,'b':2} convert(dicttype,test.items()) => {'a':1,'b':2} So we're almost done. Now all we have to do is slice the result to the desired length: convert(dicttype,test.items()[0:1]) # ERR But *dict.items() *is not sliceable. However, it *is* iterable... but we need another count variable (or is there a better way?): c = 0 convert(dicttype, [ i for i in test.items() if (c:=c+1)<2 ]) Phew! That was a lot of work, and I'm left with a bunch of special cases, but it works. Now I need to understand from a Python guru what the Pythonic way of doing this is which *doesn't* require all this ugliness. (This doesn't really work for the original problem, because there's no way of putting "..." at the end of a dictionary object, but I still think I learned something about Python.) I did take a look at the pprint source code, and could no doubt modify it to handle print-length, but at this point, I'm still trying to understand how Python code can be written generically. So I was disappointed to see that *_print_list, _print_tuple, *and* _print_set *are not written generically, but as three separate functions. I also wonder what the '({' case is supposed to cover. A lot of questions -- probably based on a lot of misunderstandings! Thanks! -s From digitalfantasy.it86559 at digitalfantasy.it Sat Jul 25 13:40:56 2020 From: digitalfantasy.it86559 at digitalfantasy.it (Liste guru) Date: Sat, 25 Jul 2020 19:40:56 +0200 Subject: Need to 'import gtk' on Ubuntu 20.04, what do I need? In-Reply-To: <9riqug-hjk5.ln1@esprimo.zbmc.eu> References: <20200724013909.GB1968@shallowsky.com> <9riqug-hjk5.ln1@esprimo.zbmc.eu> Message-ID: Il 24/07/2020 10:31, Chris Green ha scritto: ?? ... > I'm a *fairly* competant Python programmer so, if I have to, I > willconsider converting from using the gtk module to using the gi > module,are there any good tutorials which might help me down this road? ?? If you look at the pygobject documentation there is a chapter (and a script, similar to 2to3) to help the migration: https://pygobject.readthedocs.io/en/latest/guide/porting.html From torriem at gmail.com Sat Jul 25 15:08:23 2020 From: torriem at gmail.com (Michael Torrie) Date: Sat, 25 Jul 2020 13:08:23 -0600 Subject: Need to 'import gtk' on Ubuntu 20.04, what do I need? In-Reply-To: References: Message-ID: <2957621c-876f-495c-0b48-10aefc327ee5@gmail.com> On 7/23/20 2:41 PM, Chris Green wrote: > I have recently upgraded my desktop system from ubuntu 19.10 to ubuntu > 20.04. I have some Oki printer/scanner driver software that is > written in Python 2 and, although python 2 is still installed on my > system it's no longer the default python and the Oki software no > longer runs. > > The error I am getting is:- > > chris at esprimo$ ./scantool.py > Traceback (most recent call last): > File "./scantool.py", line 52, in > import gtk > ImportError: No module named gtk > > So what do I need to install on my Ubuntu 20.04 system to provide the > gtk module? Someone has made a PPA with the python2 pygtk2 package: https://launchpad.net/~nrbrtx/+archive/ubuntu/python2-stuff sudo add-apt-repository ppa:nrbrtx/python2-stuff sudo apt-get install python-gtk2 I can't vouch for the source, so use at your own risk. From PythonList at DancesWithMice.info Sat Jul 25 19:42:45 2020 From: PythonList at DancesWithMice.info (dn) Date: Sun, 26 Jul 2020 11:42:45 +1200 Subject: How to limit *length* of PrettyPrinter In-Reply-To: References: Message-ID: <00f53890-e149-6af4-0b08-0fa6da4e114b@DancesWithMice.info> Let me preface this reply with the concern that my level of competence, in this area, is insufficient. However, there are a number of folk 'here' who are 'into' Python's internals, and will (hopefully) jump-in... Also, whilst we appear to be concentrating on understanding the content of a data-structure, have we adequately defined "length"? (per msg title) - total number of o/p lines (per paper.ref) - total number of characters 'printed' - total number of elements l-r (of any/all embedded data-structures) - the number of elements in each embedded data-structure - the number of characters displayed from each embedded d-s - depth of data-structure t-d - something else? On 25/07/2020 10:52, Stavros Macrakis wrote: > dn, Thanks again. > > For background, I come from C and Lisp hacking (one of the MIT > developers of Macsyma /Maxima > ) and also play with > R,?though I haven't been a professional developer for many years. I know > better than to Reply to a Digest -- sorry about that, I was just being > sloppy. Us 'silver-surfers' have to stick-together! Also in the seventies I decided Lisp was not for me... > The reason I wanted print-length limitation was that I wanted to get an > overview of an object I'd created, which contains some very long lists. > I expected that this was standard functionality?that I simply couldn't > find in the docs. > > I'm familiar?with writing?pretty-printer ("grind") functions with string > output (from way back: see section II.I, p. 12 > ), but > I'm not at all familiar with Python's type/class system, which is why > I'm trying to understand it by playing with it. I accept, one might say 'on faith', that in Python "everything is an object", and proceed from there. Sorry! Similarly, I've merely accepted the limitations of pprint() - and probably use it less-and-less, as I become more-and-more oriented towards TDD... > I did try looking at the Python Standard Library docs, but I don't see > where it mentions the superclasses of the numerics or of the collection > types or the equivalent of *numberp*. If I use *type(4).__bases__*, I > get just*(,)*, which isn't very helpful. I suspect that > that isn't the correct way of finding a class's superclasses -- what is? If you haven't already, try: - The Python Language Reference Manual (see Python docs) in particular "Data Model" - PSL: Data Types = "types -- Dynamic type creation and names for built-in types" - PSL: collections - PSL: collections.abc Another source of 'useful background' are PEPs (Python Enhancement Proposals). Note that some have been accepted and are part of the current-language - so the "proposal" part has become an historic record. In comparison: some have been rejected, and others are still under-discussion... - PEP 0: an index - PEP 3119 -- Introducing Abstract Base Classes - PEP 3141 -- A Type Hierarchy for Numbers - and no-doubt many more, which will keep you happily entertained, and save the members of your local flock of sheep from thinking that to you they are a mere number... > BTW, where do I look to understand the difference between *dir(type(4)) > *(which does not include *__bases__*) and *type(4).__dir__(type(4)) > *(which does)? According to Martelli (2017, p. 127), *dir(*x*)*?just > calls /*x*./*__dir__()*; but *type(4).__dir__() *=> ERR for me. Has this > changed since 3.5, or is Martelli just wrong? I don't know - and I'm not about to question Alex! > There's nothing?else obvious in dir(0) or in dir(type(0)). After some > looking around, I find that the base classes are not built-in, but need > to be added with the *numbers*?and *collections.abc *modules? That's a > surprise! Yes, to me there is much mystery in this (hence "faith", earlier). Everything is a sub-class of object. When I need to differentiate, eg between a list and a dict; I either resort to isinstance() or back to the helpful table/taxonomy in collections.abc and hasattr() - thus a tuple is a Collection and a Sequence, but not a MutableSequence like a list. A set looks like a list until it comes to duplicate values or behaving as a Sequence. A dict is a MutableMapping, but as you say (below), when considered a Collection will only behave as a list of keys. So, we then chase the *View-s... > You suggested I try *pp.__builtins__.__dict__()* . I couldn't figure out > what you meant by *pp* here (the module name *pprint*? the class > *pprint.PrettyPrint*? the configured function > *pprint.PrettyPrinter(width=20,indent=3).pprint*? none worked...). I > finally figured out that you must have meant something like > *pp=pprint.PrettyPrinter(width=80).print; pp(__builtins__.__dict__)*. > Still not sure which attributes could be useful. With apologies: "pp" is indeed pprint. The code-example should have been prefaced with: from pprint import pprint as pp This is (?my) short-hand, whenever I'm using pprint within a module. (you will find our number-crunching friends referring to "np" rather than the full: "numpy", and similar... > With bottom-up prototyping it is wise to start with the 'standard' > cases! (and to 'extend' one-bite at a time) > Agreed! I started with lists, but couldn't figure out how to extend that > to tuples and sets.? I was thinking I could build a list then convert it > to a tuple or set. The core recursive step looks something like this: > > ? ? ? CONVERT( map( lambda i: limit(i, length, depth-1) , obj[0:length] > )?+ ( [] if len(obj) <= length else ['...'] ) ) > > ... since map returns an iterator, not a collection of the same type as > its input -- so how do I convert to the right result type (CONVERT)? > > After discovering that typ.__new__(typ,obj) doesn't work for mutables, > and thrashing for a while, I tried this: > > ? ? ? def convert(typ,obj): > ? ? ? ? ? ?newobj = typ.__new__(typ,obj) > ? ? ? ? ? ?newobj.__init__(obj) > ? ? ? ? ? ?return newobj > > which is pretty ugly, because the *__new__* initializer is magically > ignored for a mutable (with no exception) and the *__init__* setter is > magically ignored for an immutable (with no exception). But it seems to > work.... > > Now, on to dictionaries! Bizarrely, the *list()*?of a dictionary, and > its iterator, return only the keys, not the key-value pairs. No problem! > We'll create yet another special case, and use */set/.items()*?(which > for some reason doesn't exist for other collection types). And /mirabile > dictu/, *convert *works correctly for that!: > > dicttype = type({'a':1}) > test = {'a':1,'b':2} > convert(dicttype,test.items()) =>?{'a':1,'b':2} > > So we're almost done. Now all we have to do is slice the result to the > desired length: > > convert(dicttype,test.items()[0:1])? ? ? # ERR > > > But */dict./items() *is not sliceable. However, it /is/?iterable... but > we need another count variable (or is there a better way?): > > > c = 0 > convert(dicttype, [ i for i in test.items() if (c:=c+1)<2 ]) > > > Phew! That was a lot of work, and I'm left with a bunch of special > cases, but it works. Now I need to understand from a Python guru what > the Pythonic way of doing this is which /doesn't/?require all this ugliness. > > (This doesn't really work for the original problem, because there's no > way of putting "..." at the end of a dictionary object, but I still > think I learned something about Python.) > > I did take a look at the pprint source code, and could no doubt modify > it to handle print-length, but at this point, I'm still trying to > understand how Python code can be written generically. So I was > disappointed to see that *_print_list, _print_tuple, *and*_print_set > *are not written generically, but as three separate functions. I also > wonder what the '({' case is supposed to cover. > > A lot of questions -- probably based on a lot of misunderstandings! ...and any response severely limited by my competence in these topics, eg my assumption that the data would be presented with different brackets, ie the "({", according to type. Recently, I offered a "Friday Finking" to the list, relating a Junior Programmer's wrestling with the challenge of expanding an existing API from scalar values to a choice between scalars and a tuple. (or was it a list - or does it really matter?) There seemed to be no suggestion beyond isinstance(). In this case, there will be a 'ladder' of if...elif...else clauses, and quite possibly needed in two places - parsing and printing. (The ref.paper talked of two passes, so...) PS there is talk of a case/switch which will handle class-distinction, but alas, not currently available (PEP 622?Python 3.10). Is the challenge one of attempting to retain and represent the values within the data-structure? There is an implicit issue here, that a first-approach may be essentially replication (ie storage-expensive). Nevertheless, proceeding in this fashion, remember that a Python list is not the "array" of other languages! Content-elements need not be homogeneous. So, an 'accumulator' list could contain a dict, a set, sundry scalars, and/or inner-lists, in perfect happiness. Through zip(), Python has a very handy (IMHO) way of linking two lists, without any effort on my part. (I work very hard at being this lazy!) So, during 'parsing', it is possible to (say) build one list recording 'type', eg list, dict, set, ... and a parallel list containing the values (or k-v pairs, or i,j, or...). Yet more, if/when a 'length' metric can be computed... Thereafter when it comes to presentation, the assembled lists can be zip-ped together in a for-loop to yield the final-presentation. Apologies, the above seems to be 'fluff around the edges' rather than addressing the central needs of the problem. I'm also a little concerned about your expertise level and the likelihood that I may be 'talking down'. -- Regards =dn From lists at andros.org.uk Sun Jul 26 08:33:57 2020 From: lists at andros.org.uk (Andrew McLean) Date: Sun, 26 Jul 2020 13:33:57 +0100 Subject: Dowloading package dependencies from locked down machine Message-ID: <31a4543e-806d-cfbd-9962-26933e1d5127@andros.org.uk> At work my only Internet access is via a locked-down PC. The IT department are not willing to install Python on it [1]. Ideally I would download packages and their dependencies from PyPi using "pip download" at the command line. Any better solutions than downloading the package in a browser, finding its dependencies manually, downloading these and so on recursively? My dream solution would be for PyPi to provide a link to a zip file that bundled up a package and its dependencies, but I realise that this is probably a very niche requirement. - Andrew [1] Apparently they think installing Python would be incompatible with their Cyber Essentials Plus security accreditation, although it's apparently fine to have Microsoft Office 365 with a build in VBA interpreter! From waste at is.invalid Sun Jul 26 08:56:04 2020 From: waste at is.invalid (Termoregolato) Date: Sun, 26 Jul 2020 14:56:04 +0200 Subject: Symlinks already present Message-ID: There is any way to check if a directory is already symlinked, without controlling every symlink viewing the link? That is a bit time consuming, due I've two or three directory that can have a new symlink, but I've to check on a list of 20-30000 symlinks to delete it and avoid duplicates... From barry at barrys-emacs.org Sun Jul 26 09:19:59 2020 From: barry at barrys-emacs.org (Barry) Date: Sun, 26 Jul 2020 14:19:59 +0100 Subject: Symlinks already present In-Reply-To: References: Message-ID: <9D792E9E-5D1E-4B6D-B10C-C99AA73B1598@barrys-emacs.org> > On 26 Jul 2020, at 14:03, Termoregolato wrote: > > ?There is any way to check if a directory is already symlinked, No. None. > without controlling every symlink viewing the link? That is a bit time consuming, due I've two or three directory that can have a new symlink, but I've to check on a list of 20-30000 symlinks to delete it and avoid duplicates... Don?t you have control of the code that is adding the symlinks? Barry > -- > https://mail.python.org/mailman/listinfo/python-list > From waste at is.invalid Sun Jul 26 13:02:46 2020 From: waste at is.invalid (Termoregolato) Date: Sun, 26 Jul 2020 19:02:46 +0200 Subject: Symlinks already present In-Reply-To: References: <9D792E9E-5D1E-4B6D-B10C-C99AA73B1598@barrys-emacs.org> Message-ID: Il 26/07/20 15:19, Barry ha scritto: > No. None. Sob :-) But thanks for confirm. > Don?t you have control of the code that is adding the symlinks? No, so I must traverse the directories where symlinks are, to deduplicate them. There are some modes to minimize the work, but that way could be the simplest. From atagar1 at gmail.com Sat Jul 25 21:36:03 2020 From: atagar1 at gmail.com (Damian Johnson) Date: Sat, 25 Jul 2020 18:36:03 -0700 Subject: Support both asyncio and synchronous callers Message-ID: Hi. I'm the author of Stem, Tor's python library [1]. Recently we migrated to asyncio, but desire to still be usable by synchronous callers. We wrote a mixin [2][3] that transparently makes any class usable by both asyncio and synchronous callers... ====================================================================== import asyncio import stem.util.asyncio class Example(stem.util.asyncio.Synchronous): async def hello(self): return 'hello' def sync_demo(): instance = Example() print('%s from a synchronous context' % instance.hello()) instance.stop() async def async_demo(): instance = Example() print('%s from an asynchronous context' % await instance.hello()) instance.stop() sync_demo() asyncio.run(async_demo()) ====================================================================== Is there a better way to approach this? Our wider ecosystem seem to be forking networking libraries into sync/async variants, with requests [4] and AIOHTTP [5] as the most prominent. Are there any libraries out there that demonstrate good support for both kinds of callers without duplicating their API? Thanks! -Damian PS. I apologize if this email gets duplicated. Initially I used a different email address which Mailman seemed to decline. [1] https://stem.torproject.org/ [2] https://gitweb.torproject.org/stem.git/tree/stem/util/asyncio.py [3] https://gitweb.torproject.org/stem.git/tree/test/unit/util/asyncio.py [4] https://requests.readthedocs.io/en/master/ [5] https://docs.aiohttp.org/en/latest/index.html From miked at dewhirst.com.au Sun Jul 26 09:07:01 2020 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Sun, 26 Jul 2020 23:07:01 +1000 Subject: Dowloading package dependencies from locked down machine Message-ID: <4BF3l60Pfdzndk3@mail.python.org> I think your best bet is to make a formal business case to your IT people and explain what's in it for them. If they hold all the cards you defeat them at your peril.Mike From macrakis at alum.mit.edu Sun Jul 26 14:52:26 2020 From: macrakis at alum.mit.edu (Stavros Macrakis) Date: Sun, 26 Jul 2020 14:52:26 -0400 Subject: How to cast to a type WAS: How to limit *length* of PrettyPrinter Message-ID: I was a bit unhappy with my convert function: def convert(typ,obj): newobj = typ.__new__(typ,obj) newobj.__init__(obj) return newobj because it called __xxx__ functions, which are supposed to be internal. It was also a surprise that __new__ ignores the obj for (mutable) lists, but __init__ ignores the obj for (immutable) tuples (rather than throwing an exception). Reading the reference manual, I see that I was right to be unhappy, because the straightforward way is: def convert(typ,obj): return typ(obj) and it works in other cases as well, e.g., type(3.4)(True) and type({})((i,i) for i in range(0,2)). From PythonList at DancesWithMice.info Sun Jul 26 16:47:57 2020 From: PythonList at DancesWithMice.info (dn) Date: Mon, 27 Jul 2020 08:47:57 +1200 Subject: Symlinks already present In-Reply-To: References: Message-ID: <5198cab4-4edc-29cc-c135-fb019abb9077@DancesWithMice.info> On 27/07/2020 00:56, Termoregolato wrote: > There is any way to check if? a directory is already symlinked, without > controlling every symlink viewing the link? That is a bit time > consuming, due I've two or three directory that can have a new symlink, > but I've to check on a list of 20-30000 symlinks to delete it and avoid > duplicates... Please review "os ? Miscellaneous operating system interfaces" (https://docs.python.org/3/library/os.html) - in particular os.stat() - and thus os.stat_result, and given what you appear to be doing, possibly os.scandir() and os.DirEntry. I built a test: dir1 -- dir-link = symlink to dir2 dir2 -- real-file >>> os.stat( "dir2", follow_symlinks=True ) os.stat_result(st_mode=16893, st_ino=2345143, st_dev=64773, st_nlink=2, st_uid=1000, st_gid=1000, st_size=4096, st_atime=1595793224, st_mtime=1595793223, st_ctime=1595793223) >>> os.stat( "dir1/dir-link", follow_symlinks=True ) os.stat_result(st_mode=16893, st_ino=2345143, st_dev=64773, st_nlink=2, st_uid=1000, st_gid=1000, st_size=4096, st_atime=1595793224, st_mtime=1595793223, st_ctime=1595793223) >>> os.stat( "dir1/dir-link", follow_symlinks=False ) os.stat_result(st_mode=41471, st_ino=2345146, st_dev=64773, st_nlink=1, st_uid=1000, st_gid=1000, st_size=7, st_atime=1595793558, st_mtime=1595793558, st_ctime=1595793558) NB st_size Size of the file in bytes, if it is a regular file or a symbolic link. The size of a symbolic link is the length of the pathname it contains, without a terminating null byte. Thus, compare the results of the two calls to detect a difference. -- Regards =dn From abolunthompson at gmail.com Sun Jul 26 17:32:19 2020 From: abolunthompson at gmail.com (Bolun Thompson) Date: Sun, 26 Jul 2020 21:32:19 +0000 Subject: Is sys.executable not supposed to follow symlinks? Message-ID: In the sys.executable documentation ( https://docs.python.org/3/library/sys.html#sys.executable), they don't specify if it follows symlinks. From my limited testing, it does not. Is this behavior guaranteed? From rosuav at gmail.com Sun Jul 26 18:10:27 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Jul 2020 08:10:27 +1000 Subject: Is sys.executable not supposed to follow symlinks? In-Reply-To: References: Message-ID: On Mon, Jul 27, 2020 at 8:04 AM Bolun Thompson wrote: > > In the sys.executable documentation ( > https://docs.python.org/3/library/sys.html#sys.executable), they don't > specify if it follows symlinks. From my limited testing, it does not. Is > this behavior guaranteed? I don't know about guaranteed, but it's certainly the behaviour I would expect. Recognizing the invocation executable is important to a lot of commands that behave differently based on that, for instance with the detection of a virtual environment. The fact that the executable might be a symlink is irrelevant. If you want to follow symlinks, you can always readlink on it. ChrisA From eryksun at gmail.com Sun Jul 26 21:12:06 2020 From: eryksun at gmail.com (Eryk Sun) Date: Sun, 26 Jul 2020 20:12:06 -0500 Subject: Is sys.executable not supposed to follow symlinks? In-Reply-To: References: Message-ID: On 7/26/20, Bolun Thompson wrote: > In the sys.executable documentation ( > https://docs.python.org/3/library/sys.html#sys.executable), they don't > specify if it follows symlinks. From my limited testing, it does not. Is > this behavior guaranteed? In Unix, the interpreter resolves the target of sys.executable if it's a symlink in order to set the prefix directory, which is the base path for the standard library (i.e. "prefix/lib/pythonX.Y"). For a contrived example, compare using a symlink vs. a hardlink when the landmark "lib/python3.8/os.py" exists relative to the directory of the link. With a hardlink, it will accept the link directory as the prefix path, without falling back on the configured default prefix path (e.g. "/usr"), and the interpreter will fail to start. But with a symlink, in an strace you can see the executable getting resolved at the start via readlink(), and it will try setting the prefix to "/usr" and eventually find the landmark "/usr/lib/python3.8/os.py". In Windows, for Python 3.8 finding python38.dll and vcruntime140.dll reliably depends on their being beside the executable in the application directory. The loader does not resolve symlinks, and depending on PATH to find python38.dll is unreliable (e.g. it could find an x86 32-bit DLL when it needs an x64 DLL). For argument's sake, it's possible to link python.exe, python38.dll, python3.dll, and vcruntime140.dll all together in the target directory (as would be done in a venv that uses symlinks). In this case, if you repeat the above contrived example by creating the landmark r"Lib\os.py" relative to the directory of the symlinks, then the interpreter will fail to start. There's no reason stopping Python in Windows from resolving the target of a symlink'd executable when searching for the prefix directory, but it's not a pressing concern since using symlinks is relatively uncommon in Windows. A virtual environment may use symlinks, but pyvenv.cfg is used to find the standard library in that case. Also, other than the above contrived example, an installed Python has a default "PythonPath" set in its registry key, which it uses when the prefix directory isn't found otherwise. From cl at isbd.net Mon Jul 27 09:35:45 2020 From: cl at isbd.net (Chris Green) Date: Mon, 27 Jul 2020 14:35:45 +0100 Subject: Need to 'import gtk' on Ubuntu 20.04, what do I need? References: <20200724013909.GB1968@shallowsky.com> <9riqug-hjk5.ln1@esprimo.zbmc.eu> Message-ID: Liste guru wrote: > Il 24/07/2020 10:31, Chris Green ha scritto: > > > ?? ... > > > I'm a *fairly* competant Python programmer so, if I have to, I > > willconsider converting from using the gtk module to using the gi > > module,are there any good tutorials which might help me down this road? > > > ?? If you look at the pygobject documentation there is a chapter (and a > script, similar to 2to3) to help the migration: > https://pygobject.readthedocs.io/en/latest/guide/porting.html > Thanks, it looks as if this is the way I will have to go. I guess converting to Python 3 and pygobject (for 3) will be a 'good thing' in the long run and it will mean I will become familiar enough with the software to keep maintaining it easily (and even fix some annoying quirks). -- Chris Green ? From waste at is.invalid Mon Jul 27 14:20:08 2020 From: waste at is.invalid (Termoregolato) Date: Mon, 27 Jul 2020 20:20:08 +0200 Subject: Symlinks already present In-Reply-To: References: <0oirhftpslnaqgpoaks0lsb4dj7rmugkl7@4ax.com> Message-ID: Il 26/07/20 20:39, Dennis Lee Bieber ha scritto: > Since symbolic links are essentially just short files containing the > path to the eventual target file/directory, with an OS flag that the file > is a link Yes, I use them massively to give to a lot of directories a kind of order, depending on their contents. It's simple to see if link is broken, but not if they're duplicate -- Pastrano con un altro account From rosuav at gmail.com Mon Jul 27 14:37:21 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jul 2020 04:37:21 +1000 Subject: Symlinks already present In-Reply-To: References: <0oirhftpslnaqgpoaks0lsb4dj7rmugkl7@4ax.com> Message-ID: On Tue, Jul 28, 2020 at 4:26 AM Termoregolato wrote: > > Il 26/07/20 20:39, Dennis Lee Bieber ha scritto: > > > Since symbolic links are essentially just short files containing the > > path to the eventual target file/directory, with an OS flag that the file > > is a link > > Yes, I use them massively to give to a lot of directories a kind of > order, depending on their contents. It's simple to see if link is > broken, but not if they're duplicate > Ah, I think I get what you're doing. Do you need an efficient way to see if a single target directory has multiple symlinks pointing to it, or are you trying to audit the entire collection all at once? I don't think there's a neat way to do the former, but the latter isn't too hard. Try something like this: # Enumerate the target directories (the real/physical ones) dirs = {dir: None for dir in os.listdir("....")} # Iterate over the symlinks and see where they point for link in os.listdir("...."): dest = os.readlink(link) if dirs[dest]: print("DUPLICATE") print(dirs[dest], link) dirs[dest] = link You can then also check if any are missing, by seeing if there are any Nones left in the dirs dict. Unfortunately there's no real way to shortcut this if you just want to check one target directory. You'd still have to readlink() every symlink to try to find them. ChrisA From 2QdxY4RzWzUUiLuE at potatochowder.com Mon Jul 27 14:41:48 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Mon, 27 Jul 2020 13:41:48 -0500 Subject: Symlinks already present In-Reply-To: References: <0oirhftpslnaqgpoaks0lsb4dj7rmugkl7@4ax.com> Message-ID: <20200727184148.GD22144@scrozzle> On 2020-07-27 at 20:20:08 +0200, Termoregolato wrote: > Il 26/07/20 20:39, Dennis Lee Bieber ha scritto: > > > Since symbolic links are essentially just short files containing the > > path to the eventual target file/directory, with an OS flag that the file > > is a link > > Yes, I use them massively to give to a lot of directories a kind of order, > depending on their contents. It's simple to see if link is broken, but not > if they're duplicate If you know where the symlinks can be, then find and collect them into a dictionary whose keys are the *targets* and whose values are a list of the symlinks that point to that target. Then it's easy to spot the targets that have more than one symlink. -- ?Whoever undertakes to set himself up as a judge of Truth and Knowledge is shipwrecked by the laughter of the gods.? ? Albert Einstein Dan Sommers, http://www.tombstonezero.net/dan From waste at is.invalid Mon Jul 27 14:35:37 2020 From: waste at is.invalid (Termoregolato) Date: Mon, 27 Jul 2020 20:35:37 +0200 Subject: Symlinks already present In-Reply-To: References: <5198cab4-4edc-29cc-c135-fb019abb9077@DancesWithMice.info> Message-ID: Il 26/07/20 22:47, dn ha scritto: > Thus, compare the results of the two calls to detect a difference. I will try also another way, If I don't err symlinks and original directory have the same inode number (I talk about Linux, where I'm using the application). I've a lot of directories like this abcd efgh .ab dc de where last part can change depending on contents. The are symlinked in a tree of a different dir, divided in many other directories, like work/a/abcd efgh .ab dc de where generally there are 5-50 links. So I could, if correct, walk the directory, and keeping a small array with the inode numbers check if these numbers are duplicated. -- Pastrano con un altro account From hschilling at criptext.com Mon Jul 27 17:35:05 2020 From: hschilling at criptext.com (Romulus Schilling) Date: Mon, 27 Jul 2020 21:35:05 +0000 Subject: Very Simple (Rather Dumb) Question In-Reply-To: <1595885704865.954141@criptext.com> Message-ID: <1595885704865.954141@criptext.com> Hello, I have a quick, and most likely rather dumb begginer question on Python. It may be simple, but I'm completely new to Python, and to programming in general, so I'll go right to the point. My question is: I just downloaded the latest version of python, and started following a tutorial I found online on "first steps with Python Programming." The thing is, in the very first part, where I just had to write "print("Hello World")" into IDLE and then save the file to my desktop and execute it, I ran into a problem. When I saved the file with helloworld.py, the file that popped up into my desktop was a uTorrent file for some reason (I have uTorrent installed), even though I saved it with the right format for a Python file (I've added photos below). I searched online for explanations but found nothing (maybe because, again, its a very stupid question). Anyway, I was wondering if someone could help me in fixing this. (and yes, I've already tried unistalling and reinstalling python, and uTorrent, to no avail) thx for the attention[https://api.criptext.com/email/open/%3C1595885704865.954141%40criptext.com%3E] From lists at andros.org.uk Mon Jul 27 19:43:20 2020 From: lists at andros.org.uk (Andrew McLean) Date: Tue, 28 Jul 2020 00:43:20 +0100 Subject: Dowloading package dependencies from locked down machine In-Reply-To: <5f1d826b.1c69fb81.1c716.cc24SMTPIN_ADDED_MISSING@mx.google.com> References: <5f1d826b.1c69fb81.1c716.cc24SMTPIN_ADDED_MISSING@mx.google.com> Message-ID: <049c5e30-e0a4-2b3a-f1cf-7ff181775dbe@andros.org.uk> On 26/07/2020 14:07, Mike Dewhirst wrote: > I think your best bet is to make a formal business case to your IT > people and explain what's in it for them. If they hold all the cards > you defeat them at your peril. The issue is that the IT department thinks that installing the full power of Python scripting on an Internet facing machine is inconsistent with the "Cyber Essentials Plus" accreditiation that they need to win Government contracts. I'm trying to come up with an alternative that would be acceptable to them, I'm not going behind their backs. I wonder, would it be possible to create a standalone executable version of pip with py2exe or similar? - Andrew From grant.b.edwards at gmail.com Mon Jul 27 18:19:10 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 27 Jul 2020 22:19:10 -0000 (UTC) Subject: Symlinks already present References: <5198cab4-4edc-29cc-c135-fb019abb9077@DancesWithMice.info> Message-ID: On 2020-07-27, Termoregolato wrote: > Il 26/07/20 22:47, dn ha scritto: > >> Thus, compare the results of the two calls to detect a difference. > > I will try also another way, If I don't err symlinks and original > directory have the same inode number (I talk about Linux, where I'm > using the application). You err. Symlinks are distinct i-nodes which are not the same i-node as the destination. A symlink is basically a file containing a string that is read and then used a path to another file. If you create a "hard" link (ln without the '-s') then you end up a single i-node that has entries in multiple directories. [old-Unix-guy story: Way back when, SunOS used to allow you (if root) to create a hard link to a directory. It's not something you did a second time.] From miked at dewhirst.com.au Mon Jul 27 21:15:49 2020 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Tue, 28 Jul 2020 11:15:49 +1000 Subject: Dowloading package dependencies from locked down machine In-Reply-To: <049c5e30-e0a4-2b3a-f1cf-7ff181775dbe@andros.org.uk> References: <5f1d826b.1c69fb81.1c716.cc24SMTPIN_ADDED_MISSING@mx.google.com> <049c5e30-e0a4-2b3a-f1cf-7ff181775dbe@andros.org.uk> Message-ID: On 28/07/2020 9:43 am, Andrew McLean wrote: > On 26/07/2020 14:07, Mike Dewhirst wrote: >> I think your best bet is to make a formal business case to your IT >> people and explain what's in it for them. If they hold all the cards >> you defeat them at your peril. > > The issue is that the IT department thinks that installing the full > power of Python scripting on an Internet facing machine is > inconsistent with the "Cyber Essentials Plus" accreditiation that they > need to win Government contracts. If that is the issue you need to change their thinking. You need to persuade them first that "Cyber Essentials Plus" accreditation is not necessary to win government contracts -OR- that replacing vb with python will (perhaps) enhance it to "Plus Plus" > I'm trying to come up with an alternative that would be acceptable to > them, I'm not going behind their backs. They could unlock your machine in a wink if you can successfully argue a compelling case. > > I wonder, would it be possible to create a standalone executable > version of pip with py2exe or similar? It might be possible. I don't know. I think however it would be unnecessary if you win your case. The hard facts are that IT people are usually overloaded and under-resourced. Anything out of the ordinary is a severe burden. Not only do they have to start catering for individual differences they have to be able to justify their decisions to management *before* anything goes wrong. Because if it did go wrong and they hadn't run it past the boss they would be looking (with a "loose cannon" blot on their CV) for another employer. May the case be with you! Mike > > - Andrew > > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From ikorot01 at gmail.com Mon Jul 27 21:33:14 2020 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 27 Jul 2020 20:33:14 -0500 Subject: Dowloading package dependencies from locked down machine In-Reply-To: <049c5e30-e0a4-2b3a-f1cf-7ff181775dbe@andros.org.uk> References: <5f1d826b.1c69fb81.1c716.cc24SMTPIN_ADDED_MISSING@mx.google.com> <049c5e30-e0a4-2b3a-f1cf-7ff181775dbe@andros.org.uk> Message-ID: Hi, On Mon, Jul 27, 2020 at 6:46 PM Andrew McLean wrote: > > On 26/07/2020 14:07, Mike Dewhirst wrote: > > I think your best bet is to make a formal business case to your IT > > people and explain what's in it for them. If they hold all the cards > > you defeat them at your peril. > > The issue is that the IT department thinks that installing the full > power of Python scripting on an Internet facing machine is inconsistent > with the "Cyber Essentials Plus" accreditiation that they need to win > Government contracts. I'm trying to come up with an alternative that > would be acceptable to them, I'm not going behind their backs. > > I wonder, would it be possible to create a standalone executable version > of pip with py2exe or similar? Coming from experience working with the Government Contractor first hand, they have to have an approved list of software people can work with. Ask to provide that list. Now such a list is provided by the Security Office and it does not come from the IT department. You can actually go and check this list yourself. Check with your company FSO. I can assure you python will definitely be on that list. Its possible that some python modules may not be there but the language/interpreter will. Thank you. > > - Andrew > > > -- > https://mail.python.org/mailman/listinfo/python-list From mats at wichmann.us Tue Jul 28 12:56:28 2020 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 28 Jul 2020 10:56:28 -0600 Subject: Dowloading package dependencies from locked down machine In-Reply-To: References: <5f1d826b.1c69fb81.1c716.cc24SMTPIN_ADDED_MISSING@mx.google.com> <049c5e30-e0a4-2b3a-f1cf-7ff181775dbe@andros.org.uk> Message-ID: <06dcbe1b-c447-55b3-dc23-86779ed9d5d6@wichmann.us> On 7/27/20 7:33 PM, Igor Korot wrote: > Hi, >> The issue is that the IT department thinks that installing the full >> power of Python scripting on an Internet facing machine is inconsistent >> with the "Cyber Essentials Plus" accreditiation that they need to win >> Government contracts. > Coming from experience working with the Government Contractor first hand, > they have to have an approved list of software people can work with. > > Ask to provide that list. > Now such a list is provided by the Security Office and it does not > come from the IT department. > > You can actually go and check this list yourself. Check with your company > FSO. > > I can assure you python will definitely be on that list. > Its possible that some python modules may not be there but the > language/interpreter will. US Government entities use Python extensively. *Some* are forced to use a special "restricted" version of Python, the mythical FIPS-Compliant version, that removes your ability to use a few things, notably the md5 hash because it's been deemed "insecure" (even if you're not using it for cryptographic purposes, it's just banned). From python at python.invalid Tue Jul 28 11:10:07 2020 From: python at python.invalid (Python) Date: Tue, 28 Jul 2020 17:10:07 +0200 Subject: Dowloading package dependencies from locked down machine In-Reply-To: References: <31a4543e-806d-cfbd-9962-26933e1d5127@andros.org.uk> Message-ID: <5f203fcd$0$13562$426a74cc@news.free.fr> Andrew McLean wrote: > At work my only Internet access is via a locked-down PC. The IT > department are not willing to install Python on it [1]. Ideally I would > download packages and their dependencies from PyPi using "pip download" > at the command line. Any better solutions than downloading the package > in a browser, finding its dependencies manually, downloading these and > so on recursively? You may want to give FPM a try: il allows you to build and provide most of PyPI in a yum/apt repository. You can make all build on a separate system then export rpm/deb packages. https://github.com/jordansissel/fpm From jpic at yourlabs.org Tue Jul 28 15:29:58 2020 From: jpic at yourlabs.org (J. Pic) Date: Tue, 28 Jul 2020 21:29:58 +0200 Subject: Dowloading package dependencies from locked down machine In-Reply-To: <31a4543e-806d-cfbd-9962-26933e1d5127@andros.org.uk> References: <31a4543e-806d-cfbd-9962-26933e1d5127@andros.org.uk> Message-ID: Ideas for solutions: - use pip install --user at home, copy over ~/.local/lib/python3.8/site-packages - same, but with ~/.cache/pip From ekopalypse at gmail.com Tue Jul 28 15:46:13 2020 From: ekopalypse at gmail.com (Eko palypse) Date: Tue, 28 Jul 2020 21:46:13 +0200 Subject: Windows and Subclassing - 'OverflowError': int too long to convert Message-ID: Hello, I am subclassing a scintilla window and it happens every now and then that I get an OverflowError. I've logged the message and could narrow down that it is a single windows message which causes this trouble. It's WM_ERASEBKGND. Now the confusing part for me is the following. According to MS WPARAM is an UINT_PTR which is defined as #if defined(_WIN64) typedef unsigned __int64 UINT_PTR; #else typedef unsigned int UINT_PTR; #endif wintypes.WPARAM is ctypes.c_ulonglong and is of size 8 on my system. I'm on a x64 Windows - so far as good, right? Now when I get this error the message I receive in this situation is always like this. hWnd=197364, msg=20, wParam=*18446744072652653190*, lParam=0 Traceback (most recent call last): File "_ctypes/callbacks.c", line 237, in 'calling callback function' File "", line 121, in new_scintilla2_proc ctypes.ArgumentError: argument 4: : int too long to convert I really doubt that 18446744072652653190 is a valid device context but who knows. The question is, why do I even get this OverflowError? If I do wintypes.WPARAM(18446744072652653190) I don't receive an exception and it is a valid 64bit value, isn't it? The code I'm using is this user32 = ctypes.WinDLL('user32', use_last_error=True) LRESULT = wintypes.LPARAM WND_PROC = ctypes.WINFUNCTYPE(LRESULT, wintypes.HWND, wintypes.UINT, wintypes.WPARAM, wintypes.LPARAM) user32.CallWindowProcW.restype = LRESULT user32.CallWindowProcW.argtypes = [WND_PROC, wintypes.HWND, wintypes.UINT, wintypes.WPARAM, wintypes.LPARAM] Any idea what might have caused this? Thank you for reading Eren From PythonList at DancesWithMice.info Tue Jul 28 15:47:28 2020 From: PythonList at DancesWithMice.info (dn) Date: Wed, 29 Jul 2020 07:47:28 +1200 Subject: Dowloading package dependencies from locked down machine In-Reply-To: References: <31a4543e-806d-cfbd-9962-26933e1d5127@andros.org.uk> Message-ID: <1cfef7ad-3368-a02d-438c-a4b9bfbe5628@DancesWithMice.info> On 29/07/2020 07:29, J. Pic wrote: > Ideas for solutions: > > - use pip install --user at home, copy over ~/.local/lib/python3.8/site-packages > - same, but with ~/.cache/pip ...or even building an entire parallel Python environment on an Internet-connected machine (even a VM), from which the PYTHONPATH dirs could be copied/mirrored to the 'difficult machine'. However, if the machine is 'locked-down', am slightly puzzled that 'the man' would allow you to add proscribed software by some other (non-Internet, eg USB) means! -- Regards =dn From barry at barrys-emacs.org Tue Jul 28 16:07:53 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Tue, 28 Jul 2020 21:07:53 +0100 Subject: Support both asyncio and synchronous callers In-Reply-To: References: Message-ID: <797E037B-B3C3-4D6C-89B9-D84501FF8A07@barrys-emacs.org> > On 26 Jul 2020, at 02:36, Damian Johnson wrote: > > Hi. I'm the author of Stem, Tor's python library [1]. Recently we > migrated to asyncio, but desire to still be usable by synchronous > callers. > > We wrote a mixin [2][3] that transparently makes any class usable by > both asyncio and synchronous callers... > > ====================================================================== > > import asyncio > import stem.util.asyncio > > class Example(stem.util.asyncio.Synchronous): > async def hello(self): > return 'hello' > > def sync_demo(): > instance = Example() > print('%s from a synchronous context' % instance.hello()) > instance.stop() > > async def async_demo(): > instance = Example() > print('%s from an asynchronous context' % await instance.hello()) > instance.stop() > > sync_demo() > asyncio.run(async_demo()) > > ====================================================================== > > Is there a better way to approach this? > > Our wider ecosystem seem to be forking networking libraries into > sync/async variants, with requests [4] and AIOHTTP [5] as the most > prominent. Are there any libraries out there that demonstrate good > support for both kinds of callers without duplicating their API? Maybe you have a sync facade that uses the async version to do the work? That way you have one implementation and two ways to use it. Barry > > Thanks! -Damian > > PS. I apologize if this email gets duplicated. Initially I used a > different email address which Mailman seemed to decline. > > [1] https://stem.torproject.org/ > [2] https://gitweb.torproject.org/stem.git/tree/stem/util/asyncio.py > [3] https://gitweb.torproject.org/stem.git/tree/test/unit/util/asyncio.py > [4] https://requests.readthedocs.io/en/master/ > [5] https://docs.aiohttp.org/en/latest/index.html > -- > https://mail.python.org/mailman/listinfo/python-list > From Gronicus at SGA.Ninja Tue Jul 28 16:56:04 2020 From: Gronicus at SGA.Ninja (Steve) Date: Tue, 28 Jul 2020 16:56:04 -0400 Subject: Local access to a file, How To ? Message-ID: <03d801d66521$82c36d20$884a4760$@SGA.Ninja> I have a python program that reads and writes to files that are all within the folder that contains the python program. There is now a second python program that is to be run to compile information in said files. I am having difficulty trying to call the local supporting program from within the main program. I would it would found easily because everything is all in the same folder. Apparently, I have to decipher paths to do the task. One problem is that the project is portable on a thumb drive and the path can change based on the computer on which the program is executed. I look up use of path and I seem to get all absolute path instruction and not relative. Where an I steering wrongly here. Steve Footnote: In 10 years, are these going to be the "good old times" that we are living right now? From python at mrabarnett.plus.com Tue Jul 28 18:06:16 2020 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 28 Jul 2020 23:06:16 +0100 Subject: Local access to a file, How To ? In-Reply-To: <03d801d66521$82c36d20$884a4760$@SGA.Ninja> References: <03d801d66521$82c36d20$884a4760$@SGA.Ninja> Message-ID: <2fe7edb2-48c9-f8e0-1806-924559478054@mrabarnett.plus.com> On 2020-07-28 21:56, Steve wrote: > > I have a python program that reads and writes to files that are all within > the folder that contains the python program. There is now a second python > program that is to be run to compile information in said files. > > > > I am having difficulty trying to call the local supporting program from > within the main program. I would it would found easily because everything > is all in the same folder. Apparently, I have to decipher paths to do the > task. > > > > One problem is that the project is portable on a thumb drive and the path > can change based on the computer on which the program is executed. I look > up use of path and I seem to get all absolute path instruction and not > relative. > > > > Where an I steering wrongly here. > It's easiest to work with absolute paths. The path of the script is given by __file__, so the folder in which the script is running is given by os.path.dirname(__file__). You can work from there to make the paths of the other files using os.path.join(...). From PythonList at DancesWithMice.info Tue Jul 28 18:14:47 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 29 Jul 2020 10:14:47 +1200 Subject: Local access to a file, How To ? In-Reply-To: <03d801d66521$82c36d20$884a4760$@SGA.Ninja> References: <03d801d66521$82c36d20$884a4760$@SGA.Ninja> Message-ID: On 29/07/2020 08:56, Steve wrote: > I have a python program that reads and writes to files that are all within > the folder that contains the python program. There is now a second python > program that is to be run to compile information in said files. > > I am having difficulty trying to call the local supporting program from > within the main program. I would it would found easily because everything > is all in the same folder. Apparently, I have to decipher paths to do the > task. > > One problem is that the project is portable on a thumb drive and the path > can change based on the computer on which the program is executed. I look > up use of path and I seem to get all absolute path instruction and not > relative. > > Where an I steering wrongly here. Questions: - is the second program kept in the same directory as the first, or somewhere else? - by "call" do you mean "import", or... If the program and the data files are in the same directory, then you will have noticed that there is no need for absolute addressing, ie open( "file.in" ) not open( "/home/me/Projets/this/file.in" ) The same applies to import-s. From program_A we can import program_B in the same directory. No need for absolute paths, anywhere! That is to say, Python works happily with the concept of the "current working directory", and when no absolute-path is provided assumes 'this directory' - or if a non-absolute-path is provided (doesn't commence with "/", in the case of Posix) prefixes the path from 'this directory'. Yes, there are many caveats beyond such a simple explanation, but that should be enough to get-going. Keeping 'everything' in the single directory, and always executing from there, should enable migration. -- Regards =dn From Marco.Sulla.Python at gmail.com Wed Jul 29 03:02:37 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Wed, 29 Jul 2020 09:02:37 +0200 Subject: How to pass options to "make test"? Message-ID: After building CPython from source, I run the regression test suite, using make test (I'm on Linux). Now I would run only some tests, and pass a custom option (-R :) I tried TESTOPTS="test_pickle" make test without success. I had to do: ./python -u -bb -E -Wd -m test -r --fail-env-changed -w -j 0 test_pickle This works, but I would specify only custom options. PS: -R option finds reference leaks (python -m test --help explains it) From gisle.vanem at gmail.com Wed Jul 29 04:26:25 2020 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Wed, 29 Jul 2020 10:26:25 +0200 Subject: The speed of glob() Message-ID: <5c319759-19b8-511d-d10b-a83d670e4971@gmail.com> Has anybody noticed the speed of 'glob()' has decreased somewhere between v3.6 and v3.10. With this little test: ------------ import os, sys, timeit, glob # change to suite globPath = u'e:/net/*/*/*/*' def _glob(): glob.glob (globPath) # I used this 'https://docs.microsoft.com/en-gb/sysinternals/downloads/sync' def flush_disks(): sync = r"f:\ProgramFiler\Sysinternals\sync.exe -nobanner" print ("Exec sync: %s" % sync) os.system (sync) flush_disks() print ("Python %d.%d.%d:" % sys.version_info[:3]) print (" 1st run: %.5f" % timeit.timeit (_glob, number=1)) print (" 2nd run: %.5f" % timeit.timeit (_glob, number=1)) ------------ I got these results: Python 3.6.5: 1st run: 0.14694 2nd run: 0.09506 <- *always* the fastest Python 3.7.7: <- from Nuget 1st run: 0.12440 2nd run: 0.09602 Python 3.10.0: <- from Git repo 1st run: 0.15922 2nd run: 0.12424 'glob()' in Python 3.6.5 is consistently 30% faster on the 2nd run compared to 3.10.0. -- --gv From rosuav at gmail.com Wed Jul 29 04:56:23 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Jul 2020 18:56:23 +1000 Subject: The speed of glob() In-Reply-To: <5c319759-19b8-511d-d10b-a83d670e4971@gmail.com> References: <5c319759-19b8-511d-d10b-a83d670e4971@gmail.com> Message-ID: On Wed, Jul 29, 2020 at 6:27 PM Gisle Vanem wrote: > > Has anybody noticed the speed of 'glob()' has > decreased somewhere between v3.6 and v3.10. > > I got these results: > Python 3.6.5: > 1st run: 0.14694 > 2nd run: 0.09506 <- *always* the fastest > Python 3.7.7: <- from Nuget > 1st run: 0.12440 > 2nd run: 0.09602 > Python 3.10.0: <- from Git repo > 1st run: 0.15922 > 2nd run: 0.12424 > > 'glob()' in Python 3.6.5 is consistently 30% faster on > the 2nd run compared to 3.10.0. > Unfortunately that's very hard to compare. If you're building Python from source, the parameters may be VERY different from a prepackaged binary. Are you able to redo this test with more consistent Python builds? For instance, you can go as far as 3.8 using python.org binaries, or alternatively, build all your tests from git (by checking out different branches). My guess is that something changed in the caching rules when listdir/scandir changes happened, but there's no way to know for sure. ChrisA From gisle.vanem at gmail.com Wed Jul 29 05:43:06 2020 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Wed, 29 Jul 2020 11:43:06 +0200 Subject: The speed of glob() In-Reply-To: References: <5c319759-19b8-511d-d10b-a83d670e4971@gmail.com> Message-ID: <001d1355-def6-77e7-dc4d-a43783a4e4bf@gmail.com> Chris Angelico wrote: >> Has anybody noticed the speed of 'glob()' has >> decreased somewhere between v3.6 and v3.10. >> >> I got these results: >> Python 3.6.5: >> 1st run: 0.14694 >> 2nd run: 0.09506 <- *always* the fastest >> Python 3.7.7: <- from Nuget >> 1st run: 0.12440 >> 2nd run: 0.09602 >> Python 3.10.0: <- from Git repo >> 1st run: 0.15922 >> 2nd run: 0.12424 >> >> 'glob()' in Python 3.6.5 is consistently 30% faster on >> the 2nd run compared to 3.10.0. >> > > Unfortunately that's very hard to compare. If you're building Python > from source, the parameters may be VERY different from a prepackaged > binary. I guess so w/o knowing why. I just tried this from MS' AppStore: Python 3.8.5: 1st run: 0.12121 2nd run: 0.07674 Fastest I've tried so far. > Are you able to redo this test with more consistent Python builds? For > instance, you can go as far as 3.8 using python.org binaries, or > alternatively, build all your tests from git (by checking out > different branches). I do not want to put to much stress on this. Maybe I'm just 'ass-u-me'ing too much? The important thing is that any Python3.x is much faster on both the 1st and 2nd run compared to my Python 2.7. -- --gv From rosuav at gmail.com Wed Jul 29 05:50:33 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Jul 2020 19:50:33 +1000 Subject: The speed of glob() In-Reply-To: <001d1355-def6-77e7-dc4d-a43783a4e4bf@gmail.com> References: <5c319759-19b8-511d-d10b-a83d670e4971@gmail.com> <001d1355-def6-77e7-dc4d-a43783a4e4bf@gmail.com> Message-ID: On Wed, Jul 29, 2020 at 7:44 PM Gisle Vanem wrote: > > Chris Angelico wrote: > > >> Has anybody noticed the speed of 'glob()' has > >> decreased somewhere between v3.6 and v3.10. > >> > >> I got these results: > >> Python 3.6.5: > >> 1st run: 0.14694 > >> 2nd run: 0.09506 <- *always* the fastest > >> Python 3.7.7: <- from Nuget > >> 1st run: 0.12440 > >> 2nd run: 0.09602 > >> Python 3.10.0: <- from Git repo > >> 1st run: 0.15922 > >> 2nd run: 0.12424 > >> > >> 'glob()' in Python 3.6.5 is consistently 30% faster on > >> the 2nd run compared to 3.10.0. > >> > > > > Unfortunately that's very hard to compare. If you're building Python > > from source, the parameters may be VERY different from a prepackaged > > binary. > > I guess so w/o knowing why. I just tried this from MS' AppStore: > Python 3.8.5: > 1st run: 0.12121 > 2nd run: 0.07674 > > Fastest I've tried so far. That suggests that there's a lot of irrelevant noise in those numbers. Ah well. > > Are you able to redo this test with more consistent Python builds? For > > instance, you can go as far as 3.8 using python.org binaries, or > > alternatively, build all your tests from git (by checking out > > different branches). > > I do not want to put to much stress on this. Maybe I'm just 'ass-u-me'ing > too much? > > The important thing is that any Python3.x is much faster on both > the 1st and 2nd run compared to my Python 2.7. > Ah, now THAT has a number of very good explanations, and most likely IS meaningful. There've been several optimizations aimed at hammering the file system less to get the same info, so I'm not at all surprised that you're seeing an improvement. BTW, I just noticed something. The path you're using for testing purposes is "e:/net". Is that network-attached or local? If it's a remote mount of some sort, then that will make a HUGE difference, and it also means that the sync command you're using probably won't ensure that you have a clean testing platform. But if that's local, then no probs, don't mind me. ChrisA From christian at python.org Wed Jul 29 05:58:19 2020 From: christian at python.org (Christian Heimes) Date: Wed, 29 Jul 2020 11:58:19 +0200 Subject: The speed of glob() In-Reply-To: <001d1355-def6-77e7-dc4d-a43783a4e4bf@gmail.com> References: <5c319759-19b8-511d-d10b-a83d670e4971@gmail.com> <001d1355-def6-77e7-dc4d-a43783a4e4bf@gmail.com> Message-ID: On 29/07/2020 11.43, Gisle Vanem wrote: > Chris Angelico wrote: > >>> Has anybody noticed the speed of 'glob()' has >>> decreased somewhere between v3.6 and v3.10. >>> >>> I got these results: >>> ??? Python 3.6.5: >>> ????? 1st run: 0.14694 >>> ????? 2nd run: 0.09506?? <- *always* the fastest >>> ??? Python 3.7.7:??????? <- from Nuget >>> ????? 1st run: 0.12440 >>> ????? 2nd run: 0.09602 >>> ??? Python 3.10.0:?????? <- from Git repo >>> ????? 1st run: 0.15922 >>> ????? 2nd run: 0.12424 >>> >>> 'glob()' in Python 3.6.5 is consistently 30% faster on >>> the 2nd run compared to 3.10.0. >>> >> >> Unfortunately that's very hard to compare. If you're building Python >> from source, the parameters may be VERY different from a prepackaged >> binary. > > I guess so w/o knowing why. I just tried this from MS' AppStore: > Python 3.8.5: > ? 1st run: 0.12121 > ? 2nd run: 0.07674 > > Fastest I've tried so far. Official builds and most distribution builds are optimized PGO builds (PGO = profile guided optimization). It's a multi-step build approach. At first the build system creates a special instrumented version of Python that collects runtime information. Then it executes tests to collect information how the code is used. Finally the build system builds Python again. The compiler uses the runtime information to create optimized code. Some distributions also use special compiler flags or other tricks to make Python even faster. Victor Stinner (a Python core dev) and his co-workers have done some research to speed up Python by up to 30% on top of PGO, https://developers.redhat.com/blog/2020/06/25/red-hat-enterprise-linux-8-2-brings-faster-python-3-8-run-speeds/ Christian From gisle.vanem at gmail.com Wed Jul 29 06:23:34 2020 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Wed, 29 Jul 2020 12:23:34 +0200 Subject: The speed of glob() In-Reply-To: References: <5c319759-19b8-511d-d10b-a83d670e4971@gmail.com> <001d1355-def6-77e7-dc4d-a43783a4e4bf@gmail.com> Message-ID: Chris Angelico wrote: > BTW, I just noticed something. The path you're using for testing > purposes is "e:/net". Is that network-attached or local? If it's a > remote mount of some sort, then that will make a HUGE difference No. Did the word 'net' make you think that :-) It's a local FAT32 partition where I keep old 'net' related projects. Whether it's NTFS or FAT32 should hopefully not matter for relative speed-compares. -- --gv From rosuav at gmail.com Wed Jul 29 06:34:32 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Jul 2020 20:34:32 +1000 Subject: The speed of glob() In-Reply-To: References: <5c319759-19b8-511d-d10b-a83d670e4971@gmail.com> <001d1355-def6-77e7-dc4d-a43783a4e4bf@gmail.com> Message-ID: On Wed, Jul 29, 2020 at 8:25 PM Gisle Vanem wrote: > > Chris Angelico wrote: > > > BTW, I just noticed something. The path you're using for testing > > purposes is "e:/net". Is that network-attached or local? If it's a > > remote mount of some sort, then that will make a HUGE difference > > No. Did the word 'net' make you think that :-) It's a local > FAT32 partition where I keep old 'net' related projects. > Whether it's NTFS or FAT32 should hopefully not matter for > relative speed-compares. It made me wonder, and I asked just in case :) The file system quite probably WILL make a difference, but only in the sense that different FSes will see greater or lesser effect from the same changes. The direction of the change should be the same regardless. ChrisA From cl at isbd.net Wed Jul 29 06:20:42 2020 From: cl at isbd.net (Chris Green) Date: Wed, 29 Jul 2020 11:20:42 +0100 Subject: Non IDE development strategy - what do others do that's fairly simple? Message-ID: I have a few python programs that I have written which I need to do some fairly extensive changes to (to get from gtk to gobject and to move to Python 3). This is on a Linux (xubuntu 20.04) system. I use the command line to do just about everything (even though the program is GUI!) and so I tend to edit in one window and test in an adjacent window on the same screen, I don't find GUI development environments comfortable. The existing code simply lives in ~/bin with a couple of modules in ~/bin/pymods (which directory is in my PYTHONPATH). I use mercurial for configuration management of the code, directly in the ~/bin directory. This works fine for the sort of minor bug fixing and updates that I do most of the time, I'm the only user so changing the 'live' code isn't a major issue and I can always drop back to the last working version using mercurial. However with this more major change to do I really need a 'development' copy of the code as well as the live working copy as it's likely I will take a few days to do the changes (as in an hour or so each day over some days) and I need the ability to use the program meanwhile. So, finally to the question, does anyone else have this command line based sort of approach and, if so, what do they do to provide a 'development version' of a program in parallel with a working version? I guess virtualenv (Python 2) and venv (Python 3) address this problem but they do feel rather more complex than I actually need and I'm not very clear how you move code from the virtual environment to 'live'. There's also the issue that I'm moving code from Python 2 to Python 3 so which virtual environment should I use? Any ideas or suggestions would be very welcome. -- Chris Green ? From cl at isbd.net Wed Jul 29 06:55:35 2020 From: cl at isbd.net (Chris Green) Date: Wed, 29 Jul 2020 11:55:35 +0100 Subject: Confused by python gtk, gobject, gi, etc. (Ubuntu repositories) Message-ID: <7618vg-s1m5.ln1@esprimo.zbmc.eu> I am trying to move some code from Python 2, gtk 2 (I think!) to Python 3. I am very confused as to what Ubuntu repository packages I need to install to provide the Python 3 modules I need. Searching in the repositories (and descriptions) for pygobject what I find is:- python-gi-dev/focal 3.36.0-1 amd64 development headers for GObject Python bindings python-glade2/focal 2.24.0-0~201711230314~ubuntu18.04.1 amd64 GTK+ bindings: Glade support python-gobject-2-dev/focal,focal 2.28.6-14ubuntu1 all development headers for the static GObject Python bindings python-gtk2/focal,now 2.24.0-0~201711230314~ubuntu18.04.1 amd64 [installed] Python bindings for the GTK+ widget set python-gtk2-dbg/focal 2.24.0-0~201711230314~ubuntu18.04.1 amd64 Python bindings for the GTK+ widget set (debug extension) python-gtk2-dev/focal,focal 2.24.0-0~201711230314~ubuntu18.04.1 all GTK+ bindings: devel files python-gtk2-doc/focal,focal 2.24.0-0~201711230314~ubuntu18.04.1 all Python bindings for the GTK+ widget set - documentation python-gtkspellcheck/focal,focal 3.0-0~3~ubuntu14.04.1 all spellchecking library written in Python for Gtk based on Enchant python-gtkspellcheck-doc/focal,focal 4.0.5-2 all Python GTK+ Spellcheck common documentation python3-gtkspellcheck/focal,focal 4.0.5-2 all Python 3 spellchecking library for GTK+ based on Enchant python3-hinawa-utils/focal,focal 0.2.0-1 all Library to control Audio and Music units on FireWire (IEEE1394) So what do I need to install to get what I need? Is it python3-gi? I think it is but I'm not at all sure! Also, where do I find the pygi-convert.sh script? I have python3-gi installed but I don't have pygi-convert.sh. -- Chris Green ? From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Jul 29 07:12:26 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Wed, 29 Jul 2020 06:12:26 -0500 Subject: Non IDE development strategy - what do others do that's fairly simple? In-Reply-To: References: Message-ID: <20200729111226.GD26859@scrozzle> On 2020-07-29 at 11:20:42 +0100, Chris Green wrote: > I have a few python programs that I have written which I need to do > some fairly extensive changes to (to get from gtk to gobject and to > move to Python 3). This is on a Linux (xubuntu 20.04) system. I use > the command line to do just about everything (even though the program > is GUI!) and so I tend to edit in one window and test in an adjacent > window on the same screen, I don't find GUI development environments > comfortable. +1. All of it. Except that I'm on Arch rather than XUbuntu, and our definitions of "one window" and "adjacent" likely vary. > However with this more major change to do I really need a > 'development' copy of the code as well as the live working copy as > it's likely I will take a few days to do the changes (as in an hour or > so each day over some days) and I need the ability to use the program > meanwhile. Given that you develop in production, you might be better off thinking of the Python3 version as a new program rather than a simple maintenance upgrade of the existing one. > ... does anyone else have this command line based sort of approach > and, if so, what do they do to provide a 'development version' of a > program in parallel with a working version? > I guess virtualenv (Python 2) and venv (Python 3) address this problem > but they do feel rather more complex than I actually need and I'm not > very clear how you move code from the virtual environment to 'live'. > There's also the issue that I'm moving code from Python 2 to Python 3 > so which virtual environment should I use? All my development takes place under ~/src, which is mostly under source coontrol, but not under virtual environments. When I'm satisfied, I "release" or "install" to ~/bin and/or ~/lib by copying the relevant file(s). Too many years of work-related production environments being unavailable or unsuitable for development (unless you squint just right at the times I used to patch machine code on a hardware emulator). HTH, YMMV, etc. From cl at isbd.net Wed Jul 29 09:34:42 2020 From: cl at isbd.net (Chris Green) Date: Wed, 29 Jul 2020 14:34:42 +0100 Subject: How to diagnose import error when importing from .so file? Message-ID: I have some Python Gtk 2 code I'm trying to convert to Python pygobject GTK 3. However I'm stuck on an import statement that fails:- import pyscand The error message is:- File "/usr/libexec/okimfputl.new/guicom.py", line 66, in import pyscand ImportError: /usr/libexec/okimfpdrv/pyscand.so: undefined symbol: _Py_ZeroStruct pyscand is a .so file so I fear I may be a bit stuffed unless I can find the source code for it. However any other ideas would be most welcome. In fact looking for this error it seems that is is a Python version mismatch error and I need to recompile pyscand.so against Python 3. Is there no way to sort of convert it to Python 3 without having the source? -- Chris Green ? From eryksun at gmail.com Wed Jul 29 10:26:22 2020 From: eryksun at gmail.com (Eryk Sun) Date: Wed, 29 Jul 2020 09:26:22 -0500 Subject: Windows and Subclassing - 'OverflowError': int too long to convert In-Reply-To: References: Message-ID: On 7/28/20, Eko palypse wrote: > > Now when I get this error the message I receive in this situation is always > like this. > > hWnd=197364, msg=20, wParam=*18446744072652653190*, lParam=0 > > Traceback (most recent call last): > File "_ctypes/callbacks.c", line 237, in 'calling callback function' > File "", line 121, in new_scintilla2_proc > ctypes.ArgumentError: argument 4: : int too long to > convert Can you provide a more complete example of how you're calling CallWindowProcW in new_scintilla2_proc? It seems like a function pointer is being called that doesn't have argtypes defined. For example: >>> user32 = ctypes.WinDLL('user32', use_last_error=True) >>> user32.CallWindowProcW(None, None, 0x14, 18446744072652653190, 0) Traceback (most recent call last): File "", line 1, in ctypes.ArgumentError: argument 4: : int too long to convert Perhaps in new_scintilla2_proc you're using a different instance of ctypes.WinDLL, or you switched to using ctypes.windll.user32. I recommend avoiding the global ctypes.LibraryLoader instances -- ctypes.cdll, ctypes.windll, and ctypes.oledll -- because using them leads to conflicts with other libraries, but you do need to use a single instance of ctypes.WinDLL for your user32 function prototypes, imported from a common module. From Gronicus at SGA.Ninja Wed Jul 29 11:13:10 2020 From: Gronicus at SGA.Ninja (Steve) Date: Wed, 29 Jul 2020 11:13:10 -0400 Subject: Local access to a file, How To ? In-Reply-To: References: <03d801d66521$82c36d20$884a4760$@SGA.Ninja> Message-ID: <002701d665ba$c6262780$52727680$@SGA.Ninja> I guess that some things are just too simple to document. I searched man-a-site to find this but failed. open( "file.in" ) Works exactly as I want. Thanks. =================================== Footnote: "What rhymes with orange?" "No it doesn't.." -----Original Message----- From: Python-list On Behalf Of DL Neil via Python-list Sent: Tuesday, July 28, 2020 6:15 PM To: python-list at python.org Subject: Re: Local access to a file, How To ? On 29/07/2020 08:56, Steve wrote: > I have a python program that reads and writes to files that are all > within the folder that contains the python program. There is now a > second python program that is to be run to compile information in said files. > > I am having difficulty trying to call the local supporting program > from within the main program. I would it would found easily because > everything is all in the same folder. Apparently, I have to decipher > paths to do the task. > > One problem is that the project is portable on a thumb drive and the > path can change based on the computer on which the program is > executed. I look up use of path and I seem to get all absolute path > instruction and not relative. > > Where an I steering wrongly here. Questions: - is the second program kept in the same directory as the first, or somewhere else? - by "call" do you mean "import", or... If the program and the data files are in the same directory, then you will have noticed that there is no need for absolute addressing, ie open( "file.in" ) not open( "/home/me/Projets/this/file.in" ) The same applies to import-s. From program_A we can import program_B in the same directory. No need for absolute paths, anywhere! That is to say, Python works happily with the concept of the "current working directory", and when no absolute-path is provided assumes 'this directory' - or if a non-absolute-path is provided (doesn't commence with "/", in the case of Posix) prefixes the path from 'this directory'. Yes, there are many caveats beyond such a simple explanation, but that should be enough to get-going. Keeping 'everything' in the single directory, and always executing from there, should enable migration. -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list From david at lowryduda.com Wed Jul 29 13:47:53 2020 From: david at lowryduda.com (David Lowry-Duda) Date: Wed, 29 Jul 2020 13:47:53 -0400 Subject: How to diagnose import error when importing from .so file? In-Reply-To: References: Message-ID: <20200729174753.GA13962@icerm-dld> > pyscand is a .so file so I fear I may be a bit stuffed unless I can > find the source code for it. > ... > In fact looking for this error it seems that is is a Python version > mismatch error and I need to recompile pyscand.so against Python 3. Is > there no way to sort of convert it to Python 3 without having the > source? Unfortunately, you'll need to recompile the .so file (or replace the dependency). Good luck! - DLD -- David Lowry-Duda From pascor22234 at gmail.com Wed Jul 29 14:46:04 2020 From: pascor22234 at gmail.com (R Pasco) Date: Wed, 29 Jul 2020 14:46:04 -0400 Subject: Winreg Message-ID: I'm running python 3.8 on Windows 8.1 x64. Running the following code produces no errors but does not add a key, name or value. I had no problems doing this using _wirreg under python 2.7. Any insight will be helpful. Code: =================== import winreg hive = winreg.HKEY_LOCAL_MACHINE keypath = 'SOFTWARE\\AAA_Newkey' host = None hosthive = winreg.ConnectRegistry( host, hive ) key = winreg.CreateKeyEx( hosthive, keypath, reserved=0, access=winreg.KEY_WRITE) winreg.SetValueEx( key, 'NewValueName', 0, winreg.REG_SZ, 'NewStringValue' ) key.Close() =================== From ekopalypse at gmail.com Wed Jul 29 15:32:19 2020 From: ekopalypse at gmail.com (Eko palypse) Date: Wed, 29 Jul 2020 21:32:19 +0200 Subject: Windows and Subclassing - 'OverflowError': int too long to convert In-Reply-To: References: Message-ID: Hello Eryk, thank you for your interest in my problem and you've nailed it, the problem was solved by putting all Windows API definitions in a separate module and making sure that I only use WinDLL. I would never have thought of that, because I only used WinDLL in this module. But a PostMessage in another module, which I created with windll, seems to have confused things a bit and now that I have merged this and other modules into one, I don't see the problem anymore. Here is the desired excerpt. (user32 is now import from win32api, where all other definitions are now also) def new_scintilla2_proc(self, hWnd, msg, wParam, lParam): if self.__WndProc(hWnd, msg, wParam, lParam): return 0 print(f'{hWnd=}, {msg=}, {wParam=}, {lParam=}') return user32.CallWindowProcW(self.prev_scintilla2_wnd_proc, hWnd, msg, wParam, lParam) def __WndProc(self, hWnd, msg, wParam, lParam): event_handler = self._event_handler.get(msg, None) if event_handler: return event_handler(msg, wParam, lParam) return False Once again, thank you Eren Am Mi., 29. Juli 2020 um 16:26 Uhr schrieb Eryk Sun : > On 7/28/20, Eko palypse wrote: > > > > Now when I get this error the message I receive in this situation is > always > > like this. > > > > hWnd=197364, msg=20, wParam=*18446744072652653190*, lParam=0 > > > > Traceback (most recent call last): > > File "_ctypes/callbacks.c", line 237, in 'calling callback function' > > File "", line 121, in new_scintilla2_proc > > ctypes.ArgumentError: argument 4: : int too long > to > > convert > > Can you provide a more complete example of how you're calling > CallWindowProcW in new_scintilla2_proc? It seems like a function > pointer is being called that doesn't have argtypes defined. For > example: > > >>> user32 = ctypes.WinDLL('user32', use_last_error=True) > >>> user32.CallWindowProcW(None, None, 0x14, 18446744072652653190, 0) > Traceback (most recent call last): > File "", line 1, in > ctypes.ArgumentError: argument 4: : int too > long to convert > > Perhaps in new_scintilla2_proc you're using a different instance of > ctypes.WinDLL, or you switched to using ctypes.windll.user32. I > recommend avoiding the global ctypes.LibraryLoader instances -- > ctypes.cdll, ctypes.windll, and ctypes.oledll -- because using them > leads to conflicts with other libraries, but you do need to use a > single instance of ctypes.WinDLL for your user32 function prototypes, > imported from a common module. > From christian at python.org Wed Jul 29 16:24:15 2020 From: christian at python.org (Christian Heimes) Date: Wed, 29 Jul 2020 22:24:15 +0200 Subject: How to diagnose import error when importing from .so file? In-Reply-To: References: Message-ID: On 29/07/2020 15.34, Chris Green wrote: > I have some Python Gtk 2 code I'm trying to convert to Python > pygobject GTK 3. > > However I'm stuck on an import statement that fails:- > > import pyscand > > > The error message is:- > > File "/usr/libexec/okimfputl.new/guicom.py", line 66, in > import pyscand > ImportError: /usr/libexec/okimfpdrv/pyscand.so: undefined symbol: _Py_ZeroStruct > > pyscand is a .so file so I fear I may be a bit stuffed unless I can > find the source code for it. However any other ideas would be most > welcome. > > In fact looking for this error it seems that is is a Python version > mismatch error and I need to recompile pyscand.so against Python 3. Is > there no way to sort of convert it to Python 3 without having the > source? You are right. The extension module is compiled for Python 2. _Py_ZeroStruct is only available in Python 2. You need the C code for the extension module. and possibly even modify the C code to make the extension work with Python 3. Christian From cl at isbd.net Wed Jul 29 17:01:15 2020 From: cl at isbd.net (Chris Green) Date: Wed, 29 Jul 2020 22:01:15 +0100 Subject: How to diagnose import error when importing from .so file? References: Message-ID: Christian Heimes wrote: > On 29/07/2020 15.34, Chris Green wrote: > > I have some Python Gtk 2 code I'm trying to convert to Python > > pygobject GTK 3. > > > > However I'm stuck on an import statement that fails:- > > > > import pyscand > > > > > > The error message is:- > > > > File "/usr/libexec/okimfputl.new/guicom.py", line 66, in > > import pyscand > > ImportError: /usr/libexec/okimfpdrv/pyscand.so: undefined symbol: _Py_ZeroStruct > > > > pyscand is a .so file so I fear I may be a bit stuffed unless I can > > find the source code for it. However any other ideas would be most > > welcome. > > > > In fact looking for this error it seems that is is a Python version > > mismatch error and I need to recompile pyscand.so against Python 3. Is > > there no way to sort of convert it to Python 3 without having the > > source? > > You are right. The extension module is compiled for Python 2. > _Py_ZeroStruct is only available in Python 2. You need the C code for > the extension module. and possibly even modify the C code to make the > extension work with Python 3. > Thanks for confirming, though it's not good news really as the chances of getting the C code to recompile pyscand.so are minimal. It's a piece of code provided by OKI and I don't really think I'll be able to get the code out of them. Even more annoying is that most of what's in pyscand.so is constants, there's only a couple of functions in there, so there's very little to it really. -- Chris Green ? From barry at barrys-emacs.org Wed Jul 29 17:12:52 2020 From: barry at barrys-emacs.org (Barry) Date: Wed, 29 Jul 2020 22:12:52 +0100 Subject: Winreg In-Reply-To: References: Message-ID: <3A1D83AB-3BF6-4951-AD13-3DF2C1FE1867@barrys-emacs.org> > On 29 Jul 2020, at 19:50, R Pasco wrote: > > ?I'm running python 3.8 on Windows 8.1 x64. Running the following code > produces no errors but does not add a key, name or value. I had no problems > doing this using _wirreg under python 2.7. Any insight will be helpful. How do you check that the key is present? Are you aware that there is one registry for 32 bit code and a separate registry for 64 bit code. if you run a 32 bit program to write the registry it will not be seen by 64 bit code for example. Barry > > Code: > =================== > import winreg > > hive = winreg.HKEY_LOCAL_MACHINE > keypath = 'SOFTWARE\\AAA_Newkey' > host = None > hosthive = winreg.ConnectRegistry( host, hive ) > key = winreg.CreateKeyEx( hosthive, keypath, reserved=0, > access=winreg.KEY_WRITE) > winreg.SetValueEx( key, 'NewValueName', 0, winreg.REG_SZ, 'NewStringValue' ) > key.Close() > =================== > -- > https://mail.python.org/mailman/listinfo/python-list > From jkexcel at comcast.net Wed Jul 29 17:18:56 2020 From: jkexcel at comcast.net (nhpython) Date: Wed, 29 Jul 2020 17:18:56 -0400 (EDT) Subject: why is requests 2.24 behaving differently on different Win10Pro PCs? Message-ID: <478791727.5298.1596057536489@connect.xfinity.com> python 3.6+ requests 2.24 2- windows 10 Pro version 2004, build 19041.388 1- kubuntu 18.04 1-suse leap 15.2 Questions 1. how do I begin to diagnose the source of the problem? 2. Has anyone experienced this behavior? I have 4 PCs running the same code. On 3 they work, but 1 fails. I have 2 win10Pros running the same code on the same network on the same subnet, which uses "requests.get()" 1 PC works fine; the code executes perfectly, but the other FAILS. (statusCode = 200, but the website doesn't send webpage) The error response from the website: We've detected unusual activity from your computer network To continue, please click the box below to let us know you're not a robot. Why did this happen? Please make sure your browser supports JavaScript and cookies and that you are not blocking them from loading. For more information you can review our Terms of Service and Cookie Policy. BTW, I tried reverting back to "urllib.request" and the same problem appears. 1 PC works the other fails. I even tried "HTMLsession" which renders javascript. Same problem. From cl at isbd.net Thu Jul 30 06:09:41 2020 From: cl at isbd.net (Chris Green) Date: Thu, 30 Jul 2020 11:09:41 +0100 Subject: What's the enum for a button press event in pygobject 3? Message-ID: <5siavg-5kl5.ln1@esprimo.zbmc.eu> I am going round and round in steadily increasing frustration trying to find the constants for button events in Pygobject/Gtk 3. I have the following imports:- import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import Gdk The old GTK 2 code had (I think):- if (event.type == gtk.gdk.BUTTON_PRESS): So what is BUTTON_PRESS in the new version, I simply can't find a straightforward description of it or example of its use. -- Chris Green ? From cl at isbd.net Thu Jul 30 07:13:28 2020 From: cl at isbd.net (Chris Green) Date: Thu, 30 Jul 2020 12:13:28 +0100 Subject: How to find code that causes a 'deprecated' warning? Message-ID: I am getting the following warning from a program I have just converted from gtk 2 to gtk 3 :- (abook:58240): Gtk-WARNING **: 12:01:58.064: Theme parsing error: gtk.css:66:28: The :prelight pseudo-class is deprecated. Use :hover instead. How do I find what is causing the warning? I'm not using the prelight pseudo-class directly in my code anywhere. -- Chris Green ? From __peter__ at web.de Thu Jul 30 10:14:59 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Jul 2020 16:14:59 +0200 Subject: How to find code that causes a 'deprecated' warning? References: Message-ID: Chris Green wrote: > I am getting the following warning from a program I have just > converted from gtk 2 to gtk 3 :- > > (abook:58240): Gtk-WARNING **: 12:01:58.064: Theme parsing error: > gtk.css:66:28: The :prelight pseudo-class is deprecated. Use :hover > instead. > > How do I find what is causing the warning? I'm not using the prelight > pseudo-class directly in my code anywhere. >From reading the message I would guess that the culprit is the file gtk.css, line 66 specifically ;) From sarvesh.poddar at yahoo.com Thu Jul 30 04:40:17 2020 From: sarvesh.poddar at yahoo.com (Sarvesh Poddar) Date: Thu, 30 Jul 2020 08:40:17 +0000 (UTC) Subject: Issue with Python installation for a beginner Python coder. References: <1876847237.7706738.1596098417334.ref@mail.yahoo.com> Message-ID: <1876847237.7706738.1596098417334@mail.yahoo.com> Hi, I re-installed Python in my Windows system as the earlier one was not able to import modules. But now I am not able to open IDLE after multiple tries.? Can you guys help me? I am a beginner?and tried out a lot of solutions provided on the internet and it's just not getting fixed. Please help. I look forward to it.? PS : Falling in love with Python, slow and steady!? From auriocus at gmx.de Thu Jul 30 10:34:50 2020 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 30 Jul 2020 16:34:50 +0200 Subject: How to diagnose import error when importing from .so file? In-Reply-To: References: Message-ID: Am 29.07.20 um 23:01 schrieb Chris Green: > Even more annoying is that most of what's in pyscand.so is constants, > there's only a couple of functions in there, so there's very little to > it really. > If there are really only constants, you could import it into Python 2 and dump the content e.g. as a JSON file to read it in under Python 3. Christian From o1bigtenor at gmail.com Thu Jul 30 10:52:43 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Thu, 30 Jul 2020 09:52:43 -0500 Subject: questions re: calendar module Message-ID: Greetings I regularly work in planning through multiple years at once. This means that I like to have a lot of stuff available in a calendar function. Python seems to be locked when I need to display more than 1 year at a time. I don't see a way to display something like 3 years worth of calendar starting at a point 23 months from now. (I see how to display 1 year at a time but not multiple years.) Is there a way to do this? TIA From python at mrabarnett.plus.com Thu Jul 30 10:50:40 2020 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 30 Jul 2020 15:50:40 +0100 Subject: What's the enum for a button press event in pygobject 3? In-Reply-To: <5siavg-5kl5.ln1@esprimo.zbmc.eu> References: <5siavg-5kl5.ln1@esprimo.zbmc.eu> Message-ID: <8ef900d9-6d8d-ec95-b749-89dbc604c94a@mrabarnett.plus.com> On 2020-07-30 11:09, Chris Green wrote: > I am going round and round in steadily increasing frustration trying > to find the constants for button events in Pygobject/Gtk 3. > > I have the following imports:- > > import gi > gi.require_version('Gtk', '3.0') > from gi.repository import Gtk > from gi.repository import Gdk > > > The old GTK 2 code had (I think):- > > if (event.type == gtk.gdk.BUTTON_PRESS): > > > So what is BUTTON_PRESS in the new version, I simply can't find a > straightforward description of it or example of its use. > > I believe it's: Gdk.EventType.BUTTON_PRESS There's documentation here: https://lazka.github.io/pgi-docs/#Gdk-3.0/enums.html#Gdk.EventType.BUTTON_PRESS From sh at changeset.nyc Thu Jul 30 10:58:26 2020 From: sh at changeset.nyc (Sumana Harihareswara) Date: Thu, 30 Jul 2020 10:58:26 -0400 Subject: pip 20.2 release, plus changes coming in 20.3 Message-ID: <3dc20496-47de-436f-9328-4699bfcdeaca@changeset.nyc> On behalf of the Python Packaging Authority, I am pleased to announce that we have just released pip 20.2, a new version of pip. You can install it by running python -m pip install --upgrade pip. The highlights for this release are: - The beta of the next-generation dependency resolver is available - Faster installations from wheel files - Improved handling of wheels containing non-ASCII file contents - Faster `pip list` using parallelized network operations - Installed packages now contain metadata about whether they were directly requested by the user (PEP 376?s REQUESTED file) The new dependency resolver is *off by default* because it is *not yet ready for everyday use*. The new dependency resolver is significantly stricter and more consistent when it receives incompatible instructions, and reduces support for certain kinds of constraints files, so some workarounds and workflows may break. Please test it with the `--use-feature=2020-resolver` flag. Please see our guide on how to test and migrate, and how to report issues . We are preparing to change the default dependency resolution behavior and make the new resolver the default in pip 20.3 (in October 2020). This release also partially optimizes pip?s network usage during installation (as part of a Google Summer of Code project by McSinyx ). Please test it with `pip install --use-feature=2020-resolver --use-feature=fast-deps` and report bugs to the issue tracker . This functionality is *still experimental* and *not ready for everyday use*. You can find more details (including deprecations and removals) in the changelog . As with all pip releases, a significant amount of the work was contributed by pip?s user community. Huge thanks to all who have contributed, whether through code, documentation, issue reports and/or discussion. Your help keeps pip improving, and is hugely appreciated. Specific thanks go to Mozilla (through its Mozilla Open Source Support Awards) and to the Chan Zuckerberg Initiative DAF, an advised fund of Silicon Valley Community Foundation, for their funding that enabled substantial work on the new resolver. -- Sumana Harihareswara pip project manager via contract with PSF Changeset Consulting https://changeset.nyc From cl at isbd.net Thu Jul 30 11:52:42 2020 From: cl at isbd.net (Chris Green) Date: Thu, 30 Jul 2020 16:52:42 +0100 Subject: How to find code that causes a 'deprecated' warning? References: Message-ID: Peter Otten <__peter__ at web.de> wrote: > Chris Green wrote: > > > I am getting the following warning from a program I have just > > converted from gtk 2 to gtk 3 :- > > > > (abook:58240): Gtk-WARNING **: 12:01:58.064: Theme parsing error: > > gtk.css:66:28: The :prelight pseudo-class is deprecated. Use :hover > > instead. > > > > How do I find what is causing the warning? I'm not using the prelight > > pseudo-class directly in my code anywhere. > > >From reading the message I would guess that the culprit is the file gtk.css, > line 66 specifically ;) > Oops, yes! :-) I guess that came with the [x]ubuntu installation, it's in ~/.config/gtk-3.0/gtk.css so I deny any responsibility for it! -- Chris Green ? From cl at isbd.net Thu Jul 30 11:50:17 2020 From: cl at isbd.net (Chris Green) Date: Thu, 30 Jul 2020 16:50:17 +0100 Subject: What's the enum for a button press event in pygobject 3? References: <5siavg-5kl5.ln1@esprimo.zbmc.eu> <8ef900d9-6d8d-ec95-b749-89dbc604c94a@mrabarnett.plus.com> Message-ID: MRAB wrote: > On 2020-07-30 11:09, Chris Green wrote: > > I am going round and round in steadily increasing frustration trying > > to find the constants for button events in Pygobject/Gtk 3. > > > > I have the following imports:- > > > > import gi > > gi.require_version('Gtk', '3.0') > > from gi.repository import Gtk > > from gi.repository import Gdk > > > > > > The old GTK 2 code had (I think):- > > > > if (event.type == gtk.gdk.BUTTON_PRESS): > > > > > > So what is BUTTON_PRESS in the new version, I simply can't find a > > straightforward description of it or example of its use. > > > > > I believe it's: > > Gdk.EventType.BUTTON_PRESS > > There's documentation here: > > https://lazka.github.io/pgi-docs/#Gdk-3.0/enums.html#Gdk.EventType.BUTTON_PRESS Brilliant, thank you, just what I needed. -- Chris Green ? From barry at barrys-emacs.org Thu Jul 30 11:56:40 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 30 Jul 2020 16:56:40 +0100 Subject: Winreg In-Reply-To: References: <3A1D83AB-3BF6-4951-AD13-3DF2C1FE1867@barrys-emacs.org> Message-ID: <6ED4E685-E94C-4858-9A07-271723FD5878@barrys-emacs.org> You left python list off your reply. > On 29 Jul 2020, at 23:38, R Pasco wrote: > > Hi, Barry, > > On Wed, Jul 29, 2020 at 5:12 PM Barry > wrote: > > > On 29 Jul 2020, at 19:50, R Pasco > wrote: > > > > ?I'm running python 3.8 on Windows 8.1 x64. Running the following code > > produces no errors but does not add a key, name or value. I had no problems > > doing this using _wirreg under python 2.7. Any insight will be helpful. > > How do you check that the key is present? > > I'm using regedit.exe to try to view it. > > Are you aware that there is one registry for 32 bit code and a separate registry for 64 bit code. > > Only vaguely. Are the "separate" registries really 64 and 32 views of the one and only Registry ? That is, using Winreg ? > Some examples use "winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_32KEY" as the access mode. Not sure what this does. > I am using python 64-bit, so what should the argument value "access=" be set to in the call to "winreg.CreateKeyEx()" ? Yes they are views. I cannot remember the details, but I suggest that you look up the details on microsoft's MSDN for the info you need. Searching for KEY_WOW64_32KEY takes you into thoses docs for example. Barrry From cl at isbd.net Thu Jul 30 12:23:32 2020 From: cl at isbd.net (Chris Green) Date: Thu, 30 Jul 2020 17:23:32 +0100 Subject: Gtk.TextBuffer problem on converting from GTK+ 2 to GTK+ 3 Message-ID: <4p8bvg-5617.ln1@esprimo.zbmc.eu> I'm converting a program from Python 2 gtk+ 2 to Python 3 and gtk+ 3. It's mostly gone reasonably smoothly but I can't get multi-line text entry to work. The class that provides text entry (both single and multi-line) is:- # # # Field on the GUI # class guiField: widget = None lines = 1 # # # Initialise the field # def __init__(self, lines=1): self.lines = lines if (self.lines > 1): self.buffer = Gtk.TextBuffer() self.view = Gtk.TextView() self.view.set_size_request(-1, 24 * lines) self.view.set_accepts_tab(False) # self.widget = self.view self.widget = Gtk.ScrolledWindow() self.widget.add(self.view) self.widget.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.widget.set_shadow_type(Gtk.ShadowType.ETCHED_IN) else: self.widget = Gtk.Entry() # # # get text from field # def get_text(self): if (self.lines > 1): [start, end] = self.buffer.get_bounds() print(self.buffer.get_text(start, end, False)) return self.buffer.get_text(start, end, False) else: return self.widget.get_text() # # # put text into a field # def set_text(self, text): if (self.lines > 1): self.buffer.set_text(text) else: self.widget.set_text(text) The single line Gtk.Entry widgets work fine, text gets loaded, I can change it and save it. The multi-line Gtk.TextBuffer ones refuse to work at all, no errors or anything but text won't load into them or save out of them. They used to work fine in gtk+ 2. Text loaded into the Gtk.TextBuffer using set_text() doesn't appear, the text boxes are empty even though the 'text' parameter does have a string in it (I've checked with a print()). I can enter text using the keyboard but that text isn't retrieved by the get_text() method. What am I doing wrong? Virtually nothing has changed in this part of my code between gtk+ 2 and gtk+ 3, just the import and gtk to Gtk and a couple of enum formats. -- Chris Green ? From python at mrabarnett.plus.com Thu Jul 30 12:58:40 2020 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 30 Jul 2020 17:58:40 +0100 Subject: Gtk.TextBuffer problem on converting from GTK+ 2 to GTK+ 3 In-Reply-To: <4p8bvg-5617.ln1@esprimo.zbmc.eu> References: <4p8bvg-5617.ln1@esprimo.zbmc.eu> Message-ID: On 2020-07-30 17:23, Chris Green wrote: > I'm converting a program from Python 2 gtk+ 2 to Python 3 and gtk+ 3. > It's mostly gone reasonably smoothly but I can't get multi-line text > entry to work. > > The class that provides text entry (both single and multi-line) is:- > > # > # > # Field on the GUI > # > class guiField: > widget = None > lines = 1 > # > # > # Initialise the field > # > def __init__(self, lines=1): > self.lines = lines > if (self.lines > 1): > self.buffer = Gtk.TextBuffer() > self.view = Gtk.TextView() > self.view.set_size_request(-1, 24 * lines) > self.view.set_accepts_tab(False) > # self.widget = self.view > self.widget = Gtk.ScrolledWindow() > self.widget.add(self.view) > self.widget.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) > self.widget.set_shadow_type(Gtk.ShadowType.ETCHED_IN) > else: > self.widget = Gtk.Entry() > # > # > # get text from field > # > def get_text(self): > if (self.lines > 1): > [start, end] = self.buffer.get_bounds() > print(self.buffer.get_text(start, end, False)) > return self.buffer.get_text(start, end, False) > else: > return self.widget.get_text() > # > # > # put text into a field > # > def set_text(self, text): > if (self.lines > 1): > self.buffer.set_text(text) > else: > self.widget.set_text(text) > > > The single line Gtk.Entry widgets work fine, text gets loaded, I can > change it and save it. > > The multi-line Gtk.TextBuffer ones refuse to work at all, no errors or > anything but text won't load into them or save out of them. They used > to work fine in gtk+ 2. > > Text loaded into the Gtk.TextBuffer using set_text() doesn't appear, > the text boxes are empty even though the 'text' parameter does have a > string in it (I've checked with a print()). I can enter text using > the keyboard but that text isn't retrieved by the get_text() method. > > What am I doing wrong? Virtually nothing has changed in this part of > my code between gtk+ 2 and gtk+ 3, just the import and gtk to Gtk and > a couple of enum formats. > You're creating a TextBuffer and a TextView, but I don't see any code that ties them together. How would the view know to display the contents of the buffer? From barry at barrys-emacs.org Thu Jul 30 12:48:37 2020 From: barry at barrys-emacs.org (Barry) Date: Thu, 30 Jul 2020 17:48:37 +0100 Subject: why is requests 2.24 behaving differently on different Win10Pro PCs? In-Reply-To: <478791727.5298.1596057536489@connect.xfinity.com> References: <478791727.5298.1596057536489@connect.xfinity.com> Message-ID: > On 29 Jul 2020, at 23:06, nhpython wrote: > > ?python 3.6+ > requests 2.24 > 2- windows 10 Pro version 2004, build 19041.388 > 1- kubuntu 18.04 > 1-suse leap 15.2 > > Questions > 1. how do I begin to diagnose the source of the problem? > 2. Has anyone experienced this behavior? > > > I have 4 PCs running the same code. On 3 they work, but 1 fails. > > I have 2 win10Pros running the same code on the same network on the same subnet, which uses "requests.get()" 1 PC works fine; the code executes perfectly, but the other FAILS. (statusCode = 200, but the website doesn't send webpage) > > The error response from the website: > > We've detected unusual activity from your computer network > To continue, please click the box below to let us know you're not a robot. > Why did this happen? > Please make sure your browser supports JavaScript and cookies and that you are not blocking them from loading. For more information you can review our Terms of Service and Cookie Policy. > > BTW, I tried reverting back to "urllib.request" and the same problem appears. 1 PC works the other fails. > I even tried "HTMLsession" which renders javascript. Same problem. > Sounds like the service you are accessing has a rate limit or other form of defence. And your requests are triggering the defences. What happens if you browse to the site? Barry > > > -- > https://mail.python.org/mailman/listinfo/python-list > From pascor22234 at gmail.com Thu Jul 30 15:14:12 2020 From: pascor22234 at gmail.com (R Pasco) Date: Thu, 30 Jul 2020 15:14:12 -0400 Subject: Winreg Message-ID: I can't find instructions for the proper way to reply to 'python list'. Is it simply a matter of keeping the message title identical to the original message and emailing again to python-list at python.org ? I'll reply both ways to test this. Yes, it's the 64/32-bit views that got me stuck. I think I've got it mostly figured out. The key HKEY_LOCAL_MACHINE:SOFTWARE requires KEY_WOW64_64KEY to be 'OR'ed. Winreg gives no indication of this requirement, but the Windows doc "Redirected, Shared, and Reflected Keys Under WOW64" does specifically mention HKEY_CURRENT_USER :SOFTWARE as needing this added access. By the way, I'm running python X64, so the program is a "64 bit" application. Strangely, the KEY_WOW64_32KEY access rights param also works identically. To sum it up the pertinent code, so far, is: ====================================== # Be able to test creating both WOW64 and non-WOW64 key paths. if 1 : hive = winreg.HKEY_LOCAL_MACHINE hivename = 'HKEY_LOCAL_MACHINE' else : hive = winreg.HKEY_CURRENT_USER hivename = 'HKEY_CURRENT_USER' # parent_keypath = 'Software' # Both hives happen to have this top level key. newsubkey = 'AAA New Leaf Key, Process PID={}' .format( os.getpid() ) # Note keys created in HKEY_LOCAL_MACHINE::SOFTWARE will be viewed in RegEdit # at HKEY_LOCAL_MACHINE:SOFTWARE\*Wow6432Node*\{newsubkey}. CreateKeyEx # access rights must be set to [winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY] # -OR- # [winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_32KEY] (??? Why does this also work ?) # newsubkeyPath = os.path.join( parent_keypath, newsubkey ) valuename = 'NewString' value = 'New String Value' with winreg.ConnectRegistry( None, hive ) as hivehndl : with winreg.OpenKeyEx( hivehndl, parent_keypath ) as parentpath_hndl : with winreg.CreateKeyEx( parentpath_hndl, newsubkey, 0, # winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY ) as newkeyhndl : winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_32KEY ) as newkeyhndl : winreg.SetValueEx( newkeyhndl, valuename, 0, winreg.REG_SZ, value ) #end ====================================== Thanks for all the help. Ray Pasco From Marco.Sulla.Python at gmail.com Thu Jul 30 15:15:13 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Thu, 30 Jul 2020 21:15:13 +0200 Subject: Non IDE development strategy - what do others do that's fairly simple? In-Reply-To: References: Message-ID: What you want is a branch, I guess. https://www.mercurial-scm.org/wiki/Branch For simplicity, I suggest you have two different directories: one for the development branch and the other for the production branch. From barry at barrys-emacs.org Thu Jul 30 15:25:49 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 30 Jul 2020 20:25:49 +0100 Subject: Winreg In-Reply-To: References: Message-ID: <08960523-FFB7-4441-9112-D400C2207D53@barrys-emacs.org> Use the Reply or Reply-To-All feature of your email program and it will do the rest for you. Barry > On 30 Jul 2020, at 20:14, R Pasco wrote: > > I can't find instructions for the proper way to reply to 'python list'. Is > it simply a matter of keeping the message title identical to the original > message and emailing again to python-list at python.org ? I'll reply both ways > to test this. > > Yes, it's the 64/32-bit views that got me stuck. I think I've got it mostly > figured out. The key HKEY_LOCAL_MACHINE:SOFTWARE requires KEY_WOW64_64KEY > to be 'OR'ed. Winreg gives no indication of this requirement, but the > Windows doc "Redirected, Shared, and Reflected Keys Under WOW64" does > specifically mention HKEY_CURRENT_USER :SOFTWARE as needing this added > access. > > By the way, I'm running python X64, so the program is a "64 bit" > application. Strangely, the KEY_WOW64_32KEY access rights param also works > identically. > > To sum it up the pertinent code, so far, is: > ====================================== > # Be able to test creating both WOW64 and non-WOW64 key paths. > if 1 : > hive = winreg.HKEY_LOCAL_MACHINE > hivename = 'HKEY_LOCAL_MACHINE' > else : > hive = winreg.HKEY_CURRENT_USER > hivename = 'HKEY_CURRENT_USER' > # > parent_keypath = 'Software' # Both hives happen to have this top > level key. > newsubkey = 'AAA New Leaf Key, Process PID={}' .format( os.getpid() ) > > # Note keys created in HKEY_LOCAL_MACHINE::SOFTWARE will be viewed in > RegEdit > # at HKEY_LOCAL_MACHINE:SOFTWARE\*Wow6432Node*\{newsubkey}. > CreateKeyEx > # access rights must be set to [winreg.KEY_ALL_ACCESS | > winreg.KEY_WOW64_64KEY] > # -OR- > # [winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_32KEY] (??? Why does this > also work ?) > # > newsubkeyPath = os.path.join( parent_keypath, newsubkey ) > > valuename = 'NewString' > value = 'New String Value' > > with winreg.ConnectRegistry( None, hive ) as hivehndl : > > with winreg.OpenKeyEx( hivehndl, parent_keypath ) as > parentpath_hndl : > > with winreg.CreateKeyEx( parentpath_hndl, newsubkey, 0, > # winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY ) as > newkeyhndl : > winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_32KEY ) as > newkeyhndl : > > winreg.SetValueEx( newkeyhndl, valuename, 0, winreg.REG_SZ, > value ) > > #end > ====================================== > > Thanks for all the help. > Ray Pasco > -- > https://mail.python.org/mailman/listinfo/python-list > From cl at isbd.net Thu Jul 30 16:08:51 2020 From: cl at isbd.net (Chris Green) Date: Thu, 30 Jul 2020 21:08:51 +0100 Subject: Gtk.TextBuffer problem on converting from GTK+ 2 to GTK+ 3 References: <4p8bvg-5617.ln1@esprimo.zbmc.eu> Message-ID: MRAB wrote: > > > > What am I doing wrong? Virtually nothing has changed in this part of > > my code between gtk+ 2 and gtk+ 3, just the import and gtk to Gtk and > > a couple of enum formats. > > > You're creating a TextBuffer and a TextView, but I don't see any code > that ties them together. How would the view know to display the contents > of the buffer? Absolutely right, thank you. I should have spotted that. I think the Gtk.TextView contructor used to take a buffer parameter but the version 3 one doesn't so I had removed it. Hence, as you say, no code tying them together. I've simply changed to:- self.view = Gtk.TextView.new_with_buffer(self.buffer) ... and all is well again. -- Chris Green ? From PythonList at DancesWithMice.info Thu Jul 30 17:33:47 2020 From: PythonList at DancesWithMice.info (dn) Date: Fri, 31 Jul 2020 09:33:47 +1200 Subject: Winreg In-Reply-To: <08960523-FFB7-4441-9112-D400C2207D53@barrys-emacs.org> References: <08960523-FFB7-4441-9112-D400C2207D53@barrys-emacs.org> Message-ID: <48467bc6-dc51-15d5-88fb-8f8875b5ca52@DancesWithMice.info> On 31/07/2020 07:25, Barry Scott wrote: > Use the Reply or Reply-To-All feature of your email program and it will do the rest for you. >> I can't find instructions for the proper way to reply to 'python list'. Is >> it simply a matter of keeping the message title identical to the original >> message and emailing again to python-list at python.org ? I'll reply both ways >> to test this. Be aware, using "Reply" (only) in at least some email-clients/webmail-apps will result in the reply going only to the previous-sender cf to the list. -- Regards =dn From cs at cskk.id.au Thu Jul 30 23:19:46 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 31 Jul 2020 13:19:46 +1000 Subject: replying to the mailing list (was: Winreg) In-Reply-To: <08960523-FFB7-4441-9112-D400C2207D53@barrys-emacs.org> References: <08960523-FFB7-4441-9112-D400C2207D53@barrys-emacs.org> Message-ID: <20200731031946.GA80328@cskk.homeip.net> On 30Jul2020 20:25, Barry Scott wrote: >Use the Reply or Reply-To-All feature of your email program and it will do the rest for you. Plain "reply" is often only "reply-to-author" for many mailers. I use "reply-to-all" myself, and edit the headers if that seems excessive. Some mailers (eg mutt) also have a "list-reply" operation, which should also be correct, arguably more correct. >> On 30 Jul 2020, at 20:14, R Pasco wrote: >> I can't find instructions for the proper way to reply to 'python >> list'. Is >> it simply a matter of keeping the message title identical to the original >> message and emailing again to python-list at python.org ? I'll reply both ways >> to test this. Using the same subject is _not_ enough. Messages are connected together with the "In-Reply-To:" header, which is automatically set by your mailer's "reply" function (regardless of the flavour mentioned above). So please just reply to the relevant list message, and make sure the list address (python-list at python.org) is in the resulting to/cc. Cheers, Cameron Simpson From eryksun at gmail.com Thu Jul 30 23:53:56 2020 From: eryksun at gmail.com (Eryk Sun) Date: Thu, 30 Jul 2020 22:53:56 -0500 Subject: Winreg In-Reply-To: References: Message-ID: On 7/30/20, R Pasco wrote: > access rights must be set to [winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY It's a bad practice to request more access than you require, at the very least because the request may fail with access denied for no good reason. KEY_ALL_ACCESS includes all applicable standard rights (WRITE_OWNER, WRITE_DAC, READ_CONTROL, DELETE) and all key rights (KEY_QUERY_VALUE, KEY_SET_VALUE, KEY_CREATE_SUB_KEY, KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, KEY_CREATE_LINK). For an existing key, do you need to change the owner, read and modify the security, delete the key, set a symlink, etc? It looks like you just need to set a value, i.e. KEY_SET_VALUE. > winreg.KEY_WOW64_32KEY] (??? Why does this also work ?) By default a 64-bit process doesn't see redirected keys, but if you need to access them, use KEY_WOW64_32KEY in the desired access. Normally a 32-bit process under WOW64 sees redirected keys, and if you need to access the non-redirected keys, use KEY_WOW64_64KEY. Note that KEY_WOW64_64KEY and KEY_WOW64_32KEY access modes only affect runtime redirection. As with the standard MAXIMUM_ALLOWED access mode, they're not assignable rights that can be granted or denied in a key object's access control list. > with winreg.ConnectRegistry( None, hive ) as hivehndl There is no need to call ConnectRegistry here. By default, predefined handles are resolved to local key handles. Also, if you actually need to access a remote machine, note that it's nonsensical to try to connect to HKEY_CURRENT_USER. The API allows it, but why would one assume that the remote machine will have a profile for the current user's SID? The remote system will most likely just connect to a handle for the default user profile. > The key HKEY_LOCAL_MACHINE:SOFTWARE requires KEY_WOW64_64KEY > to be 'OR'ed. Winreg gives no indication of this requirement, but the > Windows doc "Redirected, Shared, and Reflected Keys Under WOW64" does > specifically mention HKEY_CURRENT_USER :SOFTWARE as needing this added > access. At the machine level, the software hive is stored on disk at "%SystemRoot%\System32\config\SOFTWARE" and mounted at "\REGISTRY\MACHINE\SOFTWARE". For a WOW64 process, by default there is extensive runtime redirection of keys in this hive to the subkeys "WOW6432Node" and "Classes\WOW6432Node". At the user level, there are two hives mounted. The user profile is stored on disk at "%USERPROFILE%\NTUSER.DAT" and mounted at "\REGISTRY\USER\", where "" is the string form of the user's security identifier (e.g. "S-1-5-21----"). For a WOW64 process, there is no redirection of subkeys that are physically stored in this hive. The user's software classes hive is stored on disk at "%LOCALAPPDATA%\Microsoft\Windows\UsrClass.dat" and mounted at "\REGISTRY\USER\_Classes". In the user profile, the "Software\Classes" key is a symbolic link to the latter. For a WOW64 process, some subkeys in the classes hive are redirected to subkeys in "WOW6432Node" (i.e. "Software\Classes\WOW6432Node"). It's just a limited subset, including "CLSID", "DirectShow", "Interface", "Media Type", and "MediaFoundation". --- One never sees "\REGISTRY\MACHINE" and "\REGISTRY\USER" in the registry API because it's designed to always use the "RootDirectory" handle in the native NT object attributes [1]. For local access, the API maps real handles for "\REGISTRY\MACHINE" and "\REGISTRY\USER" to the predefined pseudo-handles HKEY_LOCAL_MACHINE and HKEY_USERS. Similarly, HKEY_CURRENT_USER is mapped to a handle for "\REGISTRY\USER\", where "" is the string form of the user's security identifier. For remote access via RegConnectRegistryW (i.e. winreg.ConnectRegistry), the predefined handles are mapped to remote-procedure-call (RPC) handles that proxy real key handles on the remote system. [1] https://docs.microsoft.com/en-us/windows/win32/api/ntdef/ns-ntdef-_object_attributes From jon+usenet at unequivocal.eu Fri Jul 31 09:15:11 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 31 Jul 2020 13:15:11 -0000 (UTC) Subject: "1,+2,", but not "(1,)+2," References: Message-ID: On 2020-07-31, Stefan Ram wrote: > You can write > >|>>> 1,+2, >|(1, 2) > > , but not > >|>>> (1,)+2, >|TypeError: can only concatenate tuple (not "int") to tuple > > . Why? (Python 3.9) For the obvious reason, as indicated by the error message? What are you expecting these expressions to mean? From python at mrabarnett.plus.com Fri Jul 31 11:16:08 2020 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 31 Jul 2020 16:16:08 +0100 Subject: "1,+2,", but not "(1,)+2," In-Reply-To: References: Message-ID: <92c761f0-1ceb-8268-e705-fae2079d80ba@mrabarnett.plus.com> On 2020-07-31 14:15, Jon Ribbens via Python-list wrote: > On 2020-07-31, Stefan Ram wrote: >> You can write >> >>|>>> 1,+2, >>|(1, 2) >> >> , but not >> >>|>>> (1,)+2, >>|TypeError: can only concatenate tuple (not "int") to tuple >> >> . Why? (Python 3.9) > > For the obvious reason, as indicated by the error message? > > What are you expecting these expressions to mean? > (For some reason, I haven't received Stefan's original post.) It's all to do with operator precedence. The '+' has a higher precedence than the ',', so: 1,+2, is parsed as: (1),(+2), NOT as: (1,)+(2,) although they happen to give the same answer. On the other hand: (1,)+2, is parsed as: ((1,)+2), which results in a TypeError. From pascor22234 at gmail.com Fri Jul 31 00:48:39 2020 From: pascor22234 at gmail.com (R Pasco) Date: Fri, 31 Jul 2020 00:48:39 -0400 Subject: Winreg In-Reply-To: References: Message-ID: My code was just experimental and will be much refined in the future which will include specific exception catches. Connecting to the local registry is to 'go the last yard' for a full-blown implementation. I had a hard time grasping the Windows registry concept of having to first get a key handle for the parent keypath and then specifying an already existing fina/'leaf' key as a string in order to simply read the key's valuename/value data. Who can tell what they were thinking at the time! It seems like a good idea to "abstract" this out since it seems overly complicated and needlessly confusing. Thanks for your extensive info. Its too bad this isn't published in the python winreg/_winreg modules' info. Ray Pasco On Fri, Jul 31, 2020 at 12:43 AM R Pasco wrote: > My code was simply experimental and will be much refined in the future > which will include specific exception catches. Connecting to the local > registry is to go the 'last yard' for a full implementation. > > I had a hard time grasping the Windows registry concept of having to first > get a key handle for the parent keypath and then specifying an already > existing final or 'leaf' key as a string in order to simply read the key's > valuename/value data. Who can tell what they were thinking at the time! It > seems like a good idea to "abstract" this out since it seems overly > complicated and needlessly confusing. > > Thanks for your extensive info. Its too bad this isn't published in the > python winreg/_winreg modules' info. > Ray Pasco > > > > On Thu, Jul 30, 2020 at 11:53 PM Eryk Sun wrote: > >> On 7/30/20, R Pasco wrote: >> >> > access rights must be set to [winreg.KEY_ALL_ACCESS | >> winreg.KEY_WOW64_64KEY >> >> It's a bad practice to request more access than you require, at the >> very least because the request may fail with access denied for no good >> reason. >> >> KEY_ALL_ACCESS includes all applicable standard rights (WRITE_OWNER, >> WRITE_DAC, READ_CONTROL, DELETE) and all key rights (KEY_QUERY_VALUE, >> KEY_SET_VALUE, KEY_CREATE_SUB_KEY, KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, >> KEY_CREATE_LINK). For an existing key, do you need to change the >> owner, read and modify the security, delete the key, set a symlink, >> etc? It looks like you just need to set a value, i.e. KEY_SET_VALUE. >> >> > winreg.KEY_WOW64_32KEY] (??? Why does this also work ?) >> >> By default a 64-bit process doesn't see redirected keys, but if you >> need to access them, use KEY_WOW64_32KEY in the desired access. >> Normally a 32-bit process under WOW64 sees redirected keys, and if you >> need to access the non-redirected keys, use KEY_WOW64_64KEY. >> >> Note that KEY_WOW64_64KEY and KEY_WOW64_32KEY access modes only affect >> runtime redirection. As with the standard MAXIMUM_ALLOWED access mode, >> they're not assignable rights that can be granted or denied in a key >> object's access control list. >> >> > with winreg.ConnectRegistry( None, hive ) as hivehndl >> >> There is no need to call ConnectRegistry here. By default, predefined >> handles are resolved to local key handles. Also, if you actually need >> to access a remote machine, note that it's nonsensical to try to >> connect to HKEY_CURRENT_USER. The API allows it, but why would one >> assume that the remote machine will have a profile for the current >> user's SID? The remote system will most likely just connect to a >> handle for the default user profile. >> >> > The key HKEY_LOCAL_MACHINE:SOFTWARE requires KEY_WOW64_64KEY >> > to be 'OR'ed. Winreg gives no indication of this requirement, but the >> > Windows doc "Redirected, Shared, and Reflected Keys Under WOW64" does >> > specifically mention HKEY_CURRENT_USER :SOFTWARE as needing this added >> > access. >> >> At the machine level, the software hive is stored on disk at >> "%SystemRoot%\System32\config\SOFTWARE" and mounted at >> "\REGISTRY\MACHINE\SOFTWARE". For a WOW64 process, by default there is >> extensive runtime redirection of keys in this hive to the subkeys >> "WOW6432Node" and "Classes\WOW6432Node". >> >> At the user level, there are two hives mounted. The user profile is >> stored on disk at "%USERPROFILE%\NTUSER.DAT" and mounted at >> "\REGISTRY\USER\", where "" is the string form of the user's >> security identifier (e.g. "S-1-5-21----"). For >> a WOW64 process, there is no redirection of subkeys that are >> physically stored in this hive. >> >> The user's software classes hive is stored on disk at >> "%LOCALAPPDATA%\Microsoft\Windows\UsrClass.dat" and mounted at >> "\REGISTRY\USER\_Classes". In the user profile, the >> "Software\Classes" key is a symbolic link to the latter. For a WOW64 >> process, some subkeys in the classes hive are redirected to subkeys in >> "WOW6432Node" (i.e. "Software\Classes\WOW6432Node"). It's just a >> limited subset, including "CLSID", "DirectShow", "Interface", "Media >> Type", and "MediaFoundation". >> >> --- >> >> One never sees "\REGISTRY\MACHINE" and "\REGISTRY\USER" in the >> registry API because it's designed to always use the "RootDirectory" >> handle in the native NT object attributes [1]. For local access, the >> API maps real handles for "\REGISTRY\MACHINE" and "\REGISTRY\USER" to >> the predefined pseudo-handles HKEY_LOCAL_MACHINE and HKEY_USERS. >> Similarly, HKEY_CURRENT_USER is mapped to a handle for >> "\REGISTRY\USER\", where "" is the string form of the user's >> security identifier. For remote access via RegConnectRegistryW (i.e. >> winreg.ConnectRegistry), the predefined handles are mapped to >> remote-procedure-call (RPC) handles that proxy real key handles on the >> remote system. >> >> [1] >> https://docs.microsoft.com/en-us/windows/win32/api/ntdef/ns-ntdef-_object_attributes >> > From python at python.invalid Fri Jul 31 09:43:18 2020 From: python at python.invalid (Python) Date: Fri, 31 Jul 2020 15:43:18 +0200 Subject: "1,+2,", but not "(1,)+2," In-Reply-To: References: Message-ID: <5f241fe4$0$15164$426a34cc@news.free.fr> Stefan Ram wrote: > Jon Ribbens writes: >> On 2020-07-31, Stefan Ram wrote: >>> You can write >>> |>>> 1,+2, >>> |(1, 2) >>> , but not >>> |>>> (1,)+2, >>> |TypeError: can only concatenate tuple (not "int") to tuple >>> . Why? (Python 3.9) >> For the obvious reason, as indicated by the error message? >> What are you expecting these expressions to mean? > > In ?1,+2,?, the right operand ?2,? obviously is interpreted > to be a 1-tuple. Nope. The right operant is 2 not 2, and is interpreted as an int. From jon+usenet at unequivocal.eu Fri Jul 31 14:25:00 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 31 Jul 2020 18:25:00 -0000 (UTC) Subject: "1,+2,", but not "(1,)+2," References: <1TXUG.767386$rLg.128609@fx49.ams4> Message-ID: On 2020-07-31, Bart wrote: > Not sure about the trailing commas on each. It seems Python ignores > trailing commas on tuple constructors, so that the A,B, would be a > 2-tuple, and A+B, would have been a 1-tuple if A+B had been legal. It's not just tuples, it's lists, sets, dictionaries, etc. It's very useful because it means that when editing source code to add new items or to rearrange items you don't need to worry about the commas. e.g.: animals = { 'cow': 'mammal', 'spider': 'arachnid', 'turtle': 'reptile', } If you want to add a new item to or remove an existing item from the dictionary, you only need to edit one line, and it doesn't matter if that line is in the middle or at the end of the existing entries. From rosuav at gmail.com Fri Jul 31 14:38:56 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Aug 2020 04:38:56 +1000 Subject: "1,+2,", but not "(1,)+2," In-Reply-To: References: <1TXUG.767386$rLg.128609@fx49.ams4> Message-ID: On Sat, Aug 1, 2020 at 4:31 AM Jon Ribbens via Python-list wrote: > > On 2020-07-31, Bart wrote: > > Not sure about the trailing commas on each. It seems Python ignores > > trailing commas on tuple constructors, so that the A,B, would be a > > 2-tuple, and A+B, would have been a 1-tuple if A+B had been legal. > > It's not just tuples, it's lists, sets, dictionaries, etc. And function parameters and basically anything that permits a comma-separated sequence. Or any other sort of sequence. You can have multiple simple statements on one line, separated by semicolons - and it's legal to have a spare semi at the end. It's REALLY annoying to run into those few cases where that doesn't work (JSON, and the SQL "create table" statement, and a handful of others). ChrisA From tanmayshah2007 at gmail.com Fri Jul 31 16:10:08 2020 From: tanmayshah2007 at gmail.com (Tanmay Shah) Date: Fri, 31 Jul 2020 14:10:08 -0600 Subject: Downloading Python Message-ID: Hello to whoever this may concern, After downloading Python 3.8.5 IDLE, an error message popped up, saying the code execution cannot proceed because python38.dll was not found. What should I do in order to use the Python interpreter? Thank you! From DomainAdmin at DancesWithMice.info Fri Jul 31 17:46:26 2020 From: DomainAdmin at DancesWithMice.info (David L Neil) Date: Sat, 1 Aug 2020 09:46:26 +1200 Subject: Winreg In-Reply-To: References: Message-ID: On 31/07/2020 16:48, R Pasco wrote: > Thanks for your extensive info. Its too bad this isn't published in the > python winreg/_winreg modules' info. > Ray Pasco Welcome to the world of documentation! Perhaps you have 'discovered' something, or maybe you're using the tool in an unusual way, or maybe the docs are too sketchy (I'm not a user of MS-Win, so can't comment). Regardless, the documentation team would welcome a contribution based upon this discussion and your learning... The best way to ensure you have learned something thoroughly is to explain it to others! -- Regards =dn From robertvstepp at gmail.com Fri Jul 31 22:24:06 2020 From: robertvstepp at gmail.com (boB Stepp) Date: Fri, 31 Jul 2020 21:24:06 -0500 Subject: Issue with Python installation for a beginner Python coder. In-Reply-To: <1876847237.7706738.1596098417334@mail.yahoo.com> References: <1876847237.7706738.1596098417334.ref@mail.yahoo.com> <1876847237.7706738.1596098417334@mail.yahoo.com> Message-ID: On Thu, Jul 30, 2020 at 9:24 AM Sarvesh Poddar via Python-list wrote: > I re-installed Python in my Windows system as the earlier one was not able to import modules... You do not provide much detail to diagnose what your problem(s) is(are). By the "earlier one" is it the same version as the one you re-installed? Were you able to run IDLE with the "earlier one"? By not being able to import modules do you mean modules from Python's standard library? Or do you mean installing third party libraries using pip? > ...But now I am not able to open IDLE after multiple tries. Have you looked in your start menu in the list of installed programs for Python? If it is there did you expand it and see if there is an entry for IDLE? How have you been trying (unsuccessfully) to open IDLE? -- boB