On Wed, Jan 6, 2016 at 9:07 PM, yehudak . <[email protected]> wrote:
> Alan, Tahir & friends, > My post was not a question, merely an observation. > I hope there's no objection to my mail. > > Yehuda > > On Wed, Jan 6, 2016 at 10:59 PM, <[email protected]> wrote: > > > Send Tutor mailing list submissions to > > [email protected] > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://mail.python.org/mailman/listinfo/tutor > > or, via email, send a message with subject or body 'help' to > > [email protected] > > > > You can reach the person managing the list at > > [email protected] > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Tutor digest..." > > > > > > Today's Topics: > > > > 1. Teaching Python (yehudak .) > > 2. Re: method, type? (Alan Gauld) > > 3. Re: Teaching Python (Alan Gauld) > > 4. Re: Teaching Python (Peter Otten) > > 5. Re: Teaching Python (Danny Yoo) > > 6. Re: Teaching Python (Tahir Hafiz) > > > > > > ---------------------------------------------------------------------- > > > > Message: 1 > > Date: Wed, 6 Jan 2016 20:23:59 +0200 > > From: "yehudak ." <[email protected]> > > To: [email protected] > > Subject: [Tutor] Teaching Python > > Message-ID: > > < > > cae3ie43gpx6ud5h8cqfsj-l1tfrwwhlcas0jbaq02wv-c+v...@mail.gmail.com> > > Content-Type: text/plain; charset=UTF-8 > > > > My grandson Guy (8th grader) is learning Python at school. That's what > made > > me teach myself Python programming as well. > > Yesterday he asked my help in his homework: > > > > Write a FOR-loop that prints all numbers up to 1000000 > > > > Thank you, the gods of Ctrl+C > > > > Yehuda > > > > > > ------------------------------ > > > > Message: 2 > > Date: Wed, 6 Jan 2016 18:57:31 +0000 > > From: Alan Gauld <[email protected]> > > To: [email protected] > > Subject: Re: [Tutor] method, type? > > Message-ID: <[email protected]> > > Content-Type: text/plain; charset=utf-8 > > > > Second attempt, my PC crashed just as I was sending the first > > one. You might see two similar posts, if so apologies... > > > > On 06/01/16 14:46, Steven D'Aprano wrote: > > > I don't understand what you mean by "Python doesn't support named > > > constructors". It seems to me that this is the *only* sort of > > > constructor that Python supports. > > > > No, Python constructors have names(new/init) but they are not > > used explicitly (ie. by the client code)to create objects. By > > contrast languages like Delphi, Smalltalk, Objective C, > > some Lisps and, I think, Eiffel (and others?) all require an > > explicit call of a constructor method and there may be > > multiple constructors per class each with different names > > (usually describing how the construction occurs or the > > nature of the object constructed). > > > > For example in Smalltalk: > > > > obj := MyClass new. # new is the normal choice of name > > obj2 := Date today. > > obj3 := Date new. > > obj4 := Time now. > > > > All of these methods (new, today, now) are constructors(*) but > > with explicit names that tells you something about the kind > > of instance created. > > > > (*)As I understand it, Smalltalk constructors are just class > > methods allocated to a constructor category. But the category > > is just an organisational device used by the IDE/library > > it doesn't actually change the code in any way. > > > > > As I understand it, "named constructor" comes from the C++ world, where > > > functions are matched not just by name, but by parameters as well. > > > > That's overloading which uses the same name but with different > > numbers/types of parameters and/or return type. The problem with > > that is that in C++ constructors must have the name of the class. > > So if you want multiple constructors that all take a single > > string as their paramater then it gets tricky. > > > > > two integers representing the position relative to the entire screen, > or > > > two integers representing the position relative to the current window. > > > The C++ compiler cannot distinguish those two cases, and would give an > > > error. > > > > Exactly so. > > > > > The solution is to use constructors with different names, which C++ > > > calls "named constructors". > > > > I stopped using C++ around v2 and it didn't have such a feature. > > Maybe its been added since. If so that's good to know. (Time > > for some googling methinks...) > > > > > So the only way to have two different constructors is to give them > > > different names. > > > > > > Hence all constructors in Python are "named constructors". > > > > But they are not native constructors such as those used in > > Smalltalk etc. They have to be factory methods that call new/init > > under the covers. And that's how most OOP languages that don't > > support named constructors get round it. (Although interestingly, > > Objective C refers to all constructors as 'factory methods', even > > the 'default' ones.) > > > > > It would be reasonable to make this a factory function declared in the > > > global module level. But I think making it a classmethod is better. > > > > I won't put up much of an argument here. In C++ or Java I'd > > definitely say use a class method. But it seems to me that I've > > seen more factory functions in modules than class method factories. > > But that's not been a detailed analysis just a gut feel for what > > seems idiomatic in Python. It also seems easier for beginners > > to grasp than the more esoteric notion of class methods. > > > > > ... ensures that if you subclass the class, you automatically > > > get a valid constructor as well. > > > > Wouldn't it return an instance of the superclass rather than > > the sub class? You'd need to override it wouldn't you? > > > > > > -- > > 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 > > > > > > > > > > ------------------------------ > > > > Message: 3 > > Date: Wed, 6 Jan 2016 19:04:24 +0000 > > From: Alan Gauld <[email protected]> > > To: [email protected] > > Subject: Re: [Tutor] Teaching Python > > Message-ID: <[email protected]> > > Content-Type: text/plain; charset=utf-8 > > > > On 06/01/16 18:23, yehudak . wrote: > > > My grandson Guy (8th grader) is learning Python at school. That's what > > made > > > me teach myself Python programming as well. > > > Yesterday he asked my help in his homework: > > > > > > Write a FOR-loop that prints all numbers up to 1000000 > > > > And the question is? > > Python has a for loop and a print function. > > It can easily handle numbers up to 1000000. > > You probably need to look at the range() function too. > > > > If you are having difficulty with any of those concepts > > let us know and ideally show us the code that fails. > > > > Alternatively if you are asking about what we think of > > the homework question itself, then I'd say it seems > > reasonable for a beginner. The only thing I'd gripe > > about is the use of uppercase FOR. That's because > > Python is case sensitive and its for loop is > > lowercase so the FOR could confuse some students. > > > > -- > > 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 > > > > > > > > > > ------------------------------ > > > > Message: 4 > > Date: Wed, 06 Jan 2016 21:40:26 +0100 > > From: Peter Otten <[email protected]> > > To: [email protected] > > Subject: Re: [Tutor] Teaching Python > > Message-ID: <[email protected]> > > Content-Type: text/plain; charset="ISO-8859-1" > > > > yehudak . wrote: > > > > > My grandson Guy (8th grader) is learning Python at school. That's what > > > made me teach myself Python programming as well. > > > Yesterday he asked my help in his homework: > > > > > > Write a FOR-loop that prints all numbers up to 1000000 > > > > > > Thank you, the gods of Ctrl+C > > > > Did you mean to imply that it took too long? > > > > It is likely that the terminal (emulation) is to blame, and not the > python > > interpreter: > > > > $ time python3 -c 'for i in range(10**6): print(i)' > /dev/null > > > > real 0m1.562s > > user 0m1.525s > > sys 0m0.033s > > > > Under 2 seconds on quite old hardware. Without redirection in Konsole > > (KDE's > > terminal emulator): > > > > $ time python3 -c 'for i in range(10**6): print(i)' > > [...] > > 999997 > > 999998 > > 999999 > > > > real 0m16.167s > > user 0m5.258s > > sys 0m5.512s > > > > But wait -- you ran the code in IDLE, right? > > Then book it under lessons learned ;) > > > > > > > > ------------------------------ > > > > Message: 5 > > Date: Wed, 6 Jan 2016 12:42:52 -0800 > > From: Danny Yoo <[email protected]> > > To: "yehudak ." <[email protected]> > > Cc: Python Tutor Mailing List <[email protected]> > > Subject: Re: [Tutor] Teaching Python > > Message-ID: > > <CAGZAPF5yHAqqXsDDXg3OtKtuV=EUqtDo_rhOv=7g45= > > [email protected]> > > Content-Type: text/plain; charset=UTF-8 > > > > On Wed, Jan 6, 2016 at 10:23 AM, yehudak . <[email protected]> wrote: > > > My grandson Guy (8th grader) is learning Python at school. That's what > > made > > > me teach myself Python programming as well. > > > Yesterday he asked my help in his homework: > > > > > > Write a FOR-loop that prints all numbers up to 1000000 > > > > Try to say explicitly where you think you're getting stuck. There are a > few > > general problem-solving strategies that you can try to apply, in the > spirit > > of Polya's How To Solve It: > > http://www.amazon.com/How-Solve-It-Mathematical-Princeton/dp/069111966X. > > > > * Do you understand the question being asked? Do you understand all the > > technical "terms" that the question is using? This is actually a really > > important one: if you don't understand the terms, there's very little > hope > > to get anything useful out of the experience. > > > > - Do you know what a for loop is? Have you seen any examples of for > loops? > > - Do you know what it means to print a number? Have you seen any examples > > of this? > > > > * Do you know what the expected output is supposed to look like? > > > > * Have you tackled problems that are similar to this one before? > > > > * Do you know how to solve a simpler version of the problem? Say, from > > changing "1000000" to "10"? > > > > > > ------------------------------ > > > > Message: 6 > > Date: Wed, 6 Jan 2016 20:59:34 +0000 > > From: Tahir Hafiz <[email protected]> > > To: "yehudak ." <[email protected]> > > Cc: tutor <[email protected]> > > Subject: Re: [Tutor] Teaching Python > > Message-ID: > > <CALmb6fvk+hd7ShHts2Qf6zOP1RzNwQo4zU6nVs390Z1ze= > > [email protected]> > > Content-Type: text/plain; charset=UTF-8 > > > > Yes that is a huge for loop. > > I can do it like this but I won't try: > > >>> for num in list(range(1000000)): > > >>> print(num) > > > > Sort of strange that the school wanted so much looping for your grandson, > > they could have picked a lower number to demonstrate a for loop. > > > > By the way there is the tqdm module which will show the time of a for > loop > > in a nice way: > > https://github.com/noamraph/tqdm > > > > > > Cheers, > > Tahir > > > > > > > > > > > > > > > > On Wed, Jan 6, 2016 at 6:23 PM, yehudak . <[email protected]> wrote: > > > > > My grandson Guy (8th grader) is learning Python at school. That's what > > made > > > me teach myself Python programming as well. > > > Yesterday he asked my help in his homework: > > > > > > Write a FOR-loop that prints all numbers up to 1000000 > > > > > > Thank you, the gods of Ctrl+C > > > > > > Yehuda > > > _______________________________________________ > > > Tutor maillist - [email protected] > > > To unsubscribe or change subscription options: > > > https://mail.python.org/mailman/listinfo/tutor > > > > > > > > > ------------------------------ > > > > Subject: Digest Footer > > > > _______________________________________________ > > Tutor maillist - [email protected] > > https://mail.python.org/mailman/listinfo/tutor > > > > > > ------------------------------ > > > > End of Tutor Digest, Vol 143, Issue 17 > > ************************************** > > > _______________________________________________ > Tutor maillist - [email protected] > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor That is okay, everyone is very friendly here. No worries. _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
