From alan.gauld at yahoo.co.uk Thu Aug 3 16:51:36 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 3 Aug 2023 21:51:36 +0100 Subject: [Tutor] Tkinter iconbitmap question In-Reply-To: <02e89c59-e100-8843-6203-4589d58a5c09@gmail.com> References: <02e89c59-e100-8843-6203-4589d58a5c09@gmail.com> Message-ID: On 27/07/2023 06:03, Phil wrote: > I'm playing with an example from ttkbootstrap and I'm having a problem > with the iconbitmap function. I realise that .ico files are not > compatible with Linux so I've chosen an xbm file instead but I still > have the same error as follows: I notice there have been no followups and even as a Tkinter user I have no idea about this topic. There is an active tkinter mailing list, I suggest you try asking on there. They are usually pretty responsive. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From phillor9 at gmail.com Thu Aug 3 19:55:20 2023 From: phillor9 at gmail.com (Phil) Date: Fri, 4 Aug 2023 09:55:20 +1000 Subject: [Tutor] Tkinter iconbitmap question In-Reply-To: References: <02e89c59-e100-8843-6203-4589d58a5c09@gmail.com> Message-ID: <9e79c27a-a8ec-0d35-854a-3eb1b801043a@gmail.com> On 4/8/23 06:51, Alan Gauld via Tutor wrote: > > There is an active tkinter mailing list, I suggest you try > asking on there. They are usually pretty responsive. Thanks Alan, I wasn't aware of a Tkinter mailing list. I'll have a browse. Regarding my question; it's not important, I was just wondering. -- Regards, Phil From alan.gauld at yahoo.co.uk Fri Aug 4 04:24:06 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 4 Aug 2023 09:24:06 +0100 Subject: [Tutor] Tkinter iconbitmap question In-Reply-To: <9e79c27a-a8ec-0d35-854a-3eb1b801043a@gmail.com> References: <02e89c59-e100-8843-6203-4589d58a5c09@gmail.com> <9e79c27a-a8ec-0d35-854a-3eb1b801043a@gmail.com> Message-ID: On 04/08/2023 00:55, Phil wrote: > Thanks Alan, I wasn't aware of a Tkinter mailing list. I'll have a browse. I'm not sure of the list address but you can find it on gmane at gmane.comp.python.tkinter There is also an IDLE one that often discusses Tkinter issues too. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From mats at wichmann.us Fri Aug 4 12:07:33 2023 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 4 Aug 2023 10:07:33 -0600 Subject: [Tutor] Tkinter iconbitmap question In-Reply-To: References: <02e89c59-e100-8843-6203-4589d58a5c09@gmail.com> <9e79c27a-a8ec-0d35-854a-3eb1b801043a@gmail.com> Message-ID: <6b41fea9-aadb-6e50-7e64-51a2dfdfbf53@wichmann.us> On 8/4/23 02:24, Alan Gauld via Tutor wrote: > On 04/08/2023 00:55, Phil wrote: > >> Thanks Alan, I wasn't aware of a Tkinter mailing list. I'll have a browse. > > I'm not sure of the list address but you can find it on gmane at > > gmane.comp.python.tkinter > > There is also an IDLE one that often discusses Tkinter issues too. One of the things that's always given me a bit of headache is that Tk of course isn't a Python project, and it's sometimes hard to keep track of how well tkinter isolates you from its particular weirdnesses - Tcl is a different language, after all. My memory is that in referring to bitmaps in Tk, you need a special leading character to indicate what you're passing is a filename, and not a variable already containing the bitmap contents. The error message *sounds* like that case or I wouldn't mention it, but I'd be kind of surprised if tkinter actually made you follow that convention. (the magic character in Tk, which I had to spend some time in long long ago - let's just call it "last century" for grins - is an '@' unless my memory has failed me, which is eminently possible). From phillor9 at gmail.com Fri Aug 4 19:38:31 2023 From: phillor9 at gmail.com (Phil) Date: Sat, 5 Aug 2023 09:38:31 +1000 Subject: [Tutor] Tkinter iconbitmap question In-Reply-To: <6b41fea9-aadb-6e50-7e64-51a2dfdfbf53@wichmann.us> References: <02e89c59-e100-8843-6203-4589d58a5c09@gmail.com> <9e79c27a-a8ec-0d35-854a-3eb1b801043a@gmail.com> <6b41fea9-aadb-6e50-7e64-51a2dfdfbf53@wichmann.us> Message-ID: <5bf0f52f-d327-3758-9c76-ecd596933108@gmail.com> On 5/8/23 02:07, Mats Wichmann wrote: in long long ago - let's just call it "last century" for grins - is an '@' unless my memory has failed me, which is eminently possible). I found a discussion on Stackoverfow and the suggestion was to prefix the icon name with a '@'. This stopped the error message but the icon still wasn't placed on the window so I posted my enquiry to this list. I do have a dual boot system but it's just too much trouble to install python on Windows just to confirm that the icon problem is just a Linux thing. -- Regards, Phil From phillor9 at gmail.com Fri Aug 4 19:42:22 2023 From: phillor9 at gmail.com (Phil) Date: Sat, 5 Aug 2023 09:42:22 +1000 Subject: [Tutor] Tkinter iconbitmap question In-Reply-To: References: <02e89c59-e100-8843-6203-4589d58a5c09@gmail.com> <9e79c27a-a8ec-0d35-854a-3eb1b801043a@gmail.com> Message-ID: On 4/8/23 18:24, Alan Gauld via Tutor wrote: > I'm not sure of the list address but you can find it on gmane at > > gmane.comp.python.tkinter > > There is also an IDLE one that often discusses Tkinter issues too. I joined the tkinter-discuss list yesterday. No questions have been posted so far so I'll if I can find the archive for the list. -- Regards, Phil From alan.gauld at yahoo.co.uk Sat Aug 5 03:51:06 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sat, 5 Aug 2023 08:51:06 +0100 Subject: [Tutor] Tkinter iconbitmap question In-Reply-To: References: <02e89c59-e100-8843-6203-4589d58a5c09@gmail.com> <9e79c27a-a8ec-0d35-854a-3eb1b801043a@gmail.com> Message-ID: On 05/08/2023 00:42, Phil wrote: >> gmane.comp.python.tkinter >> >> There is also an IDLE one that often discusses Tkinter issues too. > > I joined the tkinter-discuss list yesterday. No questions have been > posted so far so I'll if I can find the archive for the list. The last post I have on gmane was on the 28th July. But it received a reply within 2 hours and was resolved within 24 hours. So not high traffic but definitely active. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From PythonList at DancesWithMice.info Tue Aug 8 19:26:52 2023 From: PythonList at DancesWithMice.info (dn) Date: Wed, 9 Aug 2023 11:26:52 +1200 Subject: [Tutor] Mtg ANN: Using computer vision AI to help protect the worlds rarest dolphin Message-ID: <38405e40-ec6d-b932-ee24-b7366a13d710@DancesWithMice.info> Wed 16 Aug 2023, 1800~20:30 NZST (0600~0830 UTC, late-Tue in US) Details and RSVP at https://www.meetup.com/nzpug-auckland/events/295091858/ Teaching a computer to see. How computer vision is helping to protect the world?s rarest dolphin and how you can train your own model. Tane van der Boon will talk about the MAUI63 project, and then lead us through how to train and utilise a custom computer vision object detector. Essentially allowing our software to be able to see. MAUI63 was given its name because when the venture began, there were only 63 M?ui dolphins left in existence. Using drone technology and AI to collect and process visual data, the founders took action to collect data to help save the world?s rarest dolphin from extinction and influence future marine conservation efforts. The MAUI63 team uses a customised drone to find and track the movement of dolphins, and enables individual dolphins to be identified through their fin markings. The information collected can then be used to inform better data driven decisions on how best to protect them. Later, Tane will lead us through a smaller task to build our own image recognizer. (more details in due course...) The Auckland Branch of the New Zealand Python Users' Group meet twice monthly. You're very welcome to attend online or in-person (as available). Meeting location-details or URL will be sent to those who RSVP. We are a healthy mix of Python users. Students, academics, hobbyists, industry professionals, and many completely new to Python. The "room" opens at 1800 (local time) with an opportunity to network with colleagues. Everything should be wrapped up by 2030. We are always keen to hear suggestions for meeting-topics, and to meet with folk who'd like to present or lead - eg a brief lightning talk, a practical coaching-session, a full lecture... Help is available if you've never done such a thing before! We follow the NZPUG Code of Conduct (https://python.nz/code-of-conduct) to create an inclusive and friendly environment. We express thanks to, and encourage you to investigate, our sponsors: Catalyst Cloud, New Zealand Open Source Society, JetBrains, and IceHouse Ventures. -- Regards =dn -- Regards, =dn From avijitprep at gmail.com Thu Aug 10 13:01:38 2023 From: avijitprep at gmail.com (Avijit Shukla) Date: Thu, 10 Aug 2023 22:31:38 +0530 Subject: [Tutor] Need sample code to read xlsx files Message-ID: Hi I need sample code to use xlsx files.. thanks..:) kindy help From alan.gauld at yahoo.co.uk Thu Aug 10 20:15:13 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 11 Aug 2023 01:15:13 +0100 Subject: [Tutor] Need sample code to read xlsx files In-Reply-To: References: Message-ID: On 10/08/2023 18:01, Avijit Shukla wrote: > Hi I need sample code to use xlsx files.. We need more details. For one thing there are two popular modules for working with Excel, one for reading and one for writing, so it depends on what you want to do to even decide which module to use. Another common option if possible is to export the data from Excel as a CSV file and use the standard library csv module. (Or you can use the standard library tools to work with the xml data in the raw excel file, but that's tricky... Finally, if the Excel includes macros etc then you may need to use pywin to access the COM interface directly (assuming it's on Windows), or alternatively use ctypes to drive the Windows libraries. So many options (and these are only some of the possibilities!) we can't start to quote code until we know what the code needs to do! -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From avijitprep at gmail.com Fri Aug 11 03:31:42 2023 From: avijitprep at gmail.com (Avijit Shukla) Date: Fri, 11 Aug 2023 13:01:42 +0530 Subject: [Tutor] (no subject) Message-ID: I need to learn about reading excel files..from system.. if possible you can share steps with sample code?? From mats at wichmann.us Fri Aug 11 09:52:14 2023 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 11 Aug 2023 07:52:14 -0600 Subject: [Tutor] (no subject) In-Reply-To: References: Message-ID: <9a2420db-afd7-281b-fe92-6dd597398030@wichmann.us> On 8/11/23 01:31, Avijit Shukla wrote: > I need to learn about reading excel files..from system.. > > if possible you can share steps with sample code?? I think you got one response already (or was that someone else? we don't seem to have a working list archive any more) There are lots of ways to deal with data from excel - from working directly with the files to asking excel to dump into a format that's easier to work with (usually csv) to interacting with the program itself. Here's one example but be aware this is only one approach: https://realpython.com/openpyxl-excel-spreadsheets-python/ From alan.gauld at yahoo.co.uk Fri Aug 11 13:01:34 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 11 Aug 2023 18:01:34 +0100 Subject: [Tutor] (no subject) In-Reply-To: <9a2420db-afd7-281b-fe92-6dd597398030@wichmann.us> References: <9a2420db-afd7-281b-fe92-6dd597398030@wichmann.us> Message-ID: On 11/08/2023 14:52, Mats Wichmann wrote: > On 8/11/23 01:31, Avijit Shukla wrote: >> I need to learn about reading excel files..from system.. >> >> if possible you can share steps with sample code?? > > I think you got one response already I think this is the extra "detail" that I asked for. He wants to *read* excel files *from the system*, whatever that means! Taken at face value, I assume he wants to read the data from a .xlsx file. And for that the best module is probably xlrd. Although I notice that a web search suggests pandas.read() can cope with xlsx files too. But pandas is quite a heavyweight module if you only want to read the data. OTOH if you were doing serious data processing then pandas is probably the best option! There are plenty pandas tutorials on the web and on Youtube so I'll let the OP search for those. The official xlrd module tutorial is here: https://xlrd.readthedocs.io/en/latest/ You also mentioned openpyxl which I've never used but notice it can be used to both read and write which might be an advantage... I also don't know how any of these tools cope with tabbed sheets, calculated fields and macros. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From trent.shipley at gmail.com Fri Aug 11 15:12:46 2023 From: trent.shipley at gmail.com (trent shipley) Date: Fri, 11 Aug 2023 12:12:46 -0700 Subject: [Tutor] (no subject) In-Reply-To: References: <9a2420db-afd7-281b-fe92-6dd597398030@wichmann.us> Message-ID: Zumstein, Felix Python for Excel O'Reilly Media, Inc. Mar 2021 On Fri, Aug 11, 2023 at 10:02?AM Alan Gauld via Tutor wrote: > On 11/08/2023 14:52, Mats Wichmann wrote: > > On 8/11/23 01:31, Avijit Shukla wrote: > >> I need to learn about reading excel files..from system.. > >> > >> if possible you can share steps with sample code?? > > > > I think you got one response already > > I think this is the extra "detail" that I asked for. > He wants to *read* excel files *from the system*, > whatever that means! > > Taken at face value, I assume he wants to read > the data from a .xlsx file. And for that the best > module is probably xlrd. Although I notice that a > web search suggests pandas.read() can cope with xlsx > files too. But pandas is quite a heavyweight module > if you only want to read the data. > > OTOH if you were doing serious data processing > then pandas is probably the best option! > > There are plenty pandas tutorials on the web > and on Youtube so I'll let the OP search for those. > > The official xlrd module tutorial is here: > > https://xlrd.readthedocs.io/en/latest/ > > You also mentioned openpyxl which I've never used > but notice it can be used to both read and write > which might be an advantage... > > I also don't know how any of these tools cope > with tabbed sheets, calculated fields and macros. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > From PythonList at DancesWithMice.info Thu Aug 17 17:15:18 2023 From: PythonList at DancesWithMice.info (dn) Date: Fri, 18 Aug 2023 09:15:18 +1200 Subject: [Tutor] OT: Why some questions shouldn't be given a direct answer Message-ID: <9c241c4d-9fb7-4cfa-343d-1a7de6647334@DancesWithMice.info> This topic, somewhat OT to our list's purposes, came-up (again) some weeks back. Here is an article which may explain why some of us don't give direct or full-answers to questions - we prioritise learning! (and if you're 'into' AI, the article covers that too) - learning takes effort - answers are not learning - gaps in knowledge are invisible (to self) - 'hitting a wall' is no fun! - learning involves hierarchies of knowledge/facts - opportunities for AI to help learning (cf confidently give 'answers') - learning is not the same as 'doing' ChatGPT Needs a Tutor Mode Fred Dixon, 23 min read, Jan 27 https://medium.com/@ffdixon/chatgpt-needs-a-tutor-mode-2e4fd1e8f423 -- Regards, =dn From hv062727 at gmail.com Fri Aug 18 03:35:03 2023 From: hv062727 at gmail.com (HarshVardhan Mahawar) Date: Fri, 18 Aug 2023 13:05:03 +0530 Subject: [Tutor] Parsing PKG-INFO Message-ID: Hello Python Community, I am working on project which generates SPDX documents of python projects, and needed help in effectively parsing the PKG-INFO metadata file, I would appreciate if someone can help Regards HarshvMahawar From mats at wichmann.us Fri Aug 18 10:53:05 2023 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 18 Aug 2023 08:53:05 -0600 Subject: [Tutor] Parsing PKG-INFO In-Reply-To: References: Message-ID: On 8/18/23 01:35, HarshVardhan Mahawar wrote: > Hello Python Community, > > I am working on project which generates SPDX documents of python projects, > and needed help in effectively parsing the PKG-INFO metadata file, I would > appreciate if someone can help Have you tried the pkginfo project? There are also various projects which do this, but aren't standalone, you might root around in the place where many of the most popular packaging projects live - https://www.pypa.io/en/latest/index.html Additionally, there are quite a few SBOM-oriented projects now, you may not actually have to reinvent the wheel (that wasn't supposed to be a pun!) here, somebody may already have done what you need. From simon.n.connah at protonmail.com Fri Aug 25 10:03:11 2023 From: simon.n.connah at protonmail.com (Simon Connah) Date: Fri, 25 Aug 2023 14:03:11 +0000 Subject: [Tutor] Should I use type hints for all new code? Message-ID: I'm wondering if I should use type hints for new code. They make things easier to read and they stop sloppy mistakes but do they have a performance impact? I just want to know what is considered best practice these days. From mats at wichmann.us Fri Aug 25 12:48:48 2023 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 25 Aug 2023 10:48:48 -0600 Subject: [Tutor] Should I use type hints for all new code? In-Reply-To: References: Message-ID: On 8/25/23 08:03, Simon Connah via Tutor wrote: > I'm wondering if I should use type hints for new code. They make things easier to read and they stop sloppy mistakes but do they have a performance impact? > > I just want to know what is considered best practice these days. "Up to you" - don't think there's really a "best practice" here, yet, there are millions of Python programmers, with vastly different needs. The people who do tend to use them faithfully are those explicitly writing to share with others - writers of examples, tutorials, etc. I suspect that gives a skewed view that they're more widely used than they may actually be in the "real world". They don't have a performance impact (*). They're designed as something that is *not* evaluated at runtime, but rather by static analysis tools. If they make you feel better, use them. If they make you more productive, either directly in your coding, or because they give better hints to your IDE and that helps you, use them. It's entirely voluntary, though. For one-off small scripts, some people feel they're more trouble than it's worth, while to others the "stating of intent" is helpful when you go read your little (or big) program a week or a month or a year later. If you hate them, don't use them (you've said that's not the case!). Advanced: * - nothing is ever *truly* black-and-white, and that includes what I said about no impact. they do take up some space; the hints for an object are stored in an attribute in the object (__annotations__), and there *is* a runtime way to introspect that. But the Python interpreter itself does not do any type checking based on those hints. From threesomequarks at proton.me Fri Aug 25 13:25:18 2023 From: threesomequarks at proton.me (ThreeBlindQuarks) Date: Fri, 25 Aug 2023 17:25:18 +0000 Subject: [Tutor] Should I use type hints for all new code? In-Reply-To: References: Message-ID: Simon, People with more experience using these features may have better answers but note how late these features were added to python even though they were available for decades in languages that not only had the features but required them! At this point, python does not require you to tell it what types things are and so on and that is considered by many to be a good thing and especially as it allows the same piece of code to work on many things interchangeably. Having a stronger system might allow for better code to be generated when COMPILED but Python is generally interpreted. It may not be much of a performance hit to have the interpreter IGNORE the hints but clearly it is extra work to read through bigger files and far easier to generate errors if typed in badly. For now, the real purpose of the extra code is to allow programs like linters to check for additional possible problems with the code. Of course, it can be quite helpful to tell others using your code what to expect but realistically, you could just as easily explain everything you want in documentation or as comments alongside the code that are also even easier to ignore. But as the feature is there, I suspect it may be good form to use it in SOME CASES and not others. I mean if the code used requires character strings and does not handle numbers, you could make that explicit. But if your code is required to handle dozens of types then creating some notation that explicitly specifies the allowed types in the code may be more trouble than it is worth, and yet more if later someone wants to extend your code to handle additional things. One consideration in a dynamic language like Python is that no matter what you specify, something different may still be passed along at runtime. Those types of errors can be caught, with some expense, by having a function do various kinds of validation before using the arguments passed to it, or catching exceptions. Who is your "audience" for looking at or using your code? If in a classroom with an instructor teaching you how to use the feature, then of course you should do what they want. If in a company that demands it and builds lots of extra time in to do it, fine. But if you have a deadline that is already hard to meet, why bother? Sent with Proton Mail secure email. ------- Original Message ------- On Friday, August 25th, 2023 at 10:03 AM, Simon Connah via Tutor wrote: > I'm wondering if I should use type hints for new code. They make things easier to read and they stop sloppy mistakes but do they have a performance impact? > > I just want to know what is considered best practice these days._______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor From PythonList at DancesWithMice.info Fri Aug 25 16:57:57 2023 From: PythonList at DancesWithMice.info (dn) Date: Sat, 26 Aug 2023 08:57:57 +1200 Subject: [Tutor] Should I use type hints for all new code? In-Reply-To: References: Message-ID: On 26/08/2023 02.03, Simon Connah via Tutor wrote: > I'm wondering if I should use type hints for new code. They make things easier to read and they stop sloppy mistakes but do they have a performance impact? > > I just want to know what is considered best practice these days. Am reminded of 'Postel's Law' (https://en.wikipedia.org/wiki/Robustness_principle), ie being precise in what one writes, but accepting what you read. Trouble is, once the Open-Closed Principle and the Single-Responsibility Principle or Separation of Concerns are added (to the above), a tension between them becomes evident - hence the word "law" being deprecated. Diving into OOP philosophy, polymorphism brings a whole extra layer to the mix. (my brain is full - can I go home now?) Remember that typing (and thus mypy, etc) is an 'add-on', rather than part of the Python language. It is not *necessary*. However, the OP lists *advantages*. Perhaps less concerning than execution-time performance is 'developer efficacy'. Python-Masters are able to 'see' larger 'chunks' of code in their minds. Whereas, Apprentices have to concentrate to produce one line at a time. If the addition of typing causes 'brain overload' and has the effect of reducing one's ability to code the series of statements necessary to complete a single task; then ignore them - or perhaps come back to add them later. If one finds it part of 'design thinking' to consider the data-type as well as the name* of some new identifier, on top of keeping the necessary program-logic in-mind; then more power to your right arm... * as often mentioned 'here', it is usually easier to name something when you come to 'use' it. Accordingly, don't stress over naming stuff at its first declaration, but re-consider its name when wanting to make use of it (and thank the 'PyCharm-gods' that they embedded refactoring/renaming operations within that IDE). If that rings-true for you, then the thought can probably be extended to typing... Another way of looking at both typing and naming, is one's design approach. Many folk today follow a type-and-design process, encouraged by the mechanisms of an interpreter and the REPL. Accordingly, thinking with one's fingers (?). Whereas, us old f***s were taught to design first, check/test next, and code last. Someone following a top-down technique such as this, has named many of the necessary components at the design-step - take a look at a UML class-diagram, as needed (eg https://i.pinimg.com/originals/d9/c3/e5/d9c3e593b86ec2294338cbc1fd97961d.png). Thus, there is 'spare' cognitive process to also consider the identifier's type. See also, database schema. Final comment. As @Mats described. I try to use type-hints in all tutorial examples, or code which may be reviewed or maintained by Python-Apprentice colleagues. Even when the typing descriptions take-up more screen/slide space, they ease readability and thus learning. "Explicit is better than implicit"! There again, dashing-off something for my own use might be an excuse to think differently. However, in increasing?decreasing decrepitude, my memory thanks typing in somewhat the same manner as ABCs (Abstract Base Classes) - a very handy aide-memoire preventing flawed assumptions (particularly when my current-self working on the code is what was once thought to be my self-in-six-months-time). (as my English teacher liked to say: "assume" makes an "ass" out of "u" and "me" - upon which witticism I shall leave you (?reeling) ) -- Regards, =dn From alan.gauld at yahoo.co.uk Fri Aug 25 17:59:57 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 25 Aug 2023 22:59:57 +0100 Subject: [Tutor] Should I use type hints for all new code? In-Reply-To: References: Message-ID: On 25/08/2023 15:03, Simon Connah via Tutor wrote: > I'm wondering if I should use type hints for new code. I'm probably in a minority here but I avoid type hints and dislike them intensely. I spent a large part of my professional life as a maintenance programmer on statically typed languages(mainly Pascal ad C/C++) And static typing resulted in probably the second biggest cause of bugs after uninitialised pointers. It's not the typing per se but the resultant need for (often unnecessary) type conversions to conform to the types. And type conversions are a huge potential source of errors (and usually intermittent and very hard to find!). I think type hints go completely against the principles of dynamic typing (of which I'm a big fan). Thankfully, in Python they are only a hint and can be safely ignored, although I'm dreading the day somebody decides to make the interpreter pay heed to them! I know that goes against the orthodoxy and certainly what I was taught in school. But in the real world I find static typing to be more of a problem than a help. Embrace dynamic typing. If it acts like a duck it is a duck. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From simon.n.connah at protonmail.com Fri Aug 25 13:12:36 2023 From: simon.n.connah at protonmail.com (Simon Connah) Date: Fri, 25 Aug 2023 17:12:36 +0000 Subject: [Tutor] Should I use type hints for all new code? In-Reply-To: References: Message-ID: ------- Original Message ------- On Friday, August 25th, 2023 at 17:48, Mats Wichmann wrote: > > > On 8/25/23 08:03, Simon Connah via Tutor wrote: > > > I'm wondering if I should use type hints for new code. They make things easier to read and they stop sloppy mistakes but do they have a performance impact? > > > > I just want to know what is considered best practice these days. > > > "Up to you" - don't think there's really a "best practice" here, yet, > there are millions of Python programmers, with vastly different needs. > > The people who do tend to use them faithfully are those explicitly > writing to share with others - writers of examples, tutorials, etc. I > suspect that gives a skewed view that they're more widely used than they > may actually be in the "real world". > > They don't have a performance impact (*). They're designed as something > that is not evaluated at runtime, but rather by static analysis tools. > > If they make you feel better, use them. If they make you more > productive, either directly in your coding, or because they give better > hints to your IDE and that helps you, use them. It's entirely voluntary, > though. For one-off small scripts, some people feel they're more > trouble than it's worth, while to others the "stating of intent" is > helpful when you go read your little (or big) program a week or a month > or a year later. If you hate them, don't use them (you've said that's > not the case!). > > > > Advanced: > > * - nothing is ever truly black-and-white, and that includes what I > said about no impact. they do take up some space; the hints for an > object are stored in an attribute in the object (annotations), and > there is a runtime way to introspect that. But the Python interpreter > itself does not do any type checking based on those hints. > Thank you very much! That was really useful. Simon. From simon.n.connah at protonmail.com Fri Aug 25 13:33:20 2023 From: simon.n.connah at protonmail.com (Simon Connah) Date: Fri, 25 Aug 2023 17:33:20 +0000 Subject: [Tutor] Should I use type hints for all new code? In-Reply-To: References: Message-ID: ------- Original Message ------- On Friday, August 25th, 2023 at 18:25, ThreeBlindQuarks wrote: > > > > Simon, > > People with more experience using these features may have better answers but note how late these features were added to python even though they were available for decades in languages that not only had the features but required them! > > At this point, python does not require you to tell it what types things are and so on and that is considered by many to be a good thing and especially as it allows the same piece of code to work on many things interchangeably. > > Having a stronger system might allow for better code to be generated when COMPILED but Python is generally interpreted. It may not be much of a performance hit to have the interpreter IGNORE the hints but clearly it is extra work to read through bigger files and far easier to generate errors if typed in badly. > > For now, the real purpose of the extra code is to allow programs like linters to check for additional possible problems with the code. > > Of course, it can be quite helpful to tell others using your code what to expect but realistically, you could just as easily explain everything you want in documentation or as comments alongside the code that are also even easier to ignore. > > But as the feature is there, I suspect it may be good form to use it in SOME CASES and not others. I mean if the code used requires character strings and does not handle numbers, you could make that explicit. But if your code is required to handle dozens of types then creating some notation that explicitly specifies the allowed types in the code may be more trouble than it is worth, and yet more if later someone wants to extend your code to handle additional things. > > One consideration in a dynamic language like Python is that no matter what you specify, something different may still be passed along at runtime. Those types of errors can be caught, with some expense, by having a function do various kinds of validation before using the arguments passed to it, or catching exceptions. > > Who is your "audience" for looking at or using your code? If in a classroom with an instructor teaching you how to use the feature, then of course you should do what they want. If in a company that demands it and builds lots of extra time in to do it, fine. But if you have a deadline that is already hard to meet, why bother? I see what you are saying. I'm mainly using Python with Django. It is just me on my own building this site so I was curious if there were any conventions. Thank you for the useful post! Simon. From PythonList at DancesWithMice.info Mon Aug 28 15:06:11 2023 From: PythonList at DancesWithMice.info (dn) Date: Tue, 29 Aug 2023 07:06:11 +1200 Subject: [Tutor] Co-op Group: Django web framework Message-ID: Are you interested in learning Django? Would like to improve your Django knowledge and skills? Have you been picking-up Django piecemeal, and need to consolidate and clarify? Do you know some Django and would like to acquire mentoring and coaching skills? If so, please join us to form a Learning Django Co-op. RSVP at https://www.meetup.com/nzpug-auckland/events/295727130/ -- Regards =dn