From mhysnm1964 at gmail.com Sun Jan 1 00:41:50 2023 From: mhysnm1964 at gmail.com (mhysnm1964 at gmail.com) Date: Sun, 1 Jan 2023 16:41:50 +1100 Subject: [Tutor] finding common words using set. Message-ID: <000901d91da3$c0dc5440$4294fcc0$@GMAIL.COM> All, I have created a function to find the common words within a list of strings. I never get any results back of the common words and cannot understand why. This is the first time I have delt with the set data methods and are trying to understand how to use them. def find_common_words(strings): # Split the strings into lists of words word_lists = [s.split() for s in strings] # Find the intersection of the sets of words common_words = set(word_lists[0]).intersection(*word_lists[1:]) # Join the common words into a single string return ' '.join(common_words) strings = ['apple orange banana', 'orange banana grape', 'banana mango'] common_words = find_common_words(strings) print(common_words) Should return banana orange and I get a null string. Any ideas why? Sean From cs at cskk.id.au Sun Jan 1 03:56:45 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 1 Jan 2023 19:56:45 +1100 Subject: [Tutor] finding common words using set. In-Reply-To: <000901d91da3$c0dc5440$4294fcc0$@GMAIL.COM> References: <000901d91da3$c0dc5440$4294fcc0$@GMAIL.COM> Message-ID: On 01Jan2023 16:41, mhysnm1964 at gmail.com wrote: >I have created a function to find the common words within a list of >strings. >I never get any results back of the common words and cannot understand why. >This is the first time I have delt with the set data methods and are trying >to understand how to use them. > >def find_common_words(strings): > # Split the strings into lists of words > word_lists = [s.split() for s in strings] > # Find the intersection of the sets of words > common_words = set(word_lists[0]).intersection(*word_lists[1:]) > # Join the common words into a single string > return ' '.join(common_words) > >strings = ['apple orange banana', 'orange banana grape', 'banana mango'] >common_words = find_common_words(strings) >print(common_words) > >Should return banana orange and I get a null string. Any ideas why? When I run it I get "banana", as it is the only word in all three strings. I'm using this code: def find_common_words(strings): print("strings =", strings) # Split the strings into lists of words word_lists = [s.split() for s in strings] print("word_lists =", word_lists) # Find the intersection of the sets of words common_words = set(word_lists[0]).intersection(*word_lists[1:]) print("common_words =", common_words) # Join the common words into a single string return ' '.join(common_words) find_common_words( ['apple orange banana', 'orange banana grape', 'banana mango'] ) which is just your code with some print() calls to see what's going on. The print() calls should show you where things are going wrong, but your code seems correct to me and seems to work here. strings = ['apple orange banana', 'orange banana grape', 'banana mango'] word_lists = [['apple', 'orange', 'banana'], ['orange', 'banana', 'grape'], ['banana', 'mango']] common_words = {'banana'} Cheers, Cameron Simpson From alan.gauld at yahoo.co.uk Sun Jan 1 04:08:04 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 1 Jan 2023 09:08:04 +0000 Subject: [Tutor] finding common words using set. In-Reply-To: <000901d91da3$c0dc5440$4294fcc0$@GMAIL.COM> References: <000901d91da3$c0dc5440$4294fcc0$@GMAIL.COM> Message-ID: On 01/01/2023 05:41, mhysnm1964 at gmail.com wrote: > I have created a function to find the common words within a list of strings. > I never get any results back of the common words and cannot understand why. > def find_common_words(strings): > > # Split the strings into lists of words > word_lists = [s.split() for s in strings] > # Find the intersection of the sets of words > common_words = set(word_lists[0]).intersection(*word_lists[1:]) This should find the common elements across all 3 lists. But there is only one common word: banana. (orange is only common to two lists not all three) > # Join the common words into a single string > return ' '.join(common_words) > > > > strings = ['apple orange banana', 'orange banana grape', 'banana mango'] > common_words = find_common_words(strings) > print(common_words) > Should return banana orange and I get a null string. Any ideas why? And this works for me. Are you sure you posted the exact code you ran? Also did you insert print statements after each assignment to check the results were what you expected? Or try it at the >>>. Here is my session: >>> strs = ['one two three', 'two three four', 'one three five'] >>> wl = [s.split() for s in strs] >>> wl [['one', 'two', 'three'], ['two', 'three', 'four'], ['one', 'three', 'five']] >>> set(wl[0]) {'two', 'one', 'three'} >>> set(wl[0]).intersection(*wl[1:]) {'three'} >>> res = set(wl[0]).intersection(*wl[1:]) >>> ' '.join(res) 'three' >>> -- 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 seraph776 at gmail.com Sun Jan 1 15:51:53 2023 From: seraph776 at gmail.com (seraph) Date: Sun, 1 Jan 2023 15:51:53 -0500 Subject: [Tutor] finding common words using set Message-ID: When I ran your code, it returned *banana. *You mentioned it should return "*banana and orange*." However, based on the example that you provided, it should only return *banana*. strings = ['apple orange banana', 'orange banana grape', 'banana mango'] > The common word in these 3 groups is *banana *- not *banana & orange*. I hope this helps! Seraph From threesomequarks at proton.me Sun Jan 1 23:52:31 2023 From: threesomequarks at proton.me (ThreeBlindQuarks) Date: Mon, 02 Jan 2023 04:52:31 +0000 Subject: [Tutor] finding common words using set In-Reply-To: References: Message-ID: I also see the code as working, albeit to test it better, change the strings to contain two common elements like so. The code did not really use sets as intended in that it gave intersection() a list of words rather than a set but that seems like something the function is designed to handle. It does have a bit of a flaw in assuming there are at least TWO strings in the initial list. Here is a version to try that works fine if you give it an empty list, just one item in a list, or any number of items. It is in a sense shorter and more general and possibly slower and will be explained below using a new function name of find_common_words_all: def find_common_words_all(strings): """ given a list of strings containing with 0 or more strings, returns a single string containing the words contained in every string as a space separated single string. """ # convert the list of strings to a list of sets containing # the unique words in each. word_lists = [set(s.split()) for s in strings] # Get the union of all the words and intersect that with ALL # the sets in the list including the first. The result is converted # to a single string containing the space separated words # in some order. Might be useful to sort them. return(' '.join(set().union(*word_lists).intersection(*word_lists))) The first non-comment line is similar to what was shown except it makes them all sets. The second line is a bit convoluted as it first constructs the union of all the sets by taking the union of an empty set with all the others. Then it invokes the intersection method on this maximal set using all the smaller sets and that is fed as an argument to a method for a string with a single space in it to ask the results to be joined into one string with that spacing between the items. All that is provided to be returned. I find it useful to return things like that sorted or in a predictable order. So here is a second version that adds a few steps to make the set into a list and sort it before the parts are recombined: def find_common_words_all_sorted(strings): """ given a list of strings containing with 0 or more strings, returns a single string containing the words contained in every string as a space separated single string. """ # convert the list of strings to a list of sets containing # the unique words in each. word_lists = [set(s.split()) for s in strings] # Get the union of all the words and intersect that with ALL # the sets in the list including the first. The result is converted # to a single string containing the space separated words # in some order. Results are sorted. return(' '.join(sorted(list(set(). union(*word_lists). intersection(*word_lists))))) Here is the result for various inputs starting with an empty list which returns an empty string, a list with one string that returns the items sorted, one with two strings containing the same items in different orders and so on to three or four including some with no intersection. It seems robust. And, yes, it can be written in many smaller steps. As far as I know, this does not break any of the requirements but I can be corrected. find_common_words_all_sorted([]) '' find_common_words_all_sorted(['a n d']) 'a d n' find_common_words_all_sorted(['a n d', 'd n a']) 'a d n' find_common_words_all_sorted(['a n d', 'r n a']) 'a n' find_common_words_all_sorted(['a n d', 'r n a', 'a b c']) 'a' find_common_words_all_sorted(['a n d', 'r n a', 'a b c', ' x y z']) '' - QQQ Sent with Proton Mail secure email. ------- Original Message ------- On Sunday, January 1st, 2023 at 3:51 PM, seraph wrote: > When I ran your code, it returned *banana. *You mentioned it should > return "banana > and orange." However, based on the example that you provided, it should > only return banana. > > strings = ['apple orange banana', 'orange banana grape', 'banana mango'] > > > The common word in these 3 groups is *banana *- not banana & orange. > > I hope this helps! > > Seraph > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor From paulf at quillandmouse.com Thu Jan 12 02:02:49 2023 From: paulf at quillandmouse.com (paulf at quillandmouse.com) Date: Thu, 12 Jan 2023 02:02:49 -0500 Subject: [Tutor] Arrow keys in subwindows Message-ID: <20230112020249.29cb41b0@yosemite.mars.lan> Folks: I can't seem to get the arrow keys (KEY_LEFT, KEY_RIGHT) to work in subwindows. I'm running Debian Linux with version 3.10.9 of Python. When I run my code using stdscr, arrow keys work just fine. I do a a key = stdscr.getch(), it registers the keys. But when I use a subwindow (key = mysubwin.getch()), they don't register. No exception dumped, but the arrow keys just don't register. Has anyone else seen this behavior, and can you explain it? Paul -- Paul M. Foster Personal Blog: http://noferblatz.com Company Site: http://quillandmouse.com Software Projects: https://gitlab.com/paulmfoster From alan.gauld at yahoo.co.uk Thu Jan 12 08:34:18 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 12 Jan 2023 13:34:18 +0000 Subject: [Tutor] Arrow keys in subwindows In-Reply-To: <20230112020249.29cb41b0@yosemite.mars.lan> References: <20230112020249.29cb41b0@yosemite.mars.lan> Message-ID: On 12/01/2023 07:02, paulf at quillandmouse.com wrote: > I can't seem to get the arrow keys (KEY_LEFT, KEY_RIGHT) to work in > subwindows. I'm running Debian Linux with version 3.10.9 of Python. > When I run my code using stdscr, arrow keys work just fine. I do a > a key = stdscr.getch(), it registers the keys. But when I use a > subwindow (key = mysubwin.getch()), they don't register. No exception > dumped, but the arrow keys just don't register. Just to clarify, this means you are using the curses library. Its always useful if you can post some real code that shows the problem in action, otherwise we are debugging blind. > Has anyone else seen this behavior, and can you explain it? I'm guessing that you initialise the main screen using the standard initscr() settings? And you used keypad() to enable the function keys. But when you create subwindows they have to be initialised separately and explicitly. So you need to call keypad() for each window where you want to read a function key (or mouse button) That's my best guess based on the minimal information available. I have a book on programming curses with Python available on Amazon for a minimal price, both kindle and paper vesions. https://www.amazon.co.uk/gp/product/B091B85B77/ref=dbs_a_def_rwt_hsch_vapi_tkin_p1_i2 -- 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 learn2program at gmail.com Thu Jan 12 17:53:44 2023 From: learn2program at gmail.com (Alan Gauld) Date: Thu, 12 Jan 2023 22:53:44 +0000 Subject: [Tutor] Arrow keys in subwindows In-Reply-To: <20230112111734.49900cc6@yosemite.mars.lan> References: <20230112020249.29cb41b0@yosemite.mars.lan> <20230112111734.49900cc6@yosemite.mars.lan> Message-ID: <183eb5d9-6eb2-6fc8-efec-13b95500dc02@yahoo.co.uk> On 12/01/2023 16:17, paulf at quillandmouse.com wrote: > I called stdscr.keypad(True), and then, within a class method, > called mwin = stdscr.subwin(...), and then mwin.keypad(True). That should work. > with it, and somehow it now worked. So, problem solved for now. Glad to hear it, althugh its always nice to know why! :-) >> >> I have a book on programming curses with Python available > > Actually, I have your ebook. In that case, thanks. I hope it proves helpful. The info on the function keys and keypad() is in the chapter on the Keyboard... -- 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 paulf at quillandmouse.com Thu Jan 12 11:17:34 2023 From: paulf at quillandmouse.com (paulf at quillandmouse.com) Date: Thu, 12 Jan 2023 11:17:34 -0500 Subject: [Tutor] Arrow keys in subwindows In-Reply-To: References: <20230112020249.29cb41b0@yosemite.mars.lan> Message-ID: <20230112111734.49900cc6@yosemite.mars.lan> On Thu, 12 Jan 2023 13:34:18 +0000 Alan Gauld via Tutor wrote: > On 12/01/2023 07:02, paulf at quillandmouse.com wrote: > > I can't seem to get the arrow keys (KEY_LEFT, KEY_RIGHT) to work in > > subwindows. I'm running Debian Linux with version 3.10.9 of Python. > > When I run my code using stdscr, arrow keys work just fine. I do a > > a key = stdscr.getch(), it registers the keys. But when I use a > > subwindow (key = mysubwin.getch()), they don't register. No > > exception dumped, but the arrow keys just don't register. > > Just to clarify, this means you are using the curses library. > Yes. At the top: "import curses". > Its always useful if you can post some real code that shows > the problem in action, otherwise we are debugging blind. > I thought about that, but it's a fair bit of code. However, I'll keep this in mind for the future. > > Has anyone else seen this behavior, and can you explain it? > > I'm guessing that you initialise the main screen using the > standard initscr() settings? And you used keypad() to > enable the function keys. > I called stdscr.keypad(True), and then, within a class method, called mwin = stdscr.subwin(...), and then mwin.keypad(True). And it didn't work, as described above (no arrow keys). So I grabbed the part of the code relevant to this, and put it in a separate file, and massaged it. That worked. Going back to the original code, I fiddled with it, and somehow it now worked. So, problem solved for now. For what it's worth, I wrote a whole bunch of curses test code in C years ago-- testing colors, menus, forms, etc. Worked fine. But it's probably been 19 years since then, and Python curses is just enough different (with OOP and such) that it's mildly difficult. > > > I have a book on programming curses with Python available > on Amazon for a minimal price, both kindle and paper vesions. > > https://www.amazon.co.uk/gp/product/B091B85B77/ref=dbs_a_def_rwt_hsch_vapi_tkin_p1_i2 > > > > Actually, I have your ebook. (Might buy the paperback too; I like physical media.) I'm only on the first chapter, though. I put a different question on the Debian list, and someone suggested your book and this list. So here I am. Thanks. Paul -- Paul M. Foster Personal Blog: http://noferblatz.com Company Site: http://quillandmouse.com Software Projects: https://gitlab.com/paulmfoster From paulf at quillandmouse.com Thu Jan 12 21:37:21 2023 From: paulf at quillandmouse.com (paulf at quillandmouse.com) Date: Thu, 12 Jan 2023 21:37:21 -0500 Subject: [Tutor] Arrow keys in subwindows In-Reply-To: <183eb5d9-6eb2-6fc8-efec-13b95500dc02@yahoo.co.uk> References: <20230112020249.29cb41b0@yosemite.mars.lan> <20230112111734.49900cc6@yosemite.mars.lan> <183eb5d9-6eb2-6fc8-efec-13b95500dc02@yahoo.co.uk> Message-ID: <20230112213721.3ba95294@yosemite.mars.lan> On Thu, 12 Jan 2023 22:53:44 +0000 Alan Gauld wrote: > > > On 12/01/2023 16:17, paulf at quillandmouse.com wrote: > > > I called stdscr.keypad(True), and then, within a class method, > > called mwin = stdscr.subwin(...), and then mwin.keypad(True). > > That should work. > > > with it, and somehow it now worked. So, problem solved for now. > > Glad to hear it, althugh its always nice to know why! :-) Actually, I think I found it. In one case, I was using getkey(), and in another, getch(). In some cases, like fetching single letters, getkey() worked fine. But for arrow keys and others, not. OTOH, getch() worked fine in all cases, as long as you put the result through ord(), or checked for KEY_LEFT, etc.. I had no idea I had used different methods in different places. Probably would have been good if I'd included the code in my email. ;-) Paul -- Paul M. Foster Personal Blog: http://noferblatz.com Company Site: http://quillandmouse.com Software Projects: https://gitlab.com/paulmfoster From cs at cskk.id.au Fri Jan 13 16:51:40 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 14 Jan 2023 08:51:40 +1100 Subject: [Tutor] Arrow keys in subwindows In-Reply-To: <20230112213721.3ba95294@yosemite.mars.lan> References: <20230112213721.3ba95294@yosemite.mars.lan> Message-ID: On 12Jan2023 21:37, paulf at quillandmouse.com wrote: >Actually, I think I found it. In one case, I was using getkey(), and in >another, getch(). In some cases, like fetching single letters, getkey() >worked fine. But for arrow keys and others, not. OTOH, getch() worked >fine in all cases, as long as you put the result through ord(), or >checked for KEY_LEFT, etc.. I had no idea I had used different methods >in different places. getch() and getkey() are supposed to do the same thing, except that getch() returns an int designating the key, and getkey() returns a string, which is a single character string for basic characters and a multicharacter string containing the key name for things like function keys and arrow keys. So you get some number>255 for the left arrow from getch() and the _string_ "KEY_LEFT" from getkey(). On my system here, curses.KEY_LEFT is 260. However, note that if you're comparing things, comparing an int to a string is permitted, it will just always be false. So I suspect you were comparing a string from getkey() with an int (because curses.KEY_LEFT is an int). And not matching. Using ord() is a mistake for multicharacter strings, but at least it will raise an exception so that mistake should show up for an arrow key. Cheers, Cameron Simpson From PythonList at DancesWithMice.info Sun Jan 15 18:22:02 2023 From: PythonList at DancesWithMice.info (dn) Date: Mon, 16 Jan 2023 12:22:02 +1300 Subject: [Tutor] First meeting of 2023 Message-ID: The Auckland Branch of the New Zealand Python Users' Group's first gathering of the new year! We're looking forward to meeting-up (virtually) on Wednesday, 1800 for 1830 NZST (0500/0530 UTC). The topic is "What would you like to do?" - both in the context of what would you like to do at the meeting AND planning what you'd like the PUG to achieve during the coming year. Please come along with ideas and questions. We're interested in your feedback of what has been successful in the past, and ideas for future activities and our group direction. It will also be a great opportunity to raise discussion points around your recent projects... Please RSVP at https://www.meetup.com/nzpug-auckland/events/njdjssyfccbxb/ Other NZPUG meetings scheduled: - Thu 19 Jan: Wellington, (in-person only) Danny Adair: how to write a browser plugin in Python (https://www.meetup.com/nzpug-wellington/events/qcbqbtyfccbzb/) - Wed 1 Feb: Auckland, Coding Evening: topic TBA (https://www.meetup.com/nzpug-auckland/events/hgxmwsyfcdbcb/) - Tue 7 Feb: Christchurch, first meeting of the year. (https://www.meetup.com/nzpug-christchurch/events/kscsxsyfcdbkb/) NB the stated days may be one-day 'ahead' if you live in a time-zone west of the Atlantic Ocean! Regards =dn (for Pete and DJ) -- You received this message because you are subscribed to the Google Groups "New Zealand Python User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to nzpug+unsubscribe at googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/nzpug/6a8c8f3f-954a-160e-bacf-7d773541b24d%40etelligence.info. -- Regards, =dn From lourenton07 at gmail.com Fri Jan 20 13:37:41 2023 From: lourenton07 at gmail.com (louis renton) Date: Fri, 20 Jan 2023 13:37:41 -0500 Subject: [Tutor] louis renton Message-ID: i'm a more hands on learner what are best and most efficient ways to learn to code From alan.gauld at yahoo.co.uk Sat Jan 21 04:01:01 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sat, 21 Jan 2023 09:01:01 +0000 Subject: [Tutor] louis renton In-Reply-To: References: Message-ID: Sent from my iPad > On 21 Jan 2023, at 01:52, louis renton wrote: > > ?i'm a more hands on learner what are best and most efficient ways to learn > to code It is hard to imagine any kind of programming tutorial that was not hands on. The key to learning to program is to write code, lots of it. Then modify it. And again. Observe the results. There are plenty of things you need to read about too, especially in terms of good practice and style but ultimately you can only learn to code by writing code. So basically pick one of the many tutorials available, read it and type the examples out(don?t just cut n paste!) then modify them and see if they do what you expect. If you don?t understand something then come back here and ask questions. Have fun. Alan g. On vacation? From paulf at quillandmouse.com Fri Jan 20 21:10:30 2023 From: paulf at quillandmouse.com (paulf at quillandmouse.com) Date: Fri, 20 Jan 2023 21:10:30 -0500 Subject: [Tutor] louis renton In-Reply-To: References: Message-ID: <20230120211030.0b50760e@yosemite.mars.lan> On Fri, 20 Jan 2023 13:37:41 -0500 louis renton wrote: > i'm a more hands on learner what are best and most efficient ways to > learn to code As a self-taught coder who started in 1974 coding mainframe BASIC, then Pascal, then C, then loads more, you figure out something (simple) you want to do, grab a reference on the language, and start coding. Code iteratively. That is, do a little, then gradually raise the complexity. Test after every iteration. If something breaks, find out why and fix it. As you continue, your confidence and familiarity will build from your successes. What you start out with is immaterial. Calculate interest amounts, generate prime numbers, whatever. It also helps to fetch some simple programs and examine the way they do it. A good and simple reference is important. Matter of fact, I've found Google to be invaluable. If you can't find it in your reference easily, Google it, and you'll find explanations and simple code examples. I'm relatively new to Python, and that's how I've done it. Also, there is a good reference for Python and its libraries on line. Look for it. Paul -- Paul M. Foster Personal Blog: http://noferblatz.com Company Site: http://quillandmouse.com Software Projects: https://gitlab.com/paulmfoster From PythonList at DancesWithMice.info Sat Jan 21 20:43:27 2023 From: PythonList at DancesWithMice.info (dn) Date: Sun, 22 Jan 2023 14:43:27 +1300 Subject: [Tutor] louis renton In-Reply-To: <20230120211030.0b50760e@yosemite.mars.lan> References: <20230120211030.0b50760e@yosemite.mars.lan> Message-ID: <42c7124a-5138-d02c-b59c-654a7d4b14ff@DancesWithMice.info> On 21/01/2023 15.10, paulf at quillandmouse.com wrote: > On Fri, 20 Jan 2023 13:37:41 -0500 > louis renton wrote: > >> i'm a more hands on learner what are best and most efficient ways to >> learn to code > > As a self-taught coder who started in 1974 coding mainframe BASIC, then > Pascal, then C, then loads more, you figure out something (simple) you > want to do, grab a reference on the language, and start coding. Code > iteratively. That is, do a little, then gradually raise the complexity. > Test after every iteration. If something breaks, find out why and fix > it. As you continue, your confidence and familiarity will build from > your successes. What you start out with is immaterial. Calculate > interest amounts, generate prime numbers, whatever. > > It also helps to fetch some simple programs and examine the way they do > it. > > A good and simple reference is important. Matter of fact, I've found > Google to be invaluable. If you can't find it in your reference easily, > Google it, and you'll find explanations and simple code examples. I'm > relatively new to Python, and that's how I've done it. Also, there is a > good reference for Python and its libraries on line. Look for it. Google is NOT a reference. What you will find listed is a collection of web-pages. Whether they are accurate or otherwise good or bad is open to question! See also: copying code from StackOverflow. The 'hit or miss' approach to learning does APPEAR to work for some people. It may better fit hobbyists than trainee-professionals. Whether an employer will be impressed is equally open to question. Some do look at project-portfolios. Do few?many?most job-adverts mention certification? A formal curriculum such as an on-line course or even a text-book has been designed to introduce topics in manageable chunks, to build upon existing knowledge, and thus to show how 'it all' hangs-together. YMMV! -- Regards, =dn From paulf at quillandmouse.com Sat Jan 21 21:05:06 2023 From: paulf at quillandmouse.com (paulf at quillandmouse.com) Date: Sat, 21 Jan 2023 21:05:06 -0500 Subject: [Tutor] louis renton In-Reply-To: <42c7124a-5138-d02c-b59c-654a7d4b14ff@DancesWithMice.info> References: <20230120211030.0b50760e@yosemite.mars.lan> <42c7124a-5138-d02c-b59c-654a7d4b14ff@DancesWithMice.info> Message-ID: <20230121210506.64e31bb9@yosemite.mars.lan> On Sun, 22 Jan 2023 14:43:27 +1300 dn via Tutor wrote: [snip] > > > > A good and simple reference is important. Matter of fact, I've found > > Google to be invaluable. If you can't find it in your reference > > easily, Google it, and you'll find explanations and simple code > > examples. I'm relatively new to Python, and that's how I've done > > it. Also, there is a good reference for Python and its libraries on > > line. Look for it. > > Google is NOT a reference. What you will find listed is a collection > of web-pages. Whether they are accurate or otherwise good or bad is > open to question! See also: copying code from StackOverflow. > Opinions apparently vary. I've found tons of useful explanations and working code from Google and Stackoverflow. "How to fetch a string from the user in Python" on Google yields useful help. Obviously, you have to copy or mimic and test to make sure stuff works. > > A formal curriculum such as an on-line course or even a text-book has > been designed to introduce topics in manageable chunks, to build upon > existing knowledge, and thus to show how 'it all' hangs-together. Doubtless a formal course of study is useful. However, my experience with academic texts (including those from my college years) has been less than stellar. My college calculus text was nearly unreadable, and I did well in high school math up through analytic geometry. This is partly why Amazon allows you a look into the book before you buy it, because a lot of them are just garbage. I've known plenty of academics who couldn't think their way out of a crossword puzzle. Paul -- Paul M. Foster Personal Blog: http://noferblatz.com Company Site: http://quillandmouse.com Software Projects: https://gitlab.com/paulmfoster From threesomequarks at proton.me Sat Jan 21 21:56:37 2023 From: threesomequarks at proton.me (ThreeBlindQuarks) Date: Sun, 22 Jan 2023 02:56:37 +0000 Subject: [Tutor] louis renton In-Reply-To: References: Message-ID: <8OCwWXSPZHDf4zWfT8DGiUAnSojuyHsDjw44sSsHWj_7W5hStbU-fO9Zw_nZdc_ePKriktUQd-cIHo5_KcFF57vzNIkUB8Z8cNpWGy85X6c=@proton.me> This is another wide-open question, Louis. You have not supplied any info to help anyone guide you. The best and most efficient way depends on you and your background and study abilities and much more. If you want to learn as a hobby, do anything you want. If you want a job, look at ways to get some form of credit or certification or at least save some projects you can show someone as samples of your work. People here could throw random books or online courses at you to choose from but many may not be relevant. I am currently reading a book on Fluent Python but although I am enjoying the book, it is not suitable for teaching basic python nor intended to. It assumes, correctly, that a person has a computer background and already can program decently and wants to learn more. Having read dozens of books on Python and written programs, it fits my wants and needs but not of lots of others. You need to figure out for yourself what works and I would start with free resources available to you ranging from Library textbooks which may be a tad dated but reasonable for a beginner, many on-line tutorials and even classes such as at COURSERA. I would not start by paying thousands of dollars unless you had some guarantee it would lead to employment. And please make sure the Python you learn and use is newer, as in version 3.0 and beyond. As has been stated, what makes something hands-on is YOU. If a course provides examples and assignments, you need to do them. Luckily, python is mainly interpreted and can offer immediate feedback and allow you to play with alternatives and get a good feel how it works. But it takes some getting used to as little details like indentation matter. So a good editing environment that knows about how Python formats code is a big plus. A tip, if you have programmed before but not in python, is to drop many of the earlier ideas and be open to the way Python programmers think and use the language. If you have no background, you need a much more basic course or textbook. Q Sent with Proton Mail secure email. ------- Original Message ------- On Friday, January 20th, 2023 at 1:37 PM, louis renton wrote: > i'm a more hands on learner what are best and most efficient ways to learn > to code > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor From leamhall at gmail.com Sun Jan 22 07:48:03 2023 From: leamhall at gmail.com (Leam Hall) Date: Sun, 22 Jan 2023 06:48:03 -0600 Subject: [Tutor] louis renton In-Reply-To: <20230121210506.64e31bb9@yosemite.mars.lan> References: <20230120211030.0b50760e@yosemite.mars.lan> <42c7124a-5138-d02c-b59c-654a7d4b14ff@DancesWithMice.info> <20230121210506.64e31bb9@yosemite.mars.lan> Message-ID: On 1/21/23 20:05, paulf at quillandmouse.com wrote: > On Sun, 22 Jan 2023 14:43:27 +1300 > dn via Tutor wrote: > > [snip] > >>> >>> A good and simple reference is important. Matter of fact, I've found >>> Google to be invaluable. If you can't find it in your reference >>> easily, Google it, and you'll find explanations and simple code >>> examples. I'm relatively new to Python, and that's how I've done >>> it. Also, there is a good reference for Python and its libraries on >>> line. Look for it. >> >> Google is NOT a reference. What you will find listed is a collection >> of web-pages. Whether they are accurate or otherwise good or bad is >> open to question! See also: copying code from StackOverflow. > Opinions apparently vary. I've found tons of useful explanations and > working code from Google and Stackoverflow. "How to fetch a string from > the user in Python" on Google yields useful help. Obviously, you have > to copy or mimic and test to make sure stuff works. As have I, but I haven't actually learned a language that way. Louis was asking about how to actually learn Python, not just find code snippets. >> A formal curriculum such as an on-line course or even a text-book has >> been designed to introduce topics in manageable chunks, to build upon >> existing knowledge, and thus to show how 'it all' hangs-together. > > Doubtless a formal course of study is useful. However, my experience > with academic texts (including those from my college years) has been > less than stellar. My college calculus text was nearly unreadable, and > I did well in high school math up through analytic geometry. This is > partly why Amazon allows you a look into the book before you buy it, > because a lot of them are just garbage. I've known plenty of academics > who couldn't think their way out of a crossword puzzle. > > Paul Yeah, a lot of textbooks are highly priced and useless. However, I've learned multiple languages and tools with good books from O'Reilly, Manning, and even Packt. The latter needs to find better editors, but some of their books are great. Dusty Phillips' book on Python 3 OOP, for example. I'm not as sold on formal education as dn is, but I have found a structured learning plan to be very useful. Google and Stack get you snippets, but there's more to Python that that. Given all the tech layoffs in the US, and the good publicity Python has gotten via the TIOBE index, a lot of folks are going to become "Python Developers". Hiring companies won't have good ways to sort out the cut-and-pasters from the actual students of the language, and we'll all suffer for it. dn and his Auckland crew are working to improve the learning portion of the community, and I applaud that. Leam -- Automation Engineer (reuel.net/resume) Scribe: The Domici War (domiciwar.net) General Ne'er-do-well (github.com/LeamHall) From PythonList at DancesWithMice.info Sun Jan 22 19:17:35 2023 From: PythonList at DancesWithMice.info (dn) Date: Mon, 23 Jan 2023 13:17:35 +1300 Subject: [Tutor] louis renton In-Reply-To: <20230121210506.64e31bb9@yosemite.mars.lan> References: <20230120211030.0b50760e@yosemite.mars.lan> <42c7124a-5138-d02c-b59c-654a7d4b14ff@DancesWithMice.info> <20230121210506.64e31bb9@yosemite.mars.lan> Message-ID: <2f89415b-3b5e-4bb3-7bb6-62c62e86ea99@DancesWithMice.info> On 22/01/2023 15.05, paulf at quillandmouse.com wrote: > On Sun, 22 Jan 2023 14:43:27 +1300 > dn via Tutor wrote: > > [snip] > >>> >>> A good and simple reference is important. Matter of fact, I've found >>> Google to be invaluable. If you can't find it in your reference >>> easily, Google it, and you'll find explanations and simple code >>> examples. I'm relatively new to Python, and that's how I've done >>> it. Also, there is a good reference for Python and its libraries on >>> line. Look for it. >> >> Google is NOT a reference. What you will find listed is a collection >> of web-pages. Whether they are accurate or otherwise good or bad is >> open to question! See also: copying code from StackOverflow. >> > > Opinions apparently vary. I've found tons of useful explanations and > working code from Google and Stackoverflow. "How to fetch a string from > the user in Python" on Google yields useful help. Obviously, you have > to copy or mimic and test to make sure stuff works. +1 but......... in order to decide if it is worth copying in the first place, and later to "test", one first needs a basis of knowledge. Some dispute this, saying that as long as they know where to find facts (Google?) why bother to learn them. However, learning is more than "facts". Per the OP's "hands on", it is knowing how to use what you know/can find-out, and actually proving that by doing-so. Question: if needed an operation, would you prefer a graduate of Med.School, or someone who is picking-up brain-surgery from different web-sites recommended by the GOOG? Learning to fetch a string is a great illustration of two aspects: 1 it is an isolated fact, ie input(); and being told, use: result = input( "prompt" ) doesn't teach much about strings or the likely constructs to do with and 'around' the uses of input(). Thus, isolated cf cohesive leads into asking: "what if I want to fetch an integer?". 'Stack-Overflow Driven Development' requires another search. Agreed, some answers do provide width and depth, but others stick strictly to the narrow question. If it were a cohesive lesson on terminal-input (as was one of my coaching-sessions at the local-PUG a few months back) then it would cover the above, including an explanation of the word "prompt", the building of a loop to cover mistakes in input (eg "ten" instead of a number), and what is/how to handle EOD through semaphore-values or the use of control-keys (which vary by OpSys). Chalk and cheese! 2 having completed a structured course, few of us remember everything - and few courses cover 'everything'. In addition, it may be that we work on Python, but don't use specific facilities for a long period. So, it IS useful to have a reminder: 'how do I use range() but not starting from zero?'. This is where having your own study notes, downloading "cheat sheets", or using Stack-Overflow (or this Mailing List's Archives) can be a 'treasure trove' (of knowledge) - and all without disturbing one's colleagues' concentration/"flow"! Have a look through some of my posts here. Partially because many don't know 'enough' to be able to frame a question without leaving-out necessary facts or leaving things open-ended; you will see that I frequently add reading references. Something to use to answer the question-posed, something for later, or something that is irrelevant to the poster's needs. Who knows? How to tell in-advance? (same conundrum faces courseware and book-authors!) >> A formal curriculum such as an on-line course or even a text-book has >> been designed to introduce topics in manageable chunks, to build upon >> existing knowledge, and thus to show how 'it all' hangs-together. > > Doubtless a formal course of study is useful. However, my experience > with academic texts (including those from my college years) has been > less than stellar. My college calculus text was nearly unreadable, and > I did well in high school math up through analytic geometry. This is > partly why Amazon allows you a look into the book before you buy it, > because a lot of them are just garbage. I've known plenty of academics > who couldn't think their way out of a crossword puzzle. +1 FWIW, I completely agree with you: some academics have no idea how to teach - and I had trouble with Calculus 101, too. You'll be familiar with the old adage: "you can't judge a book by its cover". Your local Librarian (note the title-case, and please be aware that some staff in a library are "Library Assistants") will be happy to discuss exactly this point: how readable is this book (for my level of expertise in the topic); and its related consideration: how applicable is this book to my own intentions, eg 'Python for Network Admin' cf 'Python for Machine Learning'. With books, courses, etc (including YouTube 'training videos'), just as with so many other aspects of life, there is no such thing as a "silver bullet"! One of the (possibly 'the') most popular Internet courses for learning to program[me] is offered by a 'top' US institution, but I look at the antiquated training techniques they use and wonder where the last fifty (or more) years went? Yet, they have higher (since first offered to-date total) attendance (- haven't compared success/pass-rates though - aspects of high drop-out rates, and attempting to counter same, a current research effort to which @Leam alludes, elsewhere). The yawning gulf in the above observations, is that if "academics" produce a range of work varying from 'impenetrable' to 'made it so easy', what is the equivalent success/failure measure for YouTube videos or web-posts? There are many 'experts' (largely self-appointed, ie no job application to an institution's employment panel, and with no editorial oversight or even a colleague's advice like a 'code review') who post material which seems to say far more about them than it does about Python (and not always in a good way, if we are judging an ability to impart information, use time efficiently, whilst also enthusing, etc, etc). There are some which are downright wrong - and therefore damaging. There are some which are truly excellent. (next proverb: sorting the wheat from the chaff!) Knowing something, and then being able to impart such knowledge to others, are quite different things! In short, we're back to the curation of material, firstly to assure quality, and secondly, to assemble some applicable sequence of 'chunks' of coverage to facilitate learning and ensure a reasonably/practically cohesive pattern of knowledge. Followed by an assessment of the material vis-a-vis one's personal needs and interests. In the case of complete ignorance about Python, pretty much any course or book which 'looks good' (per above, see also @Leam's list of reputable publishers from his experience) is a place to start. Once the new-learner has picked-up built-in types, functions, loops, etc (the 'core' of the language if you will*; (s)he is much better-equipped to review alternate materials - even to the point of 'dropping' the first and promoting him-/her-self to something heading-off in a more appropriate application of the language (for example). * and the subject of another local initiative called: "The When of Python" In the case of the OP: - proving one's learning by challenging yourself to produce some "hands on" application of new-knowledge is by-far the best way to learn/re-inforce new-knowledge - the phrase "learn to code" seems wider than "Python". Perhaps then, something which introduces computing or computer science may be more appropriate, eg Harvard CS50 (https://cs50.harvard.edu/x/2023/) which introduces ComSc "(Two thirds of CS50 students have never taken CS before.)" and in terms of programming languages introduces C, Python, SQL, and HTML5 with the aim of providing just-enough knowledge to facilitate a person's (deliberate choice of) next steps - and note how they list 'choices' of learning-path based upon different peoples' intentions and expectations! - as far as Python is concerned, two good starting places are: - The (official) Python Tutorial (https://docs.python.org/3/tutorial/index.html) which we (list members) have all used (or at least scanned), right? - @Alan's (our ListAdmin) own course, with the added advantage of being able to pose any follow-up questions 'here' and hear-back (content warning: another old adage) "straight from the horse's mouth". (when he gets back from holidays/vacation) (sorry Alan, please don't be an old nag at me...) Disclaimer: Harvard was one of the founding institutions for edX, since sold to 2U, but with the retention of (some) managerial oversight. I use the edX platform, but not for Python training. -- Regards, =dn From mats at wichmann.us Sun Jan 22 19:31:41 2023 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 22 Jan 2023 17:31:41 -0700 Subject: [Tutor] louis renton In-Reply-To: <2f89415b-3b5e-4bb3-7bb6-62c62e86ea99@DancesWithMice.info> References: <20230120211030.0b50760e@yosemite.mars.lan> <42c7124a-5138-d02c-b59c-654a7d4b14ff@DancesWithMice.info> <20230121210506.64e31bb9@yosemite.mars.lan> <2f89415b-3b5e-4bb3-7bb6-62c62e86ea99@DancesWithMice.info> Message-ID: On 1/22/23 17:17, dn via Tutor wrote: > +1 but......... > in order to decide if it is worth copying in the first place, and later > to "test", one first needs a basis of knowledge. > > Some dispute this, saying that as long as they know where to find facts > (Google?) why bother to learn them. However, learning is more than > "facts". Per the OP's "hands on", it is knowing how to use what you > know/can find-out, and actually proving that by doing-so. > > Question: if needed an operation, would you prefer a graduate of > Med.School, or someone who is picking-up brain-surgery from different > web-sites recommended by the GOOG? see all the furor about ChatGPT... some think it will make programmers obsolete because "AI will write your code for you, eliminating all the need for deep knowledge". But StackOverflow, which has its own detractors, bans answers generated by ChatGPT... From oscar.j.benjamin at gmail.com Sun Jan 22 19:50:34 2023 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 23 Jan 2023 00:50:34 +0000 Subject: [Tutor] louis renton In-Reply-To: References: <20230120211030.0b50760e@yosemite.mars.lan> <42c7124a-5138-d02c-b59c-654a7d4b14ff@DancesWithMice.info> <20230121210506.64e31bb9@yosemite.mars.lan> <2f89415b-3b5e-4bb3-7bb6-62c62e86ea99@DancesWithMice.info> Message-ID: On Mon, 23 Jan 2023 at 00:35, Mats Wichmann wrote: > > On 1/22/23 17:17, dn via Tutor wrote: > > > +1 but......... > > in order to decide if it is worth copying in the first place, and later > > to "test", one first needs a basis of knowledge. > > > > Some dispute this, saying that as long as they know where to find facts > > (Google?) why bother to learn them. However, learning is more than > > "facts". Per the OP's "hands on", it is knowing how to use what you > > know/can find-out, and actually proving that by doing-so. > > > > Question: if needed an operation, would you prefer a graduate of > > Med.School, or someone who is picking-up brain-surgery from different > > web-sites recommended by the GOOG? > > see all the furor about ChatGPT... some think it will make programmers > obsolete because "AI will write your code for you, eliminating all the > need for deep knowledge". But StackOverflow, which has its own > detractors, bans answers generated by ChatGPT... I think StackOverflow's reasons were in part very particular to their situation. From what I understand some people had promoted the idea that anyone could use ChatGPT to quickly gain "reputation". Then a lot of people blindly posted outputs from ChatGPT that were not helpful so SO banned it. I've seen something similar here: https://github.com/sympy/sympy/issues/24524#issuecomment-1383545797 That usage of ChatGPT is bad but isolated (I haven't seen any other occurrence) so not massively problematic in the way that I think it was for SO. -- Oscar From mats at wichmann.us Sun Jan 22 20:02:25 2023 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 22 Jan 2023 18:02:25 -0700 Subject: [Tutor] louis renton In-Reply-To: References: <20230120211030.0b50760e@yosemite.mars.lan> <42c7124a-5138-d02c-b59c-654a7d4b14ff@DancesWithMice.info> <20230121210506.64e31bb9@yosemite.mars.lan> <2f89415b-3b5e-4bb3-7bb6-62c62e86ea99@DancesWithMice.info> Message-ID: <62ddd3f7-6866-2efc-ca68-42a00b23fac6@wichmann.us> On 1/22/23 17:50, Oscar Benjamin wrote: > On Mon, 23 Jan 2023 at 00:35, Mats Wichmann wrote: > I think StackOverflow's reasons were in part very particular to their > situation. From what I understand some people had promoted the idea > that anyone could use ChatGPT to quickly gain "reputation". Then a lot > of people blindly posted outputs from ChatGPT that were not helpful so > SO banned it. I've seen something similar here: > https://github.com/sympy/sympy/issues/24524#issuecomment-1383545797 > That usage of ChatGPT is bad but isolated (I haven't seen any other > occurrence) so not massively problematic in the way that I think it > was for SO. I think the situation is a little related to what was claimed earlier in this thread (about "googling for stuff"), which is the only reason I brought it up: the answers may well be right, even of high quality. It's even possible that that's the case in a large majority of cases. But if you don't have the background to make that determination, how can you trust it? There have been lots of examples as people play around with the AI of the system being essentially "faked out" and getting something pretty dramatically wrong. From oscar.j.benjamin at gmail.com Sun Jan 22 20:35:31 2023 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Mon, 23 Jan 2023 01:35:31 +0000 Subject: [Tutor] louis renton In-Reply-To: <62ddd3f7-6866-2efc-ca68-42a00b23fac6@wichmann.us> References: <20230120211030.0b50760e@yosemite.mars.lan> <42c7124a-5138-d02c-b59c-654a7d4b14ff@DancesWithMice.info> <20230121210506.64e31bb9@yosemite.mars.lan> <2f89415b-3b5e-4bb3-7bb6-62c62e86ea99@DancesWithMice.info> <62ddd3f7-6866-2efc-ca68-42a00b23fac6@wichmann.us> Message-ID: On Mon, 23 Jan 2023 at 01:03, Mats Wichmann wrote: > > On 1/22/23 17:50, Oscar Benjamin wrote: > > On Mon, 23 Jan 2023 at 00:35, Mats Wichmann wrote: > > > I think StackOverflow's reasons were in part very particular to their > > situation. From what I understand some people had promoted the idea > > that anyone could use ChatGPT to quickly gain "reputation". Then a lot > > of people blindly posted outputs from ChatGPT that were not helpful so > > SO banned it. I've seen something similar here: > > https://github.com/sympy/sympy/issues/24524#issuecomment-1383545797 > > That usage of ChatGPT is bad but isolated (I haven't seen any other > > occurrence) so not massively problematic in the way that I think it > > was for SO. > > I think the situation is a little related to what was claimed earlier in > this thread (about "googling for stuff"), which is the only reason I > brought it up: the answers may well be right, even of high quality. > It's even possible that that's the case in a large majority of cases. > But if you don't have the background to make that determination, how can > you trust it? There have been lots of examples as people play around > with the AI of the system being essentially "faked out" and getting > something pretty dramatically wrong. To be clear in the context of the GitHub issue I linked above the answer was pure gibberish. I don't know what input was given to the AI but the output was worthless or completely irrelevant (I honestly don't understand what it is referring to). I don't understand the thought process of the person submitting it who later admitted their own lack of knowledge. The danger (and this was sort of SO's concern) is that actual human communication could become overwhelmed by these things. The flipside is that ChatGPT can be useful for various things. I've tested it and it can work okay and in some ways be more useful than a basic web search but when it's wrong it will confidently assert the wrong answer with no caveats or citations. That seems like a very dangerous thing to put in the hands of people who don't know what they're doing. -- Oscar From cs at cskk.id.au Sun Jan 22 20:43:59 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 23 Jan 2023 12:43:59 +1100 Subject: [Tutor] louis renton In-Reply-To: <62ddd3f7-6866-2efc-ca68-42a00b23fac6@wichmann.us> References: <62ddd3f7-6866-2efc-ca68-42a00b23fac6@wichmann.us> Message-ID: On 22Jan2023 18:02, Mats Wichmann wrote: >I think the situation is a little related to what was claimed earlier >in this thread (about "googling for stuff"), which is the only reason I >brought it up: the answers may well be right, even of high quality. >It's even possible that that's the case in a large majority of cases. >But if you don't have the background to make that determination, how >can you trust it? There have been lots of examples as people play >around with the AI of the system being essentially "faked out" and >getting something pretty dramatically wrong. I saw (with horror and amusement) the other day, this: https://pypi.org/project/stackoverflow/ Cheers, Cameron Simpson From paulf at quillandmouse.com Sun Jan 22 22:25:15 2023 From: paulf at quillandmouse.com (paulf at quillandmouse.com) Date: Sun, 22 Jan 2023 22:25:15 -0500 Subject: [Tutor] louis renton In-Reply-To: <2f89415b-3b5e-4bb3-7bb6-62c62e86ea99@DancesWithMice.info> References: <20230120211030.0b50760e@yosemite.mars.lan> <42c7124a-5138-d02c-b59c-654a7d4b14ff@DancesWithMice.info> <20230121210506.64e31bb9@yosemite.mars.lan> <2f89415b-3b5e-4bb3-7bb6-62c62e86ea99@DancesWithMice.info> Message-ID: <20230122222515.76a12afc@yosemite.mars.lan> On Mon, 23 Jan 2023 13:17:35 +1300 dn via Tutor wrote: > On 22/01/2023 15.05, paulf at quillandmouse.com wrote: > > On Sun, 22 Jan 2023 14:43:27 +1300 > > dn via Tutor wrote: > > > > [snip] No particular disagreement. When I was a kid, I was endlessly curious. I spent hours at the library. How do lasers work? What's the chemical composition of vinegar? How does a car engine operate? I once called a gun shop to find out what "caliber" really meant, because all the definitions I could find were so vague. In 1974, I got access to the school district's mainframe via an acoustic modem and teletype. I had the idea I'd like to make some programs, so I searched for what languages the computer knew. They had BASIC, which sounded like a good idea. I bought a book called "Basic Basic", and used it as a reference. What if I wanted to calculate how much a loan would cost at the end of the loan's term? How do you do math in BASIC? Blah blah blah. When I went to college, I asked around about what computer facilities their were. Unless you were a grad student, you had to punch cards and submit them to the crew at the comp center. Wait three days. Get back a printout of how you failed. I was used to near instantaneous, real time interaction with a computer. And now they wanted me to punch cards and wait days? Forget it. I never took a computer course. (Mea culpa. This was actually a bad decision. Had I started taking computer courses, I might have ended up with a computer science degree instead.) Then in about 1985 I bought my own desktop computer, and cast about for a way to make programs (I was actually an electrician at the time). I found this book/reference/compiler for a language called Pascal (Borland's Turbo Pascal). I thought of a thing I'd like to make, and I tried this, consulted the manual, refined it, etc. I wrote quite a few useful programs. My roommate liked to gamble in Vegas, and I wrote a program for him to practice blackjack with. But Pascal was a teaching language. I wanted a "real" programming language. I looked around and found C. Then I bought "The C Programming Language", the best language reference I've ever read. I wrote all kinds of programs in C, and was very comfortable with it. Still am. Somewhere in the 90s, I got a job coding FoxPro, which I did for a few years. Then I purchased a company and proceeded to write hundreds of thousands of lines of PHP code to run the internal infrastructure for the business-- payroll, AP, AR, customer relations, statistics, job tracking, etc. I've found learning most subjects far faster and more effective when I tackle it on my own. The only exception would be mathematics. That's me. There are others who simply can't do it without some structured class time. And yes, employers foolishly consider a degree more important than thousands of hours of real world experience. They also consider MCSCs superior to years of working with Linux. But I can tell you most Linux folks know more about networking than MCSCs ever will, at least back when I started using Linux. I'm not even a network admin, but I know more than most of the guys from my ISP who visit me to fix or replace my modems and routers. If you're one of those classroom folks, find a community college or an online resource, like some of those "dn" mentioned. The OP didn't sound like that type, so I advised him to do what I would do (and have done). If you need to get a job in programming, then by all means get a degree. You may not be able to program very well at the end (I can't say), but you'll be able to get a programming job (hopefully). It's also worth noting that just because someone hasn't done a full course of study in a language, that doesn't mean their code isn't good. Microsoft Windows is full of code written by guys with degrees in CS and courses in programming. But when I worked for a Microsoft shop back in the 90s, we had to wipe and reinstall every six months, because Windows took about that long to self destruct. Paul -- Paul M. Foster Personal Blog: http://noferblatz.com Company Site: http://quillandmouse.com Software Projects: https://gitlab.com/paulmfoster From paulf at quillandmouse.com Sun Jan 22 22:39:18 2023 From: paulf at quillandmouse.com (paulf at quillandmouse.com) Date: Sun, 22 Jan 2023 22:39:18 -0500 Subject: [Tutor] louis renton In-Reply-To: References: <20230120211030.0b50760e@yosemite.mars.lan> <42c7124a-5138-d02c-b59c-654a7d4b14ff@DancesWithMice.info> <20230121210506.64e31bb9@yosemite.mars.lan> <2f89415b-3b5e-4bb3-7bb6-62c62e86ea99@DancesWithMice.info> Message-ID: <20230122223918.0e81d683@yosemite.mars.lan> On Sun, 22 Jan 2023 17:31:41 -0700 Mats Wichmann wrote: > > see all the furor about ChatGPT... some think it will make > programmers obsolete because "AI will write your code for you, > eliminating all the need for deep knowledge". But StackOverflow, > which has its own detractors, bans answers generated by ChatGPT... > Something more alarming came across my radar recently. There is apparently some program or programs which will make musical arrangements for people, which they can then put on records, etc. Now if you're just some guy who wants to play around with this stuff, fair enough. The claim was that this could replace musicians. Of course that's silly. But the idea of some complete musical noob putting out a song and getting paid for it is frightening. Thousands of musicians and arrangers have spent decades honing their craft and producing incredible songs. And some pimply faced kid can just punch up a music AI on his computer and get paid millions for it? Of course, considering the state of "music" today, I have to wonder if it might not be an improvement. Paul -- Paul M. Foster Personal Blog: http://noferblatz.com Company Site: http://quillandmouse.com Software Projects: https://gitlab.com/paulmfoster From paulf at quillandmouse.com Sun Jan 22 22:29:54 2023 From: paulf at quillandmouse.com (paulf at quillandmouse.com) Date: Sun, 22 Jan 2023 22:29:54 -0500 Subject: [Tutor] louis renton In-Reply-To: References: <20230120211030.0b50760e@yosemite.mars.lan> <42c7124a-5138-d02c-b59c-654a7d4b14ff@DancesWithMice.info> <20230121210506.64e31bb9@yosemite.mars.lan> <2f89415b-3b5e-4bb3-7bb6-62c62e86ea99@DancesWithMice.info> Message-ID: <20230122222954.75d7c7ef@yosemite.mars.lan> On Sun, 22 Jan 2023 17:31:41 -0700 Mats Wichmann wrote: [snip] > > see all the furor about ChatGPT... some think it will make > programmers obsolete because "AI will write your code for you, > eliminating all the need for deep knowledge". But StackOverflow, > which has its own detractors, bans answers generated by ChatGPT... > I love claims like that. Back in the day, drum machines were going to replace drummers. And CDs would replace vinyl. Neither happened. Yes, drum machines are more common today. Yes, there are more CDs printed than vinyl records. But drummers and vinyl records are still around. I'm sure ChatGPT can produce working, maybe even optimized code. But there will still be programmers as long as there are computers. Paul -- Paul M. Foster Personal Blog: http://noferblatz.com Company Site: http://quillandmouse.com Software Projects: https://gitlab.com/paulmfoster From threesomequarks at proton.me Sun Jan 22 21:22:44 2023 From: threesomequarks at proton.me (ThreeBlindQuarks) Date: Mon, 23 Jan 2023 02:22:44 +0000 Subject: [Tutor] louis renton In-Reply-To: <2f89415b-3b5e-4bb3-7bb6-62c62e86ea99@DancesWithMice.info> References: <20230120211030.0b50760e@yosemite.mars.lan> <42c7124a-5138-d02c-b59c-654a7d4b14ff@DancesWithMice.info> <20230121210506.64e31bb9@yosemite.mars.lan> <2f89415b-3b5e-4bb3-7bb6-62c62e86ea99@DancesWithMice.info> Message-ID: After reading several messages here that suggest that not liking Calculus 101 is a required pre-requisite for learning Python, I must bow out of this conversation. Actually, my college did not use that numbering scheme and my calculus courses were called 3.2, 4.2, 5.2 and 10.1 and in later schools my courses tended to be at least 500 level, so I cannot say I liked, or disliked anything labeled 101. Now that the necessary humor has been attempted, and failed, may I ask a blindingly annoying question? Why among the many messages on the non-informative subject of "Louis Renton" have we not seen any messages from this aforementioned person who started this and has not yet replied in any way? I personally suggest the possibility we are once again being used by some party who sits back and watches endless uneducated debate after an overly broad question for whatever reasons appeal to them. Another good reason for me to bow out. No need to help anyone who does not participate in the process. Q-uit Sent with Proton Mail secure email. ------- Original Message ------- On Sunday, January 22nd, 2023 at 7:17 PM, dn via Tutor wrote: > On 22/01/2023 15.05, paulf at quillandmouse.com wrote: > > > On Sun, 22 Jan 2023 14:43:27 +1300 > > dn via Tutor tutor at python.org wrote: > > > > [snip] > > > > > > A good and simple reference is important. Matter of fact, I've found > > > > Google to be invaluable. If you can't find it in your reference > > > > easily, Google it, and you'll find explanations and simple code > > > > examples. I'm relatively new to Python, and that's how I've done > > > > it. Also, there is a good reference for Python and its libraries on > > > > line. Look for it. > > > > > > Google is NOT a reference. What you will find listed is a collection > > > of web-pages. Whether they are accurate or otherwise good or bad is > > > open to question! See also: copying code from StackOverflow. > > > > Opinions apparently vary. I've found tons of useful explanations and > > working code from Google and Stackoverflow. "How to fetch a string from > > the user in Python" on Google yields useful help. Obviously, you have > > to copy or mimic and test to make sure stuff works. > > > +1 but......... > in order to decide if it is worth copying in the first place, and later > to "test", one first needs a basis of knowledge. > > Some dispute this, saying that as long as they know where to find facts > (Google?) why bother to learn them. However, learning is more than > "facts". Per the OP's "hands on", it is knowing how to use what you > know/can find-out, and actually proving that by doing-so. > > Question: if needed an operation, would you prefer a graduate of > Med.School, or someone who is picking-up brain-surgery from different > web-sites recommended by the GOOG? > > > Learning to fetch a string is a great illustration of two aspects: > > 1 it is an isolated fact, ie input(); and being told, use: > > result = input( "prompt" ) > > doesn't teach much about strings or the likely constructs to do with and > 'around' the uses of input(). Thus, isolated cf cohesive leads into > asking: "what if I want to fetch an integer?". 'Stack-Overflow Driven > Development' requires another search. Agreed, some answers do provide > width and depth, but others stick strictly to the narrow question. If it > were a cohesive lesson on terminal-input (as was one of my > coaching-sessions at the local-PUG a few months back) then it would > cover the above, including an explanation of the word "prompt", the > building of a loop to cover mistakes in input (eg "ten" instead of a > number), and what is/how to handle EOD through semaphore-values or the > use of control-keys (which vary by OpSys). Chalk and cheese! > > 2 having completed a structured course, few of us remember everything - > and few courses cover 'everything'. In addition, it may be that we work > on Python, but don't use specific facilities for a long period. So, it > IS useful to have a reminder: 'how do I use range() but not starting > from zero?'. This is where having your own study notes, downloading > "cheat sheets", or using Stack-Overflow (or this Mailing List's > Archives) can be a 'treasure trove' (of knowledge) - and all without > disturbing one's colleagues' concentration/"flow"! > > Have a look through some of my posts here. Partially because many don't > know 'enough' to be able to frame a question without leaving-out > necessary facts or leaving things open-ended; you will see that I > frequently add reading references. Something to use to answer the > question-posed, something for later, or something that is irrelevant to > the poster's needs. Who knows? How to tell in-advance? > (same conundrum faces courseware and book-authors!) > > > > A formal curriculum such as an on-line course or even a text-book has > > > been designed to introduce topics in manageable chunks, to build upon > > > existing knowledge, and thus to show how 'it all' hangs-together. > > > > Doubtless a formal course of study is useful. However, my experience > > with academic texts (including those from my college years) has been > > less than stellar. My college calculus text was nearly unreadable, and > > I did well in high school math up through analytic geometry. This is > > partly why Amazon allows you a look into the book before you buy it, > > because a lot of them are just garbage. I've known plenty of academics > > who couldn't think their way out of a crossword puzzle. > > > +1 > FWIW, I completely agree with you: some academics have no idea how to > teach - and I had trouble with Calculus 101, too. > > You'll be familiar with the old adage: "you can't judge a book by its > cover". Your local Librarian (note the title-case, and please be aware > that some staff in a library are "Library Assistants") will be happy to > discuss exactly this point: how readable is this book (for my level of > expertise in the topic); and its related consideration: how applicable > is this book to my own intentions, eg 'Python for Network Admin' cf > 'Python for Machine Learning'. > > With books, courses, etc (including YouTube 'training videos'), just as > with so many other aspects of life, there is no such thing as a "silver > bullet"! One of the (possibly 'the') most popular Internet courses for > learning to program[me] is offered by a 'top' US institution, but I look > at the antiquated training techniques they use and wonder where the last > fifty (or more) years went? Yet, they have higher (since first offered > to-date total) attendance (- haven't compared success/pass-rates though > - aspects of high drop-out rates, and attempting to counter same, a > current research effort to which @Leam alludes, elsewhere). > > > The yawning gulf in the above observations, is that if "academics" > produce a range of work varying from 'impenetrable' to 'made it so > easy', what is the equivalent success/failure measure for YouTube videos > or web-posts? There are many 'experts' (largely self-appointed, ie no > job application to an institution's employment panel, and with no > editorial oversight or even a colleague's advice like a 'code review') > who post material which seems to say far more about them than it does > about Python (and not always in a good way, if we are judging an ability > to impart information, use time efficiently, whilst also enthusing, etc, > etc). > > There are some which are downright wrong - and therefore damaging. There > are some which are truly excellent. > (next proverb: sorting the wheat from the chaff!) > > Knowing something, and then being able to impart such knowledge to > others, are quite different things! > > > In short, we're back to the curation of material, firstly to assure > quality, and secondly, to assemble some applicable sequence of 'chunks' > of coverage to facilitate learning and ensure a reasonably/practically > cohesive pattern of knowledge. Followed by an assessment of the material > vis-a-vis one's personal needs and interests. > > In the case of complete ignorance about Python, pretty much any course > or book which 'looks good' (per above, see also @Leam's list of > reputable publishers from his experience) is a place to start. Once the > new-learner has picked-up built-in types, functions, loops, etc (the > 'core' of the language if you will*; (s)he is much better-equipped to > review alternate materials - even to the point of 'dropping' the first > and promoting him-/her-self to something heading-off in a more > appropriate application of the language (for example). > > * and the subject of another local initiative called: "The When of Python" > > > In the case of the OP: > - proving one's learning by challenging yourself to produce some "hands > on" application of new-knowledge is by-far the best way to > learn/re-inforce new-knowledge > - the phrase "learn to code" seems wider than "Python". Perhaps then, > something which introduces computing or computer science may be more > appropriate, eg Harvard CS50 (https://cs50.harvard.edu/x/2023/) which > introduces ComSc "(Two thirds of CS50 students have never taken CS > before.)" and in terms of programming languages introduces C, Python, > SQL, and HTML5 with the aim of providing just-enough knowledge to > facilitate a person's (deliberate choice of) next steps - and note how > they list 'choices' of learning-path based upon different peoples' > intentions and expectations! > - as far as Python is concerned, two good starting places are: > - The (official) Python Tutorial > (https://docs.python.org/3/tutorial/index.html) which we (list members) > have all used (or at least scanned), right? > - @Alan's (our ListAdmin) own course, with the added advantage of > being able to pose any follow-up questions 'here' and hear-back (content > warning: another old adage) "straight from the horse's mouth". (when he > gets back from holidays/vacation) > (sorry Alan, please don't be an old nag at me...) > > > Disclaimer: > Harvard was one of the founding institutions for edX, since sold to 2U, > but with the retention of (some) managerial oversight. I use the edX > platform, but not for Python training. > > -- > Regards, > =dn > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor From phillor9 at gmail.com Fri Jan 27 01:10:08 2023 From: phillor9 at gmail.com (Phil) Date: Fri, 27 Jan 2023 16:10:08 +1000 Subject: [Tutor] Tkinter and after() method Message-ID: <918cf5d0-3492-c9ae-7de6-5435f839c036@gmail.com> It's been quite some time since I've played with Tkinter and despite searching the Internet for most of the day I seem to have hit a dead-end. I'm trying to put a pause within a for-loop as follows: def my_function(self): ??? for i in range(5): ??????? do something here eg. print(i) ??????? self.after(1000) Instead of printing i every second my_function is delayed for 5 seconds. To try to get some understanding of what's required I tried this: self.r = 31 self.abc() self.print_count() self.after(1000, self.print_count() def abc(self): ??? self.r += 1 ??? print(self.r) def print_count(self) ??? self.abc() ??? self.after(1000, self.print_count() This prints 32 - 1025, without a one second delay, before the programme ends with: "RecursionError: maximum recursion depth exceeded while calling a Python object". Although I haven't tried it I suspect that if I used a label to display the count rather than a print statement then I might not see a recursion error. I probably should try that before posting this but I've got a splitting headache and it hasn't helped with my original delay within a for_loop problem. -- Regards, Phil From phillor9 at gmail.com Fri Jan 27 01:32:12 2023 From: phillor9 at gmail.com (Phil) Date: Fri, 27 Jan 2023 16:32:12 +1000 Subject: [Tutor] Re my earlier question about after() Message-ID: I found the answer to the second part of my question, instead of self.after(1000, self.print_count() it should be self.after(1000, self.print_count). So please ignore all after how do I insert a delay within a for_loop. -- Regards, Phil From alan.gauld at yahoo.co.uk Fri Jan 27 05:17:52 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 27 Jan 2023 10:17:52 +0000 Subject: [Tutor] Tkinter and after() method In-Reply-To: <918cf5d0-3492-c9ae-7de6-5435f839c036@gmail.com> References: <918cf5d0-3492-c9ae-7de6-5435f839c036@gmail.com> Message-ID: On 27/01/2023 06:10, Phil wrote: > It's been quite some time since I've played with Tkinter and despite > searching the Internet for most of the day I seem to have hit a dead-end. > > I'm trying to put a pause within a for-loop as follows: > > def my_function(self): > ??? for i in range(5): > ??????? do something here eg. print(i) > ??????? self.after(1000) > It really helps if you show us working code. It need not be your own application but just a simple model of your code structure that exhibits the same behaviour. In this case I assume the "functin" is actually a method of your App or GUI or window object? (A method is not the same as a fuction with a self parameter!) If thats the case calling after inside a for loop is extremely bad practice and quite likely to cause your GUI to freeze which is a very bad user experience. > Instead of printing i every second my_function is delayed for 5 seconds. I'm not sure why because I don't see anything that could be tested. > To try to get some understanding of what's required I tried this: > > self.r = 31 > > self.abc() > self.print_count() > self.after(1000, self.print_count() > > def abc(self): > ??? self.r += 1 > ??? print(self.r) > > def print_count(self) > ??? self.abc() > ??? self.after(1000, self.print_count() That makes no sense whatsoever. What context did you try that in? Is it inside another method? In which case your abc() and print_count() methods only exist inside that method? If you defined it somewhere else what does the outer self refer to? > This prints 32 - 1025, without a one second delay, before the programme > ends with: "RecursionError: maximum recursion depth exceeded while > calling a Python object". No surprise on the error because print_count calls print_count forever. Why there is no delay may depend on the code we can't see. > Although I haven't tried it I suspect that if I used a label to display > the count rather than a print statement then I might not see a recursion > error. Yes you wouyld. You never terminate the recursion so it will keep going till it reaches the limit. I think you should try using after() in a more conventional split-method way rather than continue with this approach. It is almost certain to end badly. Here is a simple program that does what I think you want: import tkinter as tk count = 0 def run_loop(): global count if count < 5: count += 1 print_count(count) else: count = 0 def print_count(val): print(val) top.after(1000, run_loop) top = tk.Tk() F = tk.Frame(top) B = tk.Button(F, text="DoIt", command = run_loop) B.pack() F.pack() top.mainloop() -- 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 Fri Jan 27 17:55:05 2023 From: phillor9 at gmail.com (Phil) Date: Sat, 28 Jan 2023 08:55:05 +1000 Subject: [Tutor] Tkinter and after() method In-Reply-To: References: <918cf5d0-3492-c9ae-7de6-5435f839c036@gmail.com> Message-ID: <6645a6e9-2751-16ef-b6e6-0263c5c204d1@gmail.com> On 27/1/23 20:17, Alan Gauld via Tutor wrote: > If thats the case calling after inside a for loop is > extremely bad practice and quite likely to cause your > GUI to freeze which is a very bad user experience. Thank you Alan for your reply and example code. The GUI did freeze, however, at the time of posting my question I couldn't think of a better method. I posted a second message about half an hour latter after I discovered a syntax error which solved the recursion error (that was only test code and nothing to do with my project) but not the freezing GUI. The answer came to me at around 3:00 AM and I have now removed the for-loop so the problem has been solved. I must resist the urge to post a plea for help whenever a problem frustrates me. >> To try to get some understanding of what's required I tried this: >> >> self.r = 31 >> >> self.abc() >> self.print_count() >> self.after(1000, self.print_count() >> >> def abc(self): >> ??? self.r += 1 >> ??? print(self.r) >> >> def print_count(self) >> ??? self.abc() >> ??? self.after(1000, self.print_count() > That makes no sense whatsoever. I can see why my test example code caused you to think that. As I said in my second posting after I removed "self.print_count()" and corrected self.after(1000, self.print_count()) to self.after(1000, self.print_count) the test worked. Anyway, thank you again for taking the trouble to reply to my confusing question. -- Regards, Phil From phillor9 at gmail.com Mon Jan 30 20:39:45 2023 From: phillor9 at gmail.com (Phil) Date: Tue, 31 Jan 2023 11:39:45 +1000 Subject: [Tutor] Tkinter and after() method In-Reply-To: References: <918cf5d0-3492-c9ae-7de6-5435f839c036@gmail.com> Message-ID: On 27/1/23 20:17, Alan Gauld via Tutor wrote: > > It really helps if you show us working code. This brings me to another question which I really hesitate to ask. As I said in my previous reply to this thread I have the project working but there is a design flaw that prevents me from making further enhancements plus I have used three global variables to get around a problem but the resulting code seems to be a bit sloppy. The Tkinter project is 128 lines in length plus a class file of 15 lines. Would anyone be interested is reviewing the code? There won't be any hard feelings and I understand completely if the answer is no. -- Regards, Phil From cs at cskk.id.au Mon Jan 30 20:49:53 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 31 Jan 2023 12:49:53 +1100 Subject: [Tutor] Tkinter and after() method In-Reply-To: References: Message-ID: On 31Jan2023 11:39, Phil wrote: >The Tkinter project is 128 lines in length plus a class file of 15 >lines. > >Would anyone be interested is reviewing the code? There won't be any >hard feelings and I understand completely if the answer is no. Feel free to post it. Can you also describe the design issue and the enhancement it blocks? Usually globals are to be avoided; normally I put state in an instance of a class and pass the class instance around. Cheers, Cameron Simpson From phillor9 at gmail.com Tue Jan 31 00:46:54 2023 From: phillor9 at gmail.com (Phil) Date: Tue, 31 Jan 2023 15:46:54 +1000 Subject: [Tutor] Tkinter and after() method In-Reply-To: References: Message-ID: <138d6531-9e76-49f3-1425-ae2486f8e82d@gmail.com> On 31/1/23 11:49, Cameron Simpson wrote: > On 31Jan2023 11:39, Phil wrote: >> The Tkinter project is 128 lines in length plus a class file of 15 >> lines. >> >> Would anyone be interested is reviewing the code? There won't be any >> hard feelings and I understand completely if the answer is no. > > Feel free to post it. Can you also describe the design issue and the > enhancement it blocks? Thank you Cameron. The most glaring flaw is that I cannot display multiple dials. I can see why but I'm not sure how to fix the flaw. Even though it runs without error, It's starting to get overly complex. This is the analogue dial class as it is at the moment: class Dial: ??? def __init__(self, x=60, y=60, size=60): ??????? self.x = x? # centre of dial ??????? self.y = y ??????? self.size = size # the diameter of the dial ??????? self.xn = self.x + 1 # the end points of the ticks and pointer ??????? self.yn = self.y + 1 ??????? self.value = 0 # the pointer's value This shows an example of how I might use the dial class: import tkinter as tk import math import dial my_frame = None # these variables allow use where the original is out of scope my_dial = None??? # I cannot see an alternative to their use at the moment my_canvas = None class Root(tk.Tk): ??? def __init__(self): ??????? super().__init__() ??????? self.title("Canvas Template") ??????? self.frame = tk.Frame(self, background='cornflowerblue') ??????? self.frame.pack(side='top', fill='both', expand=True) ??????? global my_frame, my_dial, my_canvas ??????? my_frame = self.frame ??????? self.canvas = tk.Canvas( ??????????? self.frame, relief='flat', background='lightgrey') ??????? self.canvas.pack(side='top', anchor='center', fill='both', ???????????????????????? expand=True, padx=10, pady=10) ??????? my_canvas = self.canvas ??????? self.quit_button = tk.Button(self, text="Quit", command=self.quit) ??????? self.quit_button.pack(side=tk.BOTTOM, anchor='se', padx=10, pady=10) ??????? self.dial = dial.Dial(180, 160, 120) ??????? my_dial = self.dial ??????? draw_dial(self.dial, self.canvas) ??????? move_pointer(self.dial, self.canvas) ??????? loop() def draw_dial(the_dial, canvasName): ??? x = the_dial.x????????? # the centre of the circle ??? y = the_dial.y ??? r = the_dial.size / 2?? # the radius of the circle ??? x0 = x - r ??? y0 = y - r ??? x1 = x + r ??? y1 = y + r ??? canvasName.create_oval(x0, y0, x1, y1) ??? # draw the ticks around the circle's edge ??? tick_length = the_dial.size / 2 ??? for tick in range(0, 101, 10): ??????? theta = tick * 2.7 - 45 ??????? theta_rad = math.radians(theta) ??????? yn = -int(tick_length * math.sin(theta_rad)) ??????? xn = -int(tick_length * math.cos(theta_rad)) ??????? canvasName.create_line(the_dial.x, the_dial.y, ?????????????????????????????? xn + the_dial.x, the_dial.y + yn) ??????? # shorten ticks ??????? x = the_dial.x ??????? y = the_dial.y ??????? r = the_dial.size / 2.7 ??????? x0 = x - r ??????? y0 = y - r ??????? x1 = x + r ??????? y1 = y + r ??????? canvasName.create_oval( ??????????? x0, y0, x1, y1, fill='lightgrey', outline='lightgrey') def move_pointer(the_dial, canvasName): ??? # this is just a test. In real use the_dial.value woule be supplied with ??? # a value from a serial device ??? pointer_length = the_dial.size * .3 ??? # erase the pointer ??? drawPointer(the_dial.x, the_dial.y, the_dial.xn + the_dial.x, ??????????????? the_dial.y + the_dial.yn, 1, canvasName) ??? theta = the_dial.value * 2.7 - 45 ??? theta_rad = math.radians(theta) ??? the_dial.yn = -int(pointer_length * math.sin(theta_rad)) ??? the_dial.xn = -int(pointer_length * math.cos(theta_rad)) ??? # draw the pointer in its new position ??? drawPointer(the_dial.x, the_dial.y, the_dial.xn + the_dial.x, ??????????????? the_dial.y + the_dial.yn, 0, canvasName) ??? # draw dial centre ??? x = the_dial.x ??? y = the_dial.y ??? r = 4 ??? x0 = x - r ??? y0 = y - r ??? x1 = x + r ??? y1 = y + r ??? canvasName.create_oval(x0, y0, x1, y1, fill='black') def drawPointer(x_centre, y_centre, x_end, y_end, fill, canvasName): ??? if fill == 1: ??????? colour = 'lightgrey' ??? else: ??????? colour = 'black' ??? canvasName.create_line( ??????? x_centre, y_centre, x_end, y_end, fill=colour) def loop(): ??? # again, this only for testing ??? global my_dial, my_canvas ??? my_dial.value += 10? # change the pointer position by 10% ??? if my_dial.value > 100: ??????? my_dial.value = 0 ??? move_pointer(my_dial, my_canvas) ??? my_frame.after(1000, loop) if __name__ == "__main__": ??? root = Root() ??? root.mainloop() -- Regards, Phil From cs at cskk.id.au Tue Jan 31 16:27:10 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 1 Feb 2023 08:27:10 +1100 Subject: [Tutor] Tkinter and after() method In-Reply-To: <138d6531-9e76-49f3-1425-ae2486f8e82d@gmail.com> References: <138d6531-9e76-49f3-1425-ae2486f8e82d@gmail.com> Message-ID: On 31Jan2023 15:46, Phil wrote: >Thank you Cameron. The most glaring flaw is that I cannot display >multiple dials. I can see why but I'm not sure how to fix the flaw. >Even though it runs without error, It's starting to get overly complex. As you suspect, using a global limits your flexibility. How about having the dial instance do its own ticker loop? Untested example: class Dial: ??? def __init__(self, frame, canvasName, x=60, y=60, size=60): self.frame = frame ??????? self.canvasName = canvasName self.x = x? # centre of dial ??????? self.y = y ??????? self.size = size # the diameter of the dial ??????? self.xn = self.x + 1 # the end points of the ticks and pointer ??????? self.yn = self.y + 1 ??????? self.value = 0 # the pointer's value self.loop() def loop(self): ??? self.value += 10? # change the pointer position by 10% ??? if self.value > 100: ??????? self.value = 0 ??? move_pointer(self, self.canvasName) ??? self.frame.after(1000, self.loop) Note that last line: `self.loop` is a reference to the `loop()` method for this particuar dial. The initialisation of the Dial kicks off the first execution of that `loop()`, as you _were_ doing in `Root.__init__` but now should do here, thus once per Dial as made. Then intialise your dial with the addition of the frame and canvasName, and do that in Root.__init__. That lets you drop the globals entirely. The basic pattern here is that all the relevant state is stored with the Dial, and thus you can independently have many dials. Frankly, I've have move_pointer() _also_ be a method of Dial. Cheers, Cameron Simpson From fatani.melinda at gmail.com Tue Jan 31 18:40:21 2023 From: fatani.melinda at gmail.com (Melinda Fatani) Date: Tue, 31 Jan 2023 16:40:21 -0700 Subject: [Tutor] question about Scribe window Message-ID: I am working virtually with an elementary student trying to learn Python. We are following a interactive curriculum I found on Twinkle.com. Things are going well, but my student can't open a Scribe window. We made sure that we have the latest Python download, but there is no bar at the top of his IDLE window to open a Scribe window. Is there a way to do that, if it doesn't show the tool bar at the top? Melinda From alan.gauld at yahoo.co.uk Tue Jan 31 20:10:00 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 1 Feb 2023 01:10:00 +0000 Subject: [Tutor] Tkinter and after() method In-Reply-To: <138d6531-9e76-49f3-1425-ae2486f8e82d@gmail.com> References: <138d6531-9e76-49f3-1425-ae2486f8e82d@gmail.com> Message-ID: On 31/01/2023 05:46, Phil wrote: > This is the analogue dial class as it is at the moment: > > class Dial: > ??? def __init__(self, x=60, y=60, size=60): > > ??????? self.x = x? # centre of dial > ??????? self.y = y > ??????? self.size = size # the diameter of the dial > > ??????? self.xn = self.x + 1 # the end points of the ticks and pointer > ??????? self.yn = self.y + 1 > > ??????? self.value = 0 # the pointer's value Where are the methods? An object that has no operations is just data... > my_dial = None??? # I cannot see an alternative to their use at the moment > my_canvas = None Why not make them attributes of your root class? After all the Root class actually represents your application does it not? > class Root(tk.Tk): > ??? def __init__(self): > ??????? super().__init__() > ??????? self.title("Canvas Template") > > ??????? self.frame = tk.Frame(self, background='cornflowerblue') > ??????? self.frame.pack(side='top', fill='both', expand=True) > > ??????? global my_frame, my_dial, my_canvas > ??????? my_frame = self.frame > > ??????? self.canvas = tk.Canvas( > ??????????? self.frame, relief='flat', background='lightgrey') > > ??????? self.canvas.pack(side='top', anchor='center', fill='both', > ???????????????????????? expand=True, padx=10, pady=10) > > ??????? my_canvas = self.canvas > > ??????? self.quit_button = tk.Button(self, text="Quit", command=self.quit) > ??????? self.quit_button.pack(side=tk.BOTTOM, anchor='se', padx=10, > pady=10) > > ??????? self.dial = dial.Dial(180, 160, 120) > > ??????? my_dial = self.dial > > ??????? draw_dial(self.dial, self.canvas) > > ??????? move_pointer(self.dial, self.canvas) > > ??????? loop() > > > def draw_dial(the_dial, canvasName): Why is this not a method of the dial class. "the_dial" being self... And canvasName is not really a name but a canvas so why not call it so: class Dial: def __init__(...)... def draw(self,aCanvas):... > def move_pointer(the_dial, canvasName): > ??? # this is just a test. In real use the_dial.value woule be supplied > with > ??? # a value from a serial device Again a method of dial... > def drawPointer(x_centre, y_centre, x_end, y_end, fill, canvasName): Again a Dial method. The coordinates should be known to the dial hopefully? > def loop(): > ??? # again, this only for testing But could be a method of Root? Then your globals become self.my_dial etc. -- 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 alan.gauld at yahoo.co.uk Tue Jan 31 20:15:13 2023 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 1 Feb 2023 01:15:13 +0000 Subject: [Tutor] question about Scribe window In-Reply-To: References: Message-ID: On 31/01/2023 23:40, Melinda Fatani wrote: > are going well, but my student can't open a Scribe window. We made sure > that we have the latest Python download, but there is no bar at the top of > his IDLE window to open a Scribe window. Is there a way to do that, if it > doesn't show the tool bar at the top? I'm going to guess that you are using a Mac? The mac version of IDLE does not have a toolbar (I don't undertand why since IDLE is a Tkinter app so shuld be platform independent!) To get a new "Edit" window - which is what I assume you mean by "scribe"? - just use the menubar and the File->New File menu item. This will open a new empty editor window. If you are not using a Mac, or that doesn't work, then please respond with more details of OS, Python version and a URL for the course you are following. -- 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 Tue Jan 31 20:51:40 2023 From: phillor9 at gmail.com (Phil) Date: Wed, 1 Feb 2023 11:51:40 +1000 Subject: [Tutor] Tkinter and after() method In-Reply-To: References: <138d6531-9e76-49f3-1425-ae2486f8e82d@gmail.com> Message-ID: <08c56c52-fbb1-ab19-81fa-82f2a0dec539@gmail.com> On 1/2/23 07:27, Cameron Simpson wrote: > > As you suspect, using a global limits your flexibility. > > How about having the dial instance do its own ticker loop? Untested > example: Thank you Cameron, > > class Dial: > ??? def __init__(self, frame, canvasName, x=60, y=60, size=60): > ??????? self.frame = frame > ??????? self.canvasName = canvasName > ??????? self.x = x? # centre of dial > ??????? self.y = y > ??????? self.size = size # the diameter of the dial > ??????? self.xn = self.x + 1 # the end points of the ticks and pointer > ??????? self.yn = self.y + 1 > ??????? self.value = 0 # the pointer's value > ??????? self.loop() > > ??? def loop(self): > ??? ??? self.value += 10? # change the pointer position by 10% > ??? ??? if self.value > 100: > ??? ??????? self.value = 0 > ??? ??? move_pointer(self, self.canvasName) > ??? ??? self.frame.after(1000, self.loop) > > Note that last line: `self.loop` is a reference to the `loop()` method > for this particuar dial. The initialisation of the Dial kicks off the > first execution of that `loop()`, as you _were_ doing in > `Root.__init__` but now should do here, thus once per Dial as made. > > Then intialise your dial with the addition of the frame and > canvasName, and do that in Root.__init__. That lets you drop the > globals entirely. I see, doesn't that limit the class to only work with Tkinter, and is that normal practise? I try to make my classes universal so that they can be used with Tkinter and Wxpython. At the moment I'll be happy if the Dial class only works with Tkinter. The basic pattern here is that all the relevant state is stored with the Dial, and thus you can independently have many dials. > > Frankly, I've have move_pointer() _also_ be a method of Dial. I'm part way through a frustrating plumbing job on my motorhome so I probably won't get back to programming until tomorrow. In the meantime I'll give your suggestions some thought. Moving frame and canvasName to Dial certainly seems like a good idea. -- Regards, Phil From phillor9 at gmail.com Tue Jan 31 21:11:49 2023 From: phillor9 at gmail.com (Phil) Date: Wed, 1 Feb 2023 12:11:49 +1000 Subject: [Tutor] Tkinter and after() method In-Reply-To: References: <138d6531-9e76-49f3-1425-ae2486f8e82d@gmail.com> Message-ID: <7882b9ad-b51d-b64c-d85e-05512a77d174@gmail.com> On 1/2/23 11:10, Alan Gauld via Tutor wrote: > > Where are the methods? > An object that has no operations is just data... I was coming to that, it's still work in progress. >> my_dial = None??? # I cannot see an alternative to their use at the moment >> my_canvas = None > Why not make them attributes of your root class? > After all the Root class actually represents your > application does it not? That's how they were but they weren't visible to functions outside the root class. I'll give this more thought. def draw_dial(the_dial, canvasName): > Why is this not a method of the dial class. "the_dial" being self... > And canvasName is not really a name but a canvas so why not call it so: > > class Dial: > > def __init__(...)... > def draw(self,aCanvas):... > >> def move_pointer(the_dial, canvasName): >> ??? # this is just a test. In real use the_dial.value woule be supplied >> with >> ??? # a value from a serial device > Again a method of dial... > >> def drawPointer(x_centre, y_centre, x_end, y_end, fill, canvasName): > Again a Dial method. > The coordinates should be known to the dial hopefully? > >> def loop(): >> ??? # again, this only for testing > But could be a method of Root? > Then your globals become > self.my_dial etc. > Thank you Alan, I thought it would be best to have the canvas drawing routines included in the root class and not the Dial class, but I see your point. Much along the lines of Cameron's suggestions. I've got to get back to my plumbing job otherwise I'll be in more trouble. -- Regards, Phil From cs at cskk.id.au Tue Jan 31 21:35:48 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 1 Feb 2023 13:35:48 +1100 Subject: [Tutor] Tkinter and after() method In-Reply-To: <08c56c52-fbb1-ab19-81fa-82f2a0dec539@gmail.com> References: <08c56c52-fbb1-ab19-81fa-82f2a0dec539@gmail.com> Message-ID: On 01Feb2023 11:51, Phil wrote: >I see, doesn't that limit the class to only work with Tkinter, and is >that normal practise? I try to make my classes universal so that they >can be used with Tkinter and Wxpython. At the moment I'll be happy if >the Dial class only works with Tkinter. Surely. But I'd probably address that with a Dial class for the dial state, and separate DialWidgets of Tk and/or Wxpython flavours, each of which has a reference to the Dial. Then the app setup makes a Dial (or is given Dials, whatever) and makes widgets to show each dial. That also lets you show the _same_ dial state in multiple places, or with different widgets (a dial or a bar or ...) all sharing state. Cheers, Cameron Simpson From cs at cskk.id.au Tue Jan 31 21:39:02 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 1 Feb 2023 13:39:02 +1100 Subject: [Tutor] Tkinter and after() method In-Reply-To: <7882b9ad-b51d-b64c-d85e-05512a77d174@gmail.com> References: <7882b9ad-b51d-b64c-d85e-05512a77d174@gmail.com> Message-ID: On 01Feb2023 12:11, Phil wrote: >On 1/2/23 11:10, Alan Gauld via Tutor wrote: >>Where are the methods? >>An object that has no operations is just data... > >I was coming to that, it's still work in progress. Aye. Some things are just state of course :-) But even a thing with not GUI methods may well grow methods returning derived values or for doing specific types of adjustments to the state. >>>my_dial = None??? # I cannot see an alternative to their use at the >>>moment >>>my_canvas = None >>Why not make them attributes of your root class? >>After all the Root class actually represents your >>application does it not? > >That's how they were but they weren't visible to functions outside the >root class. I'll give this more thought. This ties Phil back to a single dial. And also ties the dial to the widget kit (tkinter). Cheers, Cameron Simpson