From __peter__ at web.de Fri Dec 1 03:20:08 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Dec 2017 09:20:08 +0100 Subject: [Tutor] problem with a sub-class References: <04ccf72d-5949-b8d9-5518-90ba7954b306@kcl.ac.uk> Message-ID: Alan Gauld via Tutor wrote: > On 30/11/17 15:37, Shall, Sydney wrote: > >> My problem is with constructing a sub-class. >> >> My sub-class is constructed as follows: >> >> import Population_ProductivityV24 as POCWP > > Note that POCWP is an alias for the *module* Population_ProductivityV24. > It is not a class. > >> line 27 : class SimulateCycleZero(POCWP): > > Here you define a class that subclasses your imported module. > Frankly I'm surprised that you don't get an error there > but hey... > >> line 28 : def __init__(self, dirname_p): > > But this is now an init for a subclass of module. > >> The error message is as follows: >> >> File >> "/Users/sydney/AnacondaProjects/Capital/Capital_with_productivity/Current_Versions/Simulate_Cycle_Zero_V3.py", >> line 27, in >> class SimulateCycleZero(POCWP): >> >> TypeError: module.__init__() takes at most 2 arguments (3 given) > > So I'm guessing the use of a module to subclass > has confused things and I confess I'm not clear on > exactly what is going on and why you get this message. A class is an instance of its metaclass. class A: pass is roughly equivalent to A = type("A", (), {}) # classname, base classes, class attributes and class B(A):>>> class A: ... def __init__(self, *args): ... print("__init__{}".format(args)) ... >>> class B(A()): pass ... __init__() __init__('B', (<__main__.A object at 0x7f3db8a1c048>,), {'__module__': '__main__', '__qualname__': 'B'}) >>> assert isinstance(B, A) >>> isinstance(B, A) True >>> B() Traceback (most recent call last): File "", line 1, in TypeError: 'A' object is not callable foo = 42 is roughly equivalent to B = type(A)("B", (A,), {"foo": 42}) When you subclass from an instance of A instead of A itself this becomes a = A() B = type(a)("B", (a,), {"foo": 42}) which can be simplified to B = A("B", (a,), {"foo": 42}) If this succeeds B is bound to an instance of A, but usually you'll see a TypeError, either immediately as the OP, >>> class A: pass ... >>> class B(A()): pass ... Traceback (most recent call last): File "", line 1, in TypeError: object() takes no parameters or later when you try to instantiate B: >>> class A: ... def __init__(self, *args): ... print("__init__{}".format(args)) ... >>> class B(A()): pass ... __init__() __init__('B', (<__main__.A object at 0x7f3db8a1c048>,), {'__module__': '__main__', '__qualname__': 'B'}) >>> isinstance(B, A) True >>> B() Traceback (most recent call last): File "", line 1, in TypeError: 'A' object is not callable > But I'm pretty sure you don;t want to subclass your > imported module and thats the mistake. From __peter__ at web.de Fri Dec 1 03:35:32 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Dec 2017 09:35:32 +0100 Subject: [Tutor] [cleaned-up] Re: problem with a sub-class References: <04ccf72d-5949-b8d9-5518-90ba7954b306@kcl.ac.uk> Message-ID: Peter Otten wrote: Sorry for the mess; second attempt: A class is an instance of its metaclass. class A: pass is roughly equivalent to A = type("A", (), {}) # classname, base classes, class attributes and class B(A): foo = 42 is roughly equivalent to B = type(A)("B", (A,), {"foo": 42}) When you subclass from an instance of A instead of A itself this becomes a = A() B = type(a)("B", (a,), {"foo": 42}) which can be simplified to B = A("B", (a,), {"foo": 42}) If this succeeds B is bound to an instance of A, but usually you'll see a TypeError, either immediately as the OP, >>> class A: pass ... >>> class B(A()): pass ... Traceback (most recent call last): File "", line 1, in TypeError: object() takes no parameters or later when you try to instantiate B: >>> class A: ... def __init__(self, *args): ... print("__init__{}".format(args)) ... >>> class B(A()): pass ... __init__() __init__('B', (<__main__.A object at 0x7f3db8a1c048>,), {'__module__': '__main__', '__qualname__': 'B'}) >>> isinstance(B, A) True >>> B() Traceback (most recent call last): File "", line 1, in TypeError: 'A' object is not callable From s.shall at virginmedia.com Fri Dec 1 06:30:14 2017 From: s.shall at virginmedia.com (Sydney Shall) Date: Fri, 1 Dec 2017 11:30:14 +0000 Subject: [Tutor] problem with a sub-class In-Reply-To: References: <04ccf72d-5949-b8d9-5518-90ba7954b306@kcl.ac.uk> Message-ID: <348b07a7-9502-5226-be3b-506d2a905de7@virginmedia.com> On 30/11/2017 22:08, Alan Gauld via Tutor wrote: > On 30/11/17 15:37, Shall, Sydney wrote: > >> My problem is with constructing a sub-class. >> >> My sub-class is constructed as follows: >> >> import Population_ProductivityV24 as POCWP > > Note that POCWP is an alias for the *module* Population_ProductivityV24. > It is not a class. > >> line 27 : class SimulateCycleZero(POCWP): > > Here you define a class that subclasses your imported module. > Frankly I'm surprised that you don't get an error there > but hey... > >> line 28 : def __init__(self, dirname_p): > > But this is now an init for a subclass of module. > >> The error message is as follows: >> >> File >> "/Users/sydney/AnacondaProjects/Capital/Capital_with_productivity/Current_Versions/Simulate_Cycle_Zero_V3.py", >> line 27, in >> class SimulateCycleZero(POCWP): >> >> TypeError: module.__init__() takes at most 2 arguments (3 given) > > So I'm guessing the use of a module to subclass > has confused things and I confess I'm not clear on > exactly what is going on and why you get this message. > But I'm pretty sure you don;t want to subclass your > imported module and thats the mistake. > > Thanks to Alan and Peter for explaining sub-classing to me. I understand a bit better now. My program is corrected and does not give the error any more. -- Sydney From a.ajmera at incycleautomation.com Fri Dec 1 09:02:47 2017 From: a.ajmera at incycleautomation.com (a.ajmera at incycleautomation.com) Date: Fri, 01 Dec 2017 07:02:47 -0700 Subject: [Tutor] Problem with 'IF' condition Message-ID: <20171201070247.ddcc2133211988ff98b4e8933e7e9b31.f35bfc33bc.mailapi@email14.godaddy.com> Hi, I am trying to compare two different values using "IF" condition in my program. Everything is working fine except this. I copied my program as plain text below, in the last section I used "IF" condition. - If you see in my code, I'm writing to "test1.txt" and saving that value in "nao" as well. On the other side, I'm reading from "test3.txt" and saving that value in "abb" just like above. Now, my goal is to compare these two variables nao & abb. As it written below. However, result never gives me "true" when actually this both variable contain same values. This code always giving me "not same" result. I'm not sure why this is not working. I would greatly appreciate your help. Please let me know for any question. tts.say("Hi") x = "C:/FTP_Folder/test1.txt" f = open(x) r = f.read(500) tts.say("Current position number in the text file is") tts.say(r) f.close() f1 = open(x,'w') z = f1.write("1") f1.close() tts.say("writing to file") tts.say("A.B.B. robot; go to my directed position") f = open(x) r0 = f.read(500) tts.say(r0) nao = r0 f.close() import time time.sleep(5) # delays for 5 seconds ##f1 = open(x,'w') ##f1.write("0") ##f1.close() y = "C:/FTP_Folder/test3.txt" f2 = open(y) r1 = f2.read(500) abb = r1 if nao == abb: print("Positions are same") print r, r1 else: print("not same") print nao, abb Best Regards, Achyut Ajmera From alan.gauld at yahoo.co.uk Fri Dec 1 12:33:02 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 1 Dec 2017 17:33:02 +0000 Subject: [Tutor] Problem with 'IF' condition In-Reply-To: <20171201070247.ddcc2133211988ff98b4e8933e7e9b31.f35bfc33bc.mailapi@email14.godaddy.com> References: <20171201070247.ddcc2133211988ff98b4e8933e7e9b31.f35bfc33bc.mailapi@email14.godaddy.com> Message-ID: On 01/12/17 14:02, a.ajmera at incycleautomation.com wrote: > - If you see in my code, I'm writing to "test1.txt" and saving that value in "nao" as well. > On the other side, I'm reading from "test3.txt" and saving that value in "abb" just like above. > > Now, my goal is to compare these two variables nao & abb. As it written below. > However, result never gives me "true" when actually this both variable contain same values. Are you absolutely sure they are the same? Have you checked, for example for newline characters or other whitespeace? You could do that by printing the repr() of the values: print repr(nao), repr(abb) Now simplifying your code slightly: > x = "C:/FTP_Folder/test1.txt" > f = open(x) > r = f.read(500) > f.close() > f1 = open(x,'w') > z = f1.write("1") > f1.close() Note that this will have deleted everything in x and replaced it with "1" > f = open(x) > r0 = f.read(500) r0 will now contain '1' > nao = r0 As will nao > f.close() > y = "C:/FTP_Folder/test3.txt" > f2 = open(y) > r1 = f2.read(500) > abb = r1 abb now contains whatever was in test3.txt. Did it contain '1'? > if nao == abb: > print("Positions are same") > print r, r1 r contains the original contents of test1 r1 contains the content of test3 > else: > print("not same") > print nao, abb whereas nao contains '1' and abb contains the same as r1 Is my interpretation what you see, and is it what you expect? In future with thee kinds of issues its good to include an actual cut n paste of the program output. -- 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 __peter__ at web.de Fri Dec 1 12:50:24 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Dec 2017 18:50:24 +0100 Subject: [Tutor] Problem with 'IF' condition References: <20171201070247.ddcc2133211988ff98b4e8933e7e9b31.f35bfc33bc.mailapi@email14.godaddy.com> Message-ID: a.ajmera at incycleautomation.com wrote: > I am trying to compare two different values using "IF" condition in my > program. Everything is working fine except this. I copied my program as > plain text below Your code has indentation errors, my analysis assumes # the following was added to make it runnable class TTS: def say(self, message): print "TTS says:", message tts = TTS() # end of my addition tts.say("Hi") x = "C:/FTP_Folder/test1.txt" f = open(x) r = f.read(500) tts.say("Current position number in the text file is") tts.say(r) f.close() f1 = open(x,'w') z = f1.write("1") f1.close() tts.say("writing to file") tts.say("A.B.B. robot; go to my directed position") f = open(x) r0 = f.read(500) tts.say(r0) nao = r0 f.close() import time time.sleep(5) # delays for 5 seconds ##f1 = open(x,'w') ##f1.write("0") ##f1.close() y = "C:/FTP_Folder/test3.txt" f2 = open(y) r1 = f2.read(500) abb = r1 if nao == abb: print("Positions are same") print r, r1 else: print("not same") print nao, abb > , in the last section I used "IF" condition. - If you see > in my code, I'm writing to "test1.txt" and saving that value in "nao" as > well. On the other side, I'm reading from "test3.txt" and saving that > value in "abb" just like above. > > Now, my goal is to compare these two variables nao & abb. As it written > below. However, result never gives me "true" when actually this both > variable contain same values. No, they don't. nao will contain the first 500 bytes of the file "C:/FTP_Folder/test1.txt" while abb will contain the first 500 bytes of the file "C:/FTP_Folder/test3.txt". But even if you start with two files with the same contents -- with the following lines > f1 = open(x,'w') > z = f1.write("1") > f1.close() you overwrite "C:/FTP_Folder/test1.txt" which now contains only a single "1". Thus the nao == abb test will only compare equal if "C:/FTP_Folder/test3.txt" contains a single "1", too. > This code always giving me "not same" > result. > > I'm not sure why this is not working. > I would greatly appreciate your help. > > Please let me know for any question. From steve at pearwood.info Fri Dec 1 18:11:54 2017 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 2 Dec 2017 10:11:54 +1100 Subject: [Tutor] Problem with 'IF' condition In-Reply-To: <20171201070247.ddcc2133211988ff98b4e8933e7e9b31.f35bfc33bc.mailapi@email14.godaddy.com> References: <20171201070247.ddcc2133211988ff98b4e8933e7e9b31.f35bfc33bc.mailapi@email14.godaddy.com> Message-ID: <20171201231154.GN22248@ando.pearwood.info> On Fri, Dec 01, 2017 at 07:02:47AM -0700, a.ajmera at incycleautomation.com wrote: > I copied my program as plain text below, Unfortunately you didn't, as the text you quote below will not run as Python code due to indentation errors. So you have (accidentally, I trust) messed up the indentation. Please take more care to copy and paste accurately, without adding extra spaces at the start of lines. > tts.say("Hi") Since tts is not defined, this fails immediately with a NameError. How is this line tts.say() relevant to your problem? It just adds extra code, and makes it impossible for us to run your code. There is no need to show us irrelevant code. > x = "C:/FTP_Folder/test1.txt" > f = open(x) > r = f.read(500) > tts.say("Current position number in the text file is") > tts.say(r) > f.close() > f1 = open(x,'w') This line has a spurious space added to the start. That's what I mean about accidentally messing up the indentation. > z = f1.write("1") > f1.close() You have now over-written the contents of file 'x' with a single digit '1'. > tts.say("writing to file") > tts.say("A.B.B. robot; go to my directed position") > f = open(x) > r0 = f.read(500) > tts.say(r0) > nao = r0 > f.close() And now you re-read the same file 'x', reading a single '1' (because that is all that is inside the file). r0 and nao will always be '1'. > import time Another copy-and-paste error introducing spurious indentation. > time.sleep(5) # delays for 5 seconds What is the point of this sleep? This has nothing to do with your problem. Take it out. > ##f1 = open(x,'w') > ##f1.write("0") > ##f1.close() > y = "C:/FTP_Folder/test3.txt" > f2 = open(y) > r1 = f2.read(500) > abb = r1 Now you read from a completely different file. > if nao == abb: > print("Positions are same") > print r, r1 > else: > print("not same") > print nao, abb Why do you expect them to be the same? You are reading from two completely different files, one has been overwritten by the digit '1' each time. The only possible way for these to be the same will be: (1) Start file x as anything. (2) Start file y with *exactly* a single digit '1' and nothing else. Be careful because some text editors will automatically add a newline to the end of your file when they save. (3) You read file x. (4) Then you over-write x with a single digit '1'. (5) Then you re-read x, reading the single digit '1' again. (6) Now you read y, getting '1'. If you get *anything* else, even a single space or newline, they won't match. (7) If they do match, your code prints the ORIGINAL (now over-written) contents of x, and the contents of y, which has to be '1' or else it will never match the NEW (over-written) contents of x. -- Steve From steve at pearwood.info Fri Dec 1 18:18:12 2017 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 2 Dec 2017 10:18:12 +1100 Subject: [Tutor] Counting iterations of a function In-Reply-To: References: Message-ID: <20171201231812.GO22248@ando.pearwood.info> On Thu, Nov 30, 2017 at 10:26:20AM -0600, Michael Dowell wrote: > Hello, I'm trying to code a magic 8-ball program and it needs to include a > counter for the number of questions asked. I'm having a hard time > implementing a count, and need a little help. I had tried to implement it > in the main() function, but that (naturally) led it to only counting '1' > for each question, for each question asked. Is there a way to count how > many times a give line of code is executed? For instance, every time the > oracle() function is run, a counter goes up. Thanks for any help. I haven't even looked at your code, but the obvious way to count the number of times a specific function is called is to have a separate counter for that function and have the function increment it. FOr example: oracle_count = 0 def oracle(): global oracle_count oracle_count += 1 ... Will that solve your problem? -- Steve From steve at pearwood.info Fri Dec 1 20:07:04 2017 From: steve at pearwood.info (Steven D'Aprano) Date: Sat, 2 Dec 2017 12:07:04 +1100 Subject: [Tutor] Python In-Reply-To: References: Message-ID: <20171202010704.GQ22248@ando.pearwood.info> On Thu, Nov 30, 2017 at 09:20:32AM +0100, Jeroen van de Ven wrote: > Hello, > Can you build these 4 programms for me? Certainly. My rate is AUD$175 an hour, payable in advance. I estimate that it will take at least three hours to write and test the first three programs. You haven't shown the fourth program, so I don't know how long it will take, but let's say... ten hours in total? Better make it twelve to be on the safe side. Oh, just a reminder... if these are assignment questions at your college or school, the school might have something to say about plagiarism and submitting other people's work as your own. -- Steve From alan.gauld at yahoo.co.uk Mon Dec 4 12:05:35 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Mon, 4 Dec 2017 17:05:35 +0000 Subject: [Tutor] Problem with 'IF' condition In-Reply-To: <20171204072931.ddcc2133211988ff98b4e8933e7e9b31.7e8a68d05c.mailapi@email14.godaddy.com> References: <20171204072931.ddcc2133211988ff98b4e8933e7e9b31.7e8a68d05c.mailapi@email14.godaddy.com> Message-ID: Please always reply all to include the tutor list On 04/12/17 14:29, a.ajmera at incycleautomation.com wrote: > Thank you so much for your quick reply. > I don't think there are any white space errors. Don't guess, prove it. To do that you *must* use repr() otherwise print() will hide the whitespace. Also do you have a valid reason for reading the first file then overwriting it? It seems like wasted effort unless you plan onm doing something with the original content at some point in the future? > ? > However, Whatever you understood is exactly same what I tried to > explain in my email. > In this email I have attached output screen shot. > abb and nao contain exactly same value(you can see in screen shot, as > I print values).? > But, I don't understand as it is printing same values(in abb and nao); > it should give output "positions are same". > But it doesnot. > ? > Please let me know if you find any errors. > ? > Best Regards, > Achyut Ajmera? > ? > ? > > --------- Original Message --------- > Subject: Re: [Tutor] Problem with 'IF' condition > From: "Alan Gauld via Tutor" > Date: 12/1/17 12:33 pm > To: tutor at python.org > > On 01/12/17 14:02, a.ajmera at incycleautomation.com wrote: > > > - If you see in my code, I'm writing to "test1.txt" and saving > that value in "nao" as well. > > On the other side, I'm reading from "test3.txt" and saving that > value in "abb" just like above. > > > > Now, my goal is to compare these two variables nao & abb. As it > written below. > > However, result never gives me "true" when actually this both > variable contain same values. > > Are you absolutely sure they are the same? Have you checked, for > example > for newline characters or other whitespeace? > You could do that by printing the repr() of the values: > > print repr(nao), repr(abb) > > Now simplifying your code slightly: > > > x = "C:/FTP_Folder/test1.txt" > > f = open(x) > > r = f.read(500) > > f.close() > > > f1 = open(x,'w') > > z = f1.write("1") > > f1.close() > > Note that this will have deleted everything in x > and replaced it with "1" > > > f = open(x) > > r0 = f.read(500) > > r0 will now contain '1' > > > nao = r0 > > As will nao > > > f.close() > > > y = "C:/FTP_Folder/test3.txt" > > f2 = open(y) > > r1 = f2.read(500) > > abb = r1 > > abb now contains whatever was in test3.txt. > Did it contain '1'? > > > if nao == abb: > > print("Positions are same") > > print r, r1 > > r contains the original contents of test1 > r1 contains the content of test3 > > > else: > > print("not same") > > print nao, abb > > whereas nao contains '1' and abb contains the > same as r1 > > Is my interpretation what you see, and is it what > you expect? > > In future with thee kinds of issues its good > to include an actual cut n paste of the program > output. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- 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 Dec 5 11:02:52 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 5 Dec 2017 16:02:52 +0000 Subject: [Tutor] More tutor testing required Message-ID: Folks, A couple of weeks ago I asked for testers for my web tutor. Many thanks to those who helped out. I've now tried to address the issues raised and the latest incarnation should work (although not well with Opera for some reason!) As before I am particularly needful of feedback from Apple users. The url is: http://www.alan-g.me.uk/l2p2/ -- 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 atuxnull at gmail.com Tue Dec 5 10:10:52 2017 From: atuxnull at gmail.com (Atux Atux) Date: Tue, 5 Dec 2017 17:10:52 +0200 Subject: [Tutor] download google contacts Message-ID: hi everyone. i am new to the area of python and i have basic knowledge, so please bear with me. i am looking for a way to download only the contacts from my google account and export them in my linux machine in a txt file, every12 hours with cronjob and overwrite the old txt file. let's make some assumptions for the sake of the example: user: whatevertux passwd: 123abcover path of the txt file:/home/john/anyplace some help please? John From alan.gauld at yahoo.co.uk Wed Dec 6 09:41:33 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 6 Dec 2017 14:41:33 +0000 Subject: [Tutor] More tutor testing required In-Reply-To: References: Message-ID: On 05/12/17 16:02, Alan Gauld via Tutor wrote: > address the issues raised and the latest incarnation > should work (although not well with Opera for some reason!) Now better with Opera, although the contents panel is still not quite right on small screens. Still looking for feedback from iOS devices (or even Safari on a desktop PC/laptop for that matter) Any input appreciated. -- 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 tkadm30 at yandex.com Wed Dec 6 04:21:06 2017 From: tkadm30 at yandex.com (Etienne Robillard) Date: Wed, 6 Dec 2017 04:21:06 -0500 Subject: [Tutor] How to debug a memory leak in a wsgi application? Message-ID: <73793f05-d918-b6a1-5d88-fda9e399dba9@yandex.com> Hi I think my wsgi application is leaking and I would like to debug it. What is the best way to profile memory usage in a running wsgi app? Best regards, Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From alan.gauld at yahoo.co.uk Wed Dec 6 10:00:33 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 6 Dec 2017 15:00:33 +0000 Subject: [Tutor] How to debug a memory leak in a wsgi application? In-Reply-To: <73793f05-d918-b6a1-5d88-fda9e399dba9@yandex.com> References: <73793f05-d918-b6a1-5d88-fda9e399dba9@yandex.com> Message-ID: On 06/12/17 09:21, Etienne Robillard wrote: > Hi > > I think my wsgi application is leaking and I would like to debug it. > > What is the best way to profile memory usage in a running wsgi app? This is probably a bit advanced for the tutor list, you might get a better response on the main Python list. But to get a sensible answer you need to provide more data: What OS and Python version? What toolset/framework are you using? What measurements lead you to suspect a memory leak? -- 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 malaclypse2 at gmail.com Wed Dec 6 12:58:56 2017 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 6 Dec 2017 12:58:56 -0500 Subject: [Tutor] download google contacts In-Reply-To: References: Message-ID: On Tue, Dec 5, 2017 at 10:10 AM, Atux Atux wrote: > i am looking for a way to download only the contacts from my google account > and export them in my linux machine in a txt file, every12 hours with > cronjob and overwrite the old txt file. > ?Have you read Google's Contacts API? documentation? It has a python library and sample code you can start with. https://developers.google.com/google-apps/contacts/v3/. It might be a bit tricky to work with since it uses OAuth, which doesn't always mix well with a command line application run non-interactively. I'm not sure the best way to deal with that, but I would guess you aren't the first person to try and solve that problem. Once you have some code, if it isn't working the way that you'd like folks here are usually happy to pitch in with advice. -- Jerry From tkadm30 at yandex.com Wed Dec 6 11:23:07 2017 From: tkadm30 at yandex.com (Etienne Robillard) Date: Wed, 6 Dec 2017 11:23:07 -0500 Subject: [Tutor] How to debug a memory leak in a wsgi application? In-Reply-To: References: <73793f05-d918-b6a1-5d88-fda9e399dba9@yandex.com> Message-ID: <724b9fb7-ccee-c8a1-62f0-938c2b8dbf22@yandex.com> Hi Alan, Thanks for the reply. I use Debian 9 with 2G of RAM and precompiled Python 2.7 with pymalloc. I don't know if debugging was enabled for this build and whether I should enable it to allow memory profiling with guppy... My problem is that guppy won't show the heap stats for the uWSGI master process. However I have partially resolved this issue by enabling --reload-on-rss 200 for the uwsgi process.? Previously, the htop utility indicated a 42.7% rss memory usage for 2 uWSGI processes. I have restarted the worker processes with SIGINT signal. Now my uwsgi command line looks like: % uwsgi --reload-on-rss 200 --gevent 100 --socket localhost:8000 --with-file /path/to/file.uwsgi --threads 2 --processes 4 --master --daemonize /var/log/uwsgi.log My framework is Django with django-hotsauce 0.8.2 and werkzeug. The web server is nginx using uWSGI with the gevent pooling handler. Etienne Le 2017-12-06 ? 10:00, Alan Gauld via Tutor a ?crit?: > On 06/12/17 09:21, Etienne Robillard wrote: >> Hi >> >> I think my wsgi application is leaking and I would like to debug it. >> >> What is the best way to profile memory usage in a running wsgi app? > This is probably a bit advanced for the tutor list, you might > get a better response on the main Python list. > > But to get a sensible answer you need to provide more data: > What OS and Python version? > What toolset/framework are you using? > What measurements lead you to suspect a memory leak? > > -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From miloshman2004 at yahoo.com Thu Dec 7 17:12:59 2017 From: miloshman2004 at yahoo.com (Milosh Bogdanovic) Date: Thu, 7 Dec 2017 22:12:59 +0000 (UTC) Subject: [Tutor] Using Tutor References: <1117998712.747161.1512684779203.ref@mail.yahoo.com> Message-ID: <1117998712.747161.1512684779203@mail.yahoo.com> Hi, I'd like to subscribe to python tutor as a beginner. regards,Milos B. From alan.gauld at yahoo.co.uk Fri Dec 8 04:02:39 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 8 Dec 2017 09:02:39 +0000 Subject: [Tutor] Using Tutor In-Reply-To: <1117998712.747161.1512684779203@mail.yahoo.com> References: <1117998712.747161.1512684779203.ref@mail.yahoo.com> <1117998712.747161.1512684779203@mail.yahoo.com> Message-ID: On 07/12/17 22:12, Milosh Bogdanovic via Tutor wrote: > Hi, > I'd like to subscribe to python tutor as a beginner. > regards,Milos B. Welcome, you are subscribed. Now you start asking questions and we will attempt to answer. It will help if you follow these guidelines: Tell us the OS and Python version Show us the code involved Show us the full error text, if any Be as specific as possible when asking questions, do not just say "it didn't work", tell us what happened, send us the output if necessary. Finally, add a useful subject line (not just "help" or similar. And do not top-post, it greatly annoys some people. -- 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 Fri Dec 8 06:46:48 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 8 Dec 2017 11:46:48 +0000 Subject: [Tutor] More tutor testing required In-Reply-To: References: Message-ID: On 05/12/17 16:02, Alan Gauld via Tutor wrote: > address the issues raised and the latest incarnation > should work (although not well with Opera for some reason!) I think I've now got scrolling to work on iOS/Safari and Opera almost works... (a slight glitch when the width is within a particular size range) If anyone uses Opera mobile on a mobile device please let me know if it looks OK. I've also added a "menu button" that hides/shows the TOC pane which should help on phones and other narrow devices. Once more any feedback is appreciated. Please send direct to me rather than the list. If this works I'll finally be able to start updating the content!... -- 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 timilehinayanlade at yahoo.com Sat Dec 9 14:09:05 2017 From: timilehinayanlade at yahoo.com (Ayanlade Timilehin) Date: Sat, 9 Dec 2017 19:09:05 +0000 (UTC) Subject: [Tutor] application development References: <758328027.1889383.1512846545478.ref@mail.yahoo.com> Message-ID: <758328027.1889383.1512846545478@mail.yahoo.com> Goodday, I'm a Windows user and I am interested in developing android applications but I can't find any tutorial?resource online. Please how can you help. From bgailer at gmail.com Sat Dec 9 19:54:54 2017 From: bgailer at gmail.com (bob gailer) Date: Sat, 9 Dec 2017 19:54:54 -0500 Subject: [Tutor] application development In-Reply-To: <758328027.1889383.1512846545478@mail.yahoo.com> References: <758328027.1889383.1512846545478.ref@mail.yahoo.com> <758328027.1889383.1512846545478@mail.yahoo.com> Message-ID: <48b6b634-c585-81e7-9054-078cde174915@gmail.com> On 12/9/2017 2:09 PM, Ayanlade Timilehin via Tutor wrote: > Goodday, I'm a Windows user and I am interested in developing android applications but I can't find any tutorial?resource online. Please how can you help. Google "android development tutorial". If you can't find what you are looking for there, then please refine your question and ask again. Since this is a Python list, perhaps you want to use Python in the development process; in that case Google "android development python". Note references to "Kivy". If you can't find what you are looking for there, then please refine your question and ask again. The more explicit your question the more likely you are to get explicit answers. Saying "I can't find any tutorial?resource online" suggests you don't know how to Google! From mats at wichmann.us Sat Dec 9 19:59:33 2017 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 9 Dec 2017 17:59:33 -0700 Subject: [Tutor] application development In-Reply-To: <758328027.1889383.1512846545478@mail.yahoo.com> References: <758328027.1889383.1512846545478.ref@mail.yahoo.com> <758328027.1889383.1512846545478@mail.yahoo.com> Message-ID: On 12/09/2017 12:09 PM, Ayanlade Timilehin via Tutor wrote: > Goodday, I'm a Windows user and I am interested in developing android applications but I can't find any tutorial?resource online. Please how can you help. I replied and it went off into a black hole due to my own error. sending again here, though Bob hit the main point I think: python-on-android is a little tricky. === You never mention the word Python but you sent this to the Python tutor list so one presumes you were interested in this question in the Python context. If not, then developing with Xamarin Forms under Visual Studio is an easy way to target Windows and Android apps from a similar environment. Xamarin can target iOS as well. I'm none of {Mobile App, Windows, Android} Developer but for a project I was able in fairly short order to develop some example apps for both platforms (and for the Tizen platform as well, using the same dev environment). However, with Python the story is different, because Android does not have a Python interpreter in the system, and Android store policies don't make it easy to deploy an app that depends on another one - you have to do something to bundle Python support with the app you develop. Go talk to Google about that issue... You have to look around some for ways to make that workable - there are a few projects. One of the ones I hear quite a bit about is called Kivy (see kivy.org). It's not the only one, some Internet searching may prove productive. From alan.gauld at yahoo.co.uk Sat Dec 9 20:12:16 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 10 Dec 2017 01:12:16 +0000 Subject: [Tutor] application development In-Reply-To: <758328027.1889383.1512846545478@mail.yahoo.com> References: <758328027.1889383.1512846545478.ref@mail.yahoo.com> <758328027.1889383.1512846545478@mail.yahoo.com> Message-ID: On 09/12/17 19:09, Ayanlade Timilehin via Tutor wrote: > I'm a Windows user and I am interested in developing android applications By far the easiest way into Android development is the AppInventor web site. http://ai2.appinventor.mit.edu Its a cloud based development tool based on Scratch but capable of generating standalone apps. It's a great way to become familiar with the Android event model. It also has an excellent web based tutorial. Once you have mastered that, moving into a more traditional development environment should be easier. (Although you may never need to since most apps are simplistic enough to be within the scope of AI.) Since this is a Python list we'll assume that means using Kivy. HTH -- 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 jiayue93 at gmail.com Sun Dec 10 00:07:00 2017 From: jiayue93 at gmail.com (jia yue Kee) Date: Sun, 10 Dec 2017 13:07:00 +0800 Subject: [Tutor] Aggregation vs Composition Message-ID: Good Day All, I am new to Python and I came across the concept of Composition and Aggregation the other day in Dusty Philips's Python 3: Object-Oriented Programming book. Based on my reading, what I gathered was that Composition implies a relationship where the child cannot exist independent of the parent while Aggregation, on the other hand, implies a relationship where the child can exist independently of the parent. However, in one of the paragraph of the book, *Dusty mentioned that composition is aggregation* (refer to the snapshot below, the sentence which has been highlighted in yellow). I am really confused by this statement and I appreciate that if someone could enlighten me on this as I do not really see how aggregation can be equivalent to composition if the child in one case can exist independently while the other could not exist independently of the parent. [image: Inline image 1] Thanks and Regards, JY From welcome2khabbab at gmail.com Sun Dec 10 00:48:16 2017 From: welcome2khabbab at gmail.com (Khabbab Zakaria) Date: Sun, 10 Dec 2017 11:18:16 +0530 Subject: [Tutor] Question Message-ID: I am working on a program where I found the line: x,y,z = np.loadtext('abcabc.txt', unpack= True, skiprows =1) What does the x, y, z thing mean? What does the unpack= True mean? Thank you -- Khabbab Zakaria Dept of Power Engineering Jadavpur University Calcutta India From alan.gauld at yahoo.co.uk Sun Dec 10 04:01:59 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 10 Dec 2017 09:01:59 +0000 Subject: [Tutor] Aggregation vs Composition In-Reply-To: References: Message-ID: On 10/12/17 05:07, jia yue Kee wrote: > in Dusty Philips's Python 3: Object-Oriented > Programming book. Caveat: I've not read this book so can only guess at what the author might be meaning. > Based on my reading, what I gathered was that Composition implies a > relationship where the child cannot exist independent of the parent while > Aggregation, on the other hand, implies a relationship where the child can > exist independently of the parent. Correct. But the key word here is "implies". In some languages the differences can be directly implemented in the language but in Python the relationships are always just implied. The differences do not really exist. (Unless you go to inordinate lengths to hide and link the data, which is rarely, if ever, justified.) > However, in one of the paragraph of the book, *Dusty mentioned that > composition is aggregation* I'm guessing he means that in Python we implement both concepts in the same way whether in a collection or a class (which in Python can be thought of as a special type of collection). This is because all values in Python are objects and variables(names) are simply references to those objects. So every object in Python must exist independent of its parent to some degree. > (refer to the snapshot below, the sentence > which has been highlighted in yellow). This is a text mailing list so graphics get stripped by the server, sorry. SEnd a URL if necessary. > I am really confused by this I think he is talking about the practical limitations in Python such that pure Composition does not really exist but is implemented *as a concept* by aggregation. But as I said I haven't read the book so am guessing. -- 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 Sun Dec 10 04:32:38 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 10 Dec 2017 09:32:38 +0000 Subject: [Tutor] Question In-Reply-To: References: Message-ID: On 10/12/17 05:48, Khabbab Zakaria wrote: > I am working on a program where I found the line: > x,y,z = np.loadtext('abcabc.txt', unpack= True, skiprows =1) > What does the x, y, z thing mean? > What does the unpack= True mean? They are related. unpacking is a feature of Python whereby a collection of values can be assigned to individual variables in one statement. Consider a list of numbers: nums = [1,2,3] we can unpack those 3 values into separate variables like so x,y,z = nums This is equivalent to: x = nums[0] y = nums[1] z = nums[2] So in your example the numpy function returns some kind of collection of 3 values which are unpacked into x,y and z exactly as we did with nums above. I assume the unpack=True argument simply controls the output of the function such that unpacking is possible, but I'm not familiar with it so cannot be sure. -- 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 steve at pearwood.info Sun Dec 10 05:41:04 2017 From: steve at pearwood.info (Steven D'Aprano) Date: Sun, 10 Dec 2017 21:41:04 +1100 Subject: [Tutor] Question In-Reply-To: References: Message-ID: <20171210104103.GH22248@ando.pearwood.info> Hello Khabbab Zakaria, On Sun, Dec 10, 2017 at 11:18:16AM +0530, Khabbab Zakaria wrote: > I am working on a program where I found the line: > x,y,z = np.loadtext('abcabc.txt', unpack= True, skiprows =1) > What does the x, y, z thing mean? "x, y, z = ..." is iterable unpacking. The right hand side has to be an iterable (any object that can be iterated over in a for-loop) such as a list, a tuple, a set, or similar. For example: x, y, z = [1, 2, 3] will set x = 1, y = 2, z = 3. It is an error if the object on the right hand side has too few or too many items: a, b, c, d, e = (1, 2, 3) # Too few items a, b, c, d, e = (1, 2, 3, 4, 5, 6, 7) # Too many items > What does the unpack= True mean? I'm afraid you will need to read the numpy documentation for that. I tried looking at it myself, but the version of numpy I have seems to be too old: py> import numpy as np py> help(np.loadtext) Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'loadtext' -- Steve From robertvstepp at gmail.com Sun Dec 10 19:40:05 2017 From: robertvstepp at gmail.com (boB Stepp) Date: Sun, 10 Dec 2017 18:40:05 -0600 Subject: [Tutor] Aggregation vs Composition In-Reply-To: References: Message-ID: I own this book, too. I'll insert the portions of the text that I believe the OP is referring to. On Sun, Dec 10, 2017 at 3:01 AM, Alan Gauld via Tutor wrote: > On 10/12/17 05:07, jia yue Kee wrote: > >> in Dusty Philips's Python 3: Object-Oriented >> Programming book. > > Caveat: I've not read this book so can only > guess at what the author might be meaning. > >> Based on my reading, what I gathered was that Composition implies a >> relationship where the child cannot exist independent of the parent while >> Aggregation, on the other hand, implies a relationship where the child can >> exist independently of the parent. The author defines composition on page 17 as: "Composition is the act of collecting together several objects to compose a new one. Composition is usually a good choice when one object is part of another object." > Correct. But the key word here is "implies". > In some languages the differences can be directly > implemented in the language but in Python the > relationships are always just implied. The differences > do not really exist. (Unless you go to inordinate > lengths to hide and link the data, which is rarely, > if ever, justified.) > >> However, in one of the paragraph of the book, *Dusty mentioned that >> composition is aggregation* On page 18 the author goes on to use a chess set as an example aiming to use object-oriented design for a computer chess game. I _think_ the OP may be referring to this paragraph: "The chess set, then, is composed of a board and thirty-two pieces. The board is further comprised of sixty-four positions. You could argue that pieces are not part of the chess set because you could replace the pieces in a chess set with a different set of pieces. While this is unlikely or impossible in a computerized version of chess, it introduces us to *aggregation*. Aggregation is almost exactly like composition. The difference is that aggregate objects can exist independently. It would be impossible for a position to be associated with a different chess board, so we say the board is composed of positions. But the pieces, which might exist independently of the chess set, are said to be in an aggregate relationship with that set." He continues in the next paragraph: "Another way to differentiate between aggregation and composition is to think about the lifespan of the object. If the composite (outside) object controls when the related (inside) objects are created and destroyed, composition is most suitable. If the related object is created independently of the composite object, or can outlast that object, an aggregate relationship makes more sense. Also keep in mind that composition is aggregation; aggregation is simply a more general form of composition. Any composite relationship is also an aggregate relationship, but not vice versa." I think it is these last two sentences that are confusing the OP. Hope this provides more context to help the OP. boB From neilc at norwich.edu Mon Dec 11 08:14:35 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 11 Dec 2017 13:14:35 +0000 (UTC) Subject: [Tutor] Aggregation vs Composition References: Message-ID: On 2017-12-10, jia yue Kee wrote: > Good Day All, > > I am new to Python and I came across the concept of Composition > and Aggregation the other day in Dusty Philips's Python 3: > Object-Oriented Programming book. Welcome! > Based on my reading, what I gathered was that Composition > implies a relationship where the child cannot exist independent > of the parent while Aggregation, on the other hand, implies a > relationship where the child can exist independently of the > parent. > > However, in one of the paragraph of the book, *Dusty mentioned > that composition is aggregation* (refer to the snapshot below, > the sentence which has been highlighted in yellow). I am really > confused by this statement and I appreciate that if someone > could enlighten me on this as I do not really see how > aggregation can be equivalent to composition if the child in > one case can exist independently while the other could not > exist independently of the parent. Those statements are logically consistent if composition is a more strict form of aggregation--a form with the additional constrain that the objects cannot exist independently of their parent. In other words, in the text aggregation is a generlisation of composition. -- Neil Cerutti From alan.gauld at yahoo.co.uk Mon Dec 11 17:29:14 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Mon, 11 Dec 2017 22:29:14 +0000 Subject: [Tutor] Aggregation vs Composition In-Reply-To: References: Message-ID: On 11/12/17 00:40, boB Stepp wrote: > I own this book, too. I'll insert the portions of the text that I > believe the OP is referring to. Thanks for the clarification Bob. >>> composition is aggregation* > > On page 18 the author goes on to use a chess set as an example... > > He continues in the next paragraph: > > ... an aggregate relationship makes more sense. Also keep in mind > that composition is aggregation; aggregation is simply a more general > form of composition. Any composite relationship is also an aggregate > relationship, but not vice versa." That's true in Python, not so in other languages (eg C++) > I think it is these last two sentences that are confusing the OP. I think it probably is, it would confuse me too the first time I saw them. -- 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 rikudou__sennin at live.com Mon Dec 11 09:04:59 2017 From: rikudou__sennin at live.com (adil gourinda) Date: Mon, 11 Dec 2017 14:04:59 +0000 Subject: [Tutor] restructuredtext's documentation Message-ID: Hi Please I have two questions: 1) Why restructuredtext's documentation is not included as a part of the official Python's documentation? 2) Can you generate a restructuredtext's PDF documentaion from Docutils website(docutils.sourceforge.net/rst.html)? Thank you for your attention From alan.gauld at yahoo.co.uk Tue Dec 12 04:34:43 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 12 Dec 2017 09:34:43 +0000 Subject: [Tutor] restructuredtext's documentation In-Reply-To: References: Message-ID: On 11/12/17 14:04, adil gourinda wrote: > Hi > Please I have two questions: > > 1) Why restructuredtext's documentation is not included as a part of the official Python's documentation? Because the module is not part of the standard library. Like most languages Python has a standard library that ships with the interpreter. Anything beyond that has to be downloaded/installed. Those extras are not part of the standard library and therefore are not documented on the official site. Usually the third party module will have some kind of web site with its own documentation. > 2) Can you generate a restructuredtext's PDF > documentaion from Docutils website The simplest way is just to load the documentation page into a browser and print to a PDF file. There seems to only be one file so that should be all you need to do. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From steve at pearwood.info Tue Dec 12 04:11:50 2017 From: steve at pearwood.info (Steven D'Aprano) Date: Tue, 12 Dec 2017 20:11:50 +1100 Subject: [Tutor] restructuredtext's documentation In-Reply-To: References: Message-ID: <20171212091149.GL22248@ando.pearwood.info> On Mon, Dec 11, 2017 at 02:04:59PM +0000, adil gourinda wrote: > Hi > Please I have two questions: > > 1) Why restructuredtext's documentation is not included as a part of > the official Python's documentation? Because RestructuredText (ReST) is not part of Python. It is a project which uses Python. > 2) Can you generate a restructuredtext's PDF documentaion from > Docutils website(docutils.sourceforge.net/rst.html)? Sure. In your browser, go to the page you want, then choose Print from the browser File menu. When the printer dialog comes up, choose "Print To File", and set the options to PDF. -- Steve From chigga101 at gmail.com Tue Dec 12 14:43:14 2017 From: chigga101 at gmail.com (Matthew Ngaha) Date: Tue, 12 Dec 2017 19:43:14 +0000 Subject: [Tutor] When do you know you're ready to start applying for jobs? Message-ID: Hi all. I took 2-3 years off in 2012 to teach myself programming. I learnt basic Javascript & Python with some Django. I don't have a Computer Science (CS) degree so I never applied for a job because I always thought I still had lots to learn and most jobs say a CS degree is required. In 2015 I had to stop my learning to find a real minimum wage job as I needed to support myself. I will never know now if I would have got a python job had I applied. It's now december 2017, so I haven't touched programming in 2 years. I've forgotten most of what I learnt now. :( I'm now financially secure to give programming another go but I don't know how I feel about relearning everything I forgot. Is it's worth it? What are your thoughts? Can I get a junior programming job without a CS degree? When do you know you're ready to start applying for jobs? How can a self learner ever know? should I have applied for some jobs back in 2015 when I was still studying? What are your opinions on my situation? Is learning Python all over again worth it without a CS degree? would I be wasting my time? From leamhall at gmail.com Tue Dec 12 15:38:13 2017 From: leamhall at gmail.com (leam hall) Date: Tue, 12 Dec 2017 15:38:13 -0500 Subject: [Tutor] When do you know you're ready to start applying for jobs? In-Reply-To: References: Message-ID: On Tue, Dec 12, 2017 at 2:43 PM, Matthew Ngaha wrote: > Can I get a junior programming job without a CS degree? > When do you know you're ready to start applying for jobs? How can a > self learner ever know? > should I have applied for some jobs back in 2015 when I was still studying? > What are your opinions on my situation? Is learning Python all over > again worth it without a CS degree? would I be wasting my time? > Most of the bugs in current commercial software packages were written by CS grads. Keep that in mind. The real question is, "do you enjoy coding so much you stay a newbie?" There are always things to learn. Do the Tutor stuff. Do CodeWarrior. If you enjoy it then look at job listsing and play with the stuff they are asking for. Continue to take classes. Work through a book of advanced topics. Help with open source projects. Answer questions for newbies when you can. If that's the life you want to lead then jump in. It will be a second job that doesn't pay for a while, but if you keep it up you'll find the right spot. Leam From sjeik_appie at hotmail.com Tue Dec 12 18:00:23 2017 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Tue, 12 Dec 2017 23:00:23 +0000 Subject: [Tutor] restructuredtext's documentation Message-ID: Op 12 dec. 2017 10:52 schreef Steven D'Aprano : > > On Mon, Dec 11, 2017 at 02:04:59PM +0000, adil gourinda wrote: > > Hi > > Please I have two questions: > > > > 1) Why restructuredtext's documentation is not included as a part of > > the official Python's documentation? > > Because RestructuredText (ReST) is not part of Python. > > It is a project which uses Python. > > > > 2) Can you generate a restructuredtext's PDF documentaion from > > Docutils website(docutils.sourceforge.net/rst.html)? > > Sure. In your browser, go to the page you want, then choose Print from > the browser File menu. When the printer dialog comes up, choose "Print > To File", and set the options to PDF. You could also try using a tool called pandoc, though you will also need LaTex/texlive for it (quite big). Alternatively: https://pypi.python.org/pypi/rst2pdf From Sunnlotus at aol.com Tue Dec 12 15:01:15 2017 From: Sunnlotus at aol.com (Rex) Date: Tue, 12 Dec 2017 15:01:15 -0500 Subject: [Tutor] When do you know you're ready to start applying for jobs? In-Reply-To: References: Message-ID: <12599EEC-8DD3-4EB3-B182-BCC1C8AE7F2B@aol.com> Hi Matthew, I am 61 years old and started to learn Python last winter to both exercise my mind and get a better handle on what this world of technology has become. I?ve got a degree in biochemistry which I?ve never used professionally and the only programming experience I ever had was in college with Fortran which did not agree with me. On the other hand I have done some CNC programming the old fashioned way in the 1970?s by typing on a teletype to a paper punch tape the x, y, i, j, and m codes that controlled machine tools. My experience with Python has opened my eyes to a whole new world and I think you under estimated yourself when you chose a minimum wage job over seeking employment in coding. From everything I have learned and read about, you have a valuable asset with what you have already learned. In my opinion, it will not be too difficult to get back on the horse and in fact you will probably be an even better programmer due to the reinforcement learning that will occur as you re-learn Python. Remember, in this life, you must take risks to succeed and have confidence in yourself. Genius is 1% inspiration and 99% perspiration. Go for it. Sent from my iPhone > On Dec 12, 2017, at 2:43 PM, Matthew Ngaha wrote: > > Hi all. I took 2-3 years off in 2012 to teach myself programming. I > learnt basic Javascript & Python with some Django. I don't have a > Computer Science (CS) degree so I never applied for a job because I > always thought I still had lots to learn and most jobs say a CS degree > is required. In 2015 I had to stop my learning to find a real minimum > wage job as I needed to support myself. I will never know now if I > would have got a python job had I applied. It's now december 2017, so > I haven't touched programming in 2 years. I've forgotten most of what > I learnt now. :( I'm now financially secure to give programming > another go but I don't know how I feel about relearning everything I > forgot. Is it's worth it? What are your thoughts? > > Can I get a junior programming job without a CS degree? > When do you know you're ready to start applying for jobs? How can a > self learner ever know? > should I have applied for some jobs back in 2015 when I was still studying? > What are your opinions on my situation? Is learning Python all over > again worth it without a CS degree? would I be wasting my time? > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor From alan.gauld at yahoo.co.uk Tue Dec 12 18:37:28 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 12 Dec 2017 23:37:28 +0000 Subject: [Tutor] When do you know you're ready to start applying for jobs? In-Reply-To: References: Message-ID: On 12/12/17 19:43, Matthew Ngaha wrote: > Hi all. I took 2-3 years off in 2012 to teach myself programming. I > learnt basic Javascript & Python with some Django. I don't have a > Computer Science (CS) degree The key issue here is what is true in your locality. In my part of the world the vast majority of programmers do NOT have a CS (or software engineering degree - something quite different). But they a majority do have a degree with a numerical bias(science, engineering, maths etc) On the other hand I've worked with programmers who studied business law, zoology and even music. And quite a few with no degree at all. But I know of other places where a degree is essential and in some places it has to be computing related. So it all depends on your local practices and I can't comment on that. > ...so I never applied for a job because I > always thought I still had lots to learn and most jobs say a CS degree But you certainly do have a lot to learn, and in computing you never stop having lots to learn. It is one of the fastest moving industries around. Much (most?) of what you learn today will have changed in 10 years time. But there are things you can learn now that won't ever change. And that includes the principles of design - an aspect all too often ignored by people learning "programming" But you can't build a significant system of any kind without an underlying design. And you can't build big systems without understanding architecture. And there are standard design patterns and architectural patterns that you can learn (MVC, State machines, Client-Server etc). There are principles (like coupling and cohesion) and axioms like DRY. There are performance patterns too, understanding O() notation and the factors that affect it. Then there are industry practices and tools. Do you know about version and release control? Debugging tools? Profiling? Hopefully you see where I'm going - you never stop learning and you can waste a lot of time becoming an expert in things that will be of no use in a few years, or you can focus on principles that are the very basis of system design and construction. There is a big gulf between being a "programmer" and being a professional software engineer. Your best bet may be to get a job in a small one man shop building small web sites for small businesses. That way you can learn about the deeper issues as you go, in a kind of apprenticeship. But don't get hung up on languages or frameworks - these things come and go like fashions on a catwalk. If you understand the principles you will learn new languages in a matter of days and weeks. Frameworks in weeks or months. > I haven't touched programming in 2 years. I've forgotten most of what > I learnt now. Two years is not long. Try it in your spare time. If it isn't coming back within a week then maybe its not for you, or maybe just as a hobby. But if you have a talent for it you should find it falls into place quite quickly. But programming for fun is a worthwhile thing too. I never code for profit these days but I still write code every week and usually have 2 or 3 projects simmering away at any one time. They make my life easier and I enjoy coding them - it's a win-win. > Can I get a junior programming job without a CS degree? > When do you know you're ready to start applying for jobs? How can a > self learner ever know? That all depends on local circumstances and the individual. If in doubt try joining an open source project. If you can get to the stage where the other developers treat you as an equal then you are definitely ready for a job! (And it's good to have on your CV/resume) HTH -- 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 james at uplinkzero.com Wed Dec 13 12:27:16 2017 From: james at uplinkzero.com (James Chapman) Date: Wed, 13 Dec 2017 17:27:16 +0000 Subject: [Tutor] How to debug a memory leak in a wsgi application? In-Reply-To: <724b9fb7-ccee-c8a1-62f0-938c2b8dbf22@yandex.com> References: <73793f05-d918-b6a1-5d88-fda9e399dba9@yandex.com> <724b9fb7-ccee-c8a1-62f0-938c2b8dbf22@yandex.com> Message-ID: Why pymalloc? I presume this means you're using ctypes which means I have more questions. If you're allocating your own blocks of memory then you need to free them too. IE, does each call to pymalloc have a corresponding call to pyfree? Is the overhead of pythons built in malloc really a problem? Are you changing pointers before you've freed the corresponding block of memory? There are many ways to create a memory leak, all of them eliminated by letting python handle your memory allocations. But, back to your original question, check out "valgrind". HTH -- James On 6 December 2017 at 16:23, Etienne Robillard wrote: > Hi Alan, > > Thanks for the reply. I use Debian 9 with 2G of RAM and precompiled Python > 2.7 with pymalloc. I don't know if debugging was enabled for this build and > whether I should enable it to allow memory profiling with guppy... My > problem is that guppy won't show the heap stats for the uWSGI master > process. However I have partially resolved this issue by enabling > --reload-on-rss 200 for the uwsgi process. Previously, the htop utility > indicated a 42.7% rss memory usage for 2 uWSGI processes. I have restarted > the worker processes with SIGINT signal. Now my uwsgi command line looks > like: > > % uwsgi --reload-on-rss 200 --gevent 100 --socket localhost:8000 > --with-file /path/to/file.uwsgi --threads 2 --processes 4 --master > --daemonize /var/log/uwsgi.log > > My framework is Django with django-hotsauce 0.8.2 and werkzeug. The web > server is nginx using uWSGI with the gevent pooling handler. > > Etienne > > Le 2017-12-06 ? 10:00, Alan Gauld via Tutor a ?crit : > >> On 06/12/17 09:21, Etienne Robillard wrote: >> >>> Hi >>> >>> I think my wsgi application is leaking and I would like to debug it. >>> >>> What is the best way to profile memory usage in a running wsgi app? >>> >> This is probably a bit advanced for the tutor list, you might >> get a better response on the main Python list. >> >> But to get a sensible answer you need to provide more data: >> What OS and Python version? >> What toolset/framework are you using? >> What measurements lead you to suspect a memory leak? >> >> >> > -- > Etienne Robillard > tkadm30 at yandex.com > https://www.isotopesoftware.ca/ > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > From tkadm30 at yandex.com Wed Dec 13 13:30:12 2017 From: tkadm30 at yandex.com (Etienne Robillard) Date: Wed, 13 Dec 2017 13:30:12 -0500 Subject: [Tutor] How to debug a memory leak in a wsgi application? In-Reply-To: References: <73793f05-d918-b6a1-5d88-fda9e399dba9@yandex.com> <724b9fb7-ccee-c8a1-62f0-938c2b8dbf22@yandex.com> Message-ID: <236a2e85-78ca-1131-eb68-6253421b3d9e@yandex.com> Hi James, Thank for your reply. Are you suggesting that under Linux the malloc() glibc library call is more memory efficient than using pymalloc? Best regards, Etienne Le 2017-12-13 ? 12:27, James Chapman a ?crit?: > Why pymalloc? I presume this means you're using ctypes which means I > have more questions. > > If you're allocating your own blocks of memory then you need to free > them too. IE, does each call to pymalloc have a corresponding call to > pyfree? > > Is the overhead of pythons built in malloc really a problem? > > Are you changing pointers before you've freed the corresponding block > of memory? > > There are many ways to create a memory leak, all of them eliminated by > letting python handle your memory allocations. > > But, back to your original question, check out "valgrind". > > HTH > > -- > James > > On 6 December 2017 at 16:23, Etienne Robillard > wrote: > > Hi Alan, > > Thanks for the reply. I use Debian 9 with 2G of RAM and > precompiled Python 2.7 with pymalloc. I don't know if debugging > was enabled for this build and whether I should enable it to allow > memory profiling with guppy... My problem is that guppy won't show > the heap stats for the uWSGI master process. However I have > partially resolved this issue by enabling --reload-on-rss 200 for > the uwsgi process.? Previously, the htop utility indicated a 42.7% > rss memory usage for 2 uWSGI processes. I have restarted the > worker processes with SIGINT signal. Now my uwsgi command line > looks like: > > % uwsgi --reload-on-rss 200 --gevent 100 --socket localhost:8000 > --with-file /path/to/file.uwsgi --threads 2 --processes 4 --master > --daemonize /var/log/uwsgi.log > > My framework is Django with django-hotsauce 0.8.2 and werkzeug. > The web server is nginx using uWSGI with the gevent pooling handler. > > Etienne > > Le 2017-12-06 ? 10:00, Alan Gauld via Tutor a ?crit?: > > On 06/12/17 09:21, Etienne Robillard wrote: > > Hi > > I think my wsgi application is leaking and I would like to > debug it. > > What is the best way to profile memory usage in a running > wsgi app? > > This is probably a bit advanced for the tutor list, you might > get a better response on the main Python list. > > But to get a sensible answer you need to provide more data: > What OS and Python version? > What toolset/framework are you using? > What measurements lead you to suspect a memory leak? > > > > -- > Etienne Robillard > tkadm30 at yandex.com > https://www.isotopesoftware.ca/ > > _______________________________________________ > Tutor maillist? - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > > > -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From james at uplinkzero.com Thu Dec 14 04:44:16 2017 From: james at uplinkzero.com (James Chapman) Date: Thu, 14 Dec 2017 09:44:16 +0000 Subject: [Tutor] How to debug a memory leak in a wsgi application? In-Reply-To: <236a2e85-78ca-1131-eb68-6253421b3d9e@yandex.com> References: <73793f05-d918-b6a1-5d88-fda9e399dba9@yandex.com> <724b9fb7-ccee-c8a1-62f0-938c2b8dbf22@yandex.com> <236a2e85-78ca-1131-eb68-6253421b3d9e@yandex.com> Message-ID: No, I'm saying you shouldn't need to make any kind of malloc calls manually. Python handles memory allocation and deallocation on your behalf. Why do you need to call pymalloc? Are you using ctypes? And if you are I presume this is then to make C-calls into a shared library? James -- James On 13 December 2017 at 18:30, Etienne Robillard wrote: > Hi James, > > Thank for your reply. Are you suggesting that under Linux the malloc() > glibc library call is more memory efficient than using pymalloc? > > Best regards, > > Etienne > > Le 2017-12-13 ? 12:27, James Chapman a ?crit : > > Why pymalloc? I presume this means you're using ctypes which means I have > more questions. > > If you're allocating your own blocks of memory then you need to free them > too. IE, does each call to pymalloc have a corresponding call to pyfree? > > Is the overhead of pythons built in malloc really a problem? > > Are you changing pointers before you've freed the corresponding block of > memory? > > There are many ways to create a memory leak, all of them eliminated by > letting python handle your memory allocations. > > But, back to your original question, check out "valgrind". > > HTH > > -- > James > > On 6 December 2017 at 16:23, Etienne Robillard wrote: > >> Hi Alan, >> >> Thanks for the reply. I use Debian 9 with 2G of RAM and precompiled >> Python 2.7 with pymalloc. I don't know if debugging was enabled for this >> build and whether I should enable it to allow memory profiling with >> guppy... My problem is that guppy won't show the heap stats for the uWSGI >> master process. However I have partially resolved this issue by enabling >> --reload-on-rss 200 for the uwsgi process. Previously, the htop utility >> indicated a 42.7% rss memory usage for 2 uWSGI processes. I have restarted >> the worker processes with SIGINT signal. Now my uwsgi command line looks >> like: >> >> % uwsgi --reload-on-rss 200 --gevent 100 --socket localhost:8000 >> --with-file /path/to/file.uwsgi --threads 2 --processes 4 --master >> --daemonize /var/log/uwsgi.log >> >> My framework is Django with django-hotsauce 0.8.2 and werkzeug. The web >> server is nginx using uWSGI with the gevent pooling handler. >> >> Etienne >> >> Le 2017-12-06 ? 10:00, Alan Gauld via Tutor a ?crit : >> >>> On 06/12/17 09:21, Etienne Robillard wrote: >>> >>>> Hi >>>> >>>> I think my wsgi application is leaking and I would like to debug it. >>>> >>>> What is the best way to profile memory usage in a running wsgi app? >>>> >>> This is probably a bit advanced for the tutor list, you might >>> get a better response on the main Python list. >>> >>> But to get a sensible answer you need to provide more data: >>> What OS and Python version? >>> What toolset/framework are you using? >>> What measurements lead you to suspect a memory leak? >>> >>> >>> >> -- >> Etienne Robillard >> tkadm30 at yandex.com >> https://www.isotopesoftware.ca/ >> >> _______________________________________________ >> Tutor maillist - Tutor at python.org >> To unsubscribe or change subscription options: >> https://mail.python.org/mailman/listinfo/tutor >> > > > -- > Etienne Robillardtkadm30 at yandex.comhttps://www.isotopesoftware.ca/ > > From james at uplinkzero.com Thu Dec 14 05:46:23 2017 From: james at uplinkzero.com (James Chapman) Date: Thu, 14 Dec 2017 10:46:23 +0000 Subject: [Tutor] How to debug a memory leak in a wsgi application? In-Reply-To: References: <73793f05-d918-b6a1-5d88-fda9e399dba9@yandex.com> <724b9fb7-ccee-c8a1-62f0-938c2b8dbf22@yandex.com> <236a2e85-78ca-1131-eb68-6253421b3d9e@yandex.com> Message-ID: ?Ah OK, now I understand why you mentioned pymalloc to begin with. I'm not familiar with uWSGI or cython. That said, why do you think it's uWSGI causing a leak? It seems unlikely. Python projects can grow in size if you're not dereferencing objects... (see https://f0rki.at/hunting-memory-leaks-in-python.html) If you use valgrind combined with python memory_profiler you should hopefully be able to get an idea as to where the leak is coming from. It's probably in your own code and leaks can be incredibly difficult to track down. Typically while reviewing your own code you end up skipping over the error time and time again because you become blind to your errors, so it might help to have someone else peer review it. These 2 links are a good starting point. https://github.com/KratosMultiphysics/Kratos/wiki/Checking-memory-usage-with-Valgrind https://github.com/pythonprofilers/memory_profiler One last note, if you are doing any of your own memory allocations, then make sure you're also freeing them: https://cython.readthedocs.io/en/latest/src/tutorial/memory_allocation.html But note, if you did this in cython: cdef double* data data = PyMem_Malloc(100 * sizeof(double)) data = PyMem_Malloc(100 * sizeof(double)) PyMem_Free(data) You would (probably, you would in C/C++) end up with a leak because you've changed the pointer. When you go to free it, only the 2nd allocation will be freed and you'll have no way of freeing the first. HTH From tkadm30 at yandex.com Thu Dec 14 05:05:59 2017 From: tkadm30 at yandex.com (Etienne Robillard) Date: Thu, 14 Dec 2017 05:05:59 -0500 Subject: [Tutor] How to debug a memory leak in a wsgi application? In-Reply-To: References: <73793f05-d918-b6a1-5d88-fda9e399dba9@yandex.com> <724b9fb7-ccee-c8a1-62f0-938c2b8dbf22@yandex.com> <236a2e85-78ca-1131-eb68-6253421b3d9e@yandex.com> Message-ID: Hi again James, Le 2017-12-14 ? 04:44, James Chapman a ?crit?: > No, I'm saying you shouldn't need to make any kind of malloc calls > manually. Python handles memory allocation and deallocation on your > behalf. All I did is installing a precompiled Python 2.7 build from the Debian repository. I believe it was built with pymalloc and debugging. > Why do you need to call pymalloc? I have not yet took the time to manually compile Python without pymalloc. > Are you using ctypes? No. > And if you are I presume this is then to make C-calls into a shared > library? I use Cython instead of ctypes. I'm guessing the memory leak was not caused by the Cython-generated C code, but from the uWSGI backend. Cheers, Etienne > > > > -- > James > > On 13 December 2017 at 18:30, Etienne Robillard > wrote: > > Hi James, > > Thank for your reply. Are you suggesting that under Linux the > malloc() glibc library call is more memory efficient than using > pymalloc? > > Best regards, > > Etienne > > > Le 2017-12-13 ? 12:27, James Chapman a ?crit?: >> Why pymalloc? I presume this means you're using ctypes which >> means I have more questions. >> >> If you're allocating your own blocks of memory then you need to >> free them too. IE, does each call to pymalloc have a >> corresponding call to pyfree? >> >> Is the overhead of pythons built in malloc really a problem? >> >> Are you changing pointers before you've freed the corresponding >> block of memory? >> >> There are many ways to create a memory leak, all of them >> eliminated by letting python handle your memory allocations. >> >> But, back to your original question, check out "valgrind". >> >> HTH >> >> -- >> James >> >> On 6 December 2017 at 16:23, Etienne Robillard >> > wrote: >> >> Hi Alan, >> >> Thanks for the reply. I use Debian 9 with 2G of RAM and >> precompiled Python 2.7 with pymalloc. I don't know if >> debugging was enabled for this build and whether I should >> enable it to allow memory profiling with guppy... My problem >> is that guppy won't show the heap stats for the uWSGI master >> process. However I have partially resolved this issue by >> enabling --reload-on-rss 200 for the uwsgi process.? >> Previously, the htop utility indicated a 42.7% rss memory >> usage for 2 uWSGI processes. I have restarted the worker >> processes with SIGINT signal. Now my uwsgi command line looks >> like: >> >> % uwsgi --reload-on-rss 200 --gevent 100 --socket >> localhost:8000 --with-file /path/to/file.uwsgi --threads 2 >> --processes 4 --master --daemonize /var/log/uwsgi.log >> >> My framework is Django with django-hotsauce 0.8.2 and >> werkzeug. The web server is nginx using uWSGI with the gevent >> pooling handler. >> >> Etienne >> >> Le 2017-12-06 ? 10:00, Alan Gauld via Tutor a ?crit?: >> >> On 06/12/17 09:21, Etienne Robillard wrote: >> >> Hi >> >> I think my wsgi application is leaking and I would >> like to debug it. >> >> What is the best way to profile memory usage in a >> running wsgi app? >> >> This is probably a bit advanced for the tutor list, you might >> get a better response on the main Python list. >> >> But to get a sensible answer you need to provide more data: >> What OS and Python version? >> What toolset/framework are you using? >> What measurements lead you to suspect a memory leak? >> >> >> >> -- >> Etienne Robillard >> tkadm30 at yandex.com >> https://www.isotopesoftware.ca/ >> >> _______________________________________________ >> Tutor maillist? - Tutor at python.org >> To unsubscribe or change subscription options: >> https://mail.python.org/mailman/listinfo/tutor >> >> >> > > -- > Etienne Robillard > tkadm30 at yandex.com > https://www.isotopesoftware.ca/ > > -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From chigga101 at gmail.com Thu Dec 14 15:30:44 2017 From: chigga101 at gmail.com (Matthew Ngaha) Date: Thu, 14 Dec 2017 20:30:44 +0000 Subject: [Tutor] When do you know you're ready to start applying for jobs? In-Reply-To: References: Message-ID: Thank you all for replying, I really appreciate it. It's all I've been thinking about lately and your responses have really cleared up a lot of things for me. On Tue, Dec 12, 2017 at 11:37 PM, Alan Gauld via Tutor wrote: > > But there are things you can learn now that won't ever change. > And that includes the principles of design - an aspect all too > often ignored by people learning "programming" But you can't > build a significant system of any kind without an underlying > design. And you can't build big systems without understanding architecture. > Thanks Alan you gave a really profound reply and I've been digesting it slowly but surely. Can you give me any tips on how I can improve on this (where I quoted you). And are there any books or tutorials you can recommend for me. > Hopefully you see where I'm going - you never stop learning > and you can waste a lot of time becoming an expert in things > that will be of no use in a few years, or you can focus on > principles that are the very basis of system design and > construction. > Yes I see where you're going. I just need a push in the right direction on where I can learn about the principles of system design. Also why isn't this taught in beginner tutorials, or is it an advanced concept? Thanks again for your response. I remember years ago your website was one of the 1st tutorials I read on python. Recently I needed a refresher on the os module and I recalled you covered it extensively, but sadly I found it's no longer on your site. It says under construction. Any ideas of when that will be finished? Thanks again. From alan.gauld at yahoo.co.uk Thu Dec 14 19:21:59 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 15 Dec 2017 00:21:59 +0000 Subject: [Tutor] When do you know you're ready to start applying for jobs? In-Reply-To: References: Message-ID: On 14/12/17 20:30, Matthew Ngaha wrote: > direction on where I can learn about the principles of system design. > Also why isn't this taught in beginner tutorials, or is it an advanced > concept? It's advanced compared to programming, but there are lots of books on the subject, especially OO design. If your local library has an ordering scheme I'd recommend starting with Coad & Youdon's two books - OOA and OOD. Although his notation has been superseded by UML (another area you could usefully research online) the principles of design (especially in the yellow design book) are still valid. The books are short and fairly non-technical, so quite easy to read. (But very expensive so I don't recommend buying them new! But I've just noticed they are very cheap 2nd hand on Amazon...) Other good design books include Grady Booch's OOD book (ideally the first edition) where again the notation is now irrelevant but the principles are sound. And for a slightly more modern twist look for Design Patterns by Gamma et al. There are also books on architecture although they are often domain specific, so you can find stuff on network architecture, data architectures, web architectures and service oriented architectures, as examples. Wikipedia is probably a good place to start on that topic. > refresher on the os module and I recalled you covered it extensively, > but sadly I found it's no longer on your site. The v2 material is still there but I haven't got round to porting it to v3. (It is covered in my paper book "Python Projects" which is effectively that whole section of my tutor in dead tree format) I'm about to do a full revision of the tutor which should include writing the missing topics in that section. HTH -- 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 akleider at sonic.net Thu Dec 14 21:16:43 2017 From: akleider at sonic.net (Alex Kleider) Date: Thu, 14 Dec 2017 18:16:43 -0800 Subject: [Tutor] When do you know you're ready to start applying for jobs? In-Reply-To: References: Message-ID: <1a3283cc36016829dfd6dbd420994e33@sonic.net> On 2017-12-14 16:21, Alan Gauld via Tutor wrote: > On 14/12/17 20:30, Matthew Ngaha wrote: >> direction on where I can learn about the principles of system design. >> Also why isn't this taught in beginner tutorials, or is it an advanced >> concept? > > It's advanced compared to programming, but there are lots of > books on the subject, especially OO design. If your local library > has an ordering scheme I'd recommend starting with > Coad & Youdon's two books - OOA and OOD. > > Although his notation has been superseded by UML (another > area you could usefully research online) the principles of design > (especially in the yellow design book) are still valid. The books > are short and fairly non-technical, so quite easy to read. (But > very expensive so I don't recommend buying them new! But > I've just noticed they are very cheap 2nd hand on Amazon...) $4.99 and $6.89 to be exact (amazon prime in the US) > From lloydwalker2 at gmail.com Fri Dec 15 13:46:01 2017 From: lloydwalker2 at gmail.com (Lloyd Walker) Date: Fri, 15 Dec 2017 18:46:01 +0000 Subject: [Tutor] Writing data to JSON Help Message-ID: Dear All, I'm currently writing a script to scrape data from my favourite podcasting websites and compile latter data into JSON format in order to create a local website of these websites. I'm currently using string formatting to create the json rather than creating a dictionary and appending that dictionary to file via the JSON lib. Could you help me create a dictionary using JSON? Code: https://gist.github.com/anonymous/42ff1e418ab315c9637f3ffe08ab0a2b Kind Regards, Lloyd Walker [image: Inline image 1] From alan.gauld at yahoo.co.uk Fri Dec 15 18:41:12 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 15 Dec 2017 23:41:12 +0000 Subject: [Tutor] Writing data to JSON Help In-Reply-To: References: Message-ID: On 15/12/17 18:46, Lloyd Walker wrote: > I'm currently using string formatting to create the json rather than > creating a dictionary and appending that dictionary to file via the JSON > lib. That's probably your mistake. The standard library is there to help you get difficult things right. Trying to reinvent it is a great way to discover how difficult apparently simple things really are. it's also a terrible way to accomplish anything productive. > Could you help me create a dictionary using JSON? > > Code: https://gist.github.com/anonymous/42ff1e418ab315c9637f3ffe08ab0a2b One thing I'd strongly suggest is to separate out your functions. Your findLinks function does a lot more than find links. Just return the list of links and create another function to store them (in whatever format you wish). Then I suggest you write that new function using the json module. That will greatly improve your chances of success. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From mats at wichmann.us Fri Dec 15 19:19:58 2017 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 15 Dec 2017 17:19:58 -0700 Subject: [Tutor] Writing data to JSON Help In-Reply-To: References: Message-ID: <47f4ebbb-c922-9692-743d-22376eac2774@wichmann.us> On 12/15/2017 04:41 PM, Alan Gauld via Tutor wrote: > On 15/12/17 18:46, Lloyd Walker wrote: > >> I'm currently using string formatting to create the json rather than >> creating a dictionary and appending that dictionary to file via the JSON >> lib. > > That's probably your mistake. The standard library is there to > help you get difficult things right. Trying to reinvent it is > a great way to discover how difficult apparently simple things > really are. it's also a terrible way to accomplish anything > productive. > >> Could you help me create a dictionary using JSON? >> >> Code: https://gist.github.com/anonymous/42ff1e418ab315c9637f3ffe08ab0a2b > > One thing I'd strongly suggest is to separate out your functions. > Your findLinks function does a lot more than find links. Just > return the list of links and create another function to store > them (in whatever format you wish). "simple is better". as in... if your code is easy to understand, it's way easier to debug. also, has_key is no longer favored in the Python world (that is not what is wrong with your code). From __peter__ at web.de Sat Dec 16 08:57:44 2017 From: __peter__ at web.de (Peter Otten) Date: Sat, 16 Dec 2017 14:57:44 +0100 Subject: [Tutor] Writing data to JSON Help References: <47f4ebbb-c922-9692-743d-22376eac2774@wichmann.us> Message-ID: Mats Wichmann wrote: > also, has_key is no longer favored in the Python world (that is not what > is wrong with your code). But then the beautiful soup is a world on its own: $ python3 Python 3.4.3 (default, Nov 28 2017, 16:41:13) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from bs4 import BeautifulSoup as BS >>> soup = BS("""withwithout""") >>> [a for a in soup.find_all("a") if "href" in a] [] >>> [a for a in soup.find_all("a") if a.has_key("href")] /usr/lib/python3/dist-packages/bs4/element.py:1400: UserWarning: has_key is deprecated. Use has_attr("href") instead. key)) [with] At least they seem to be moving in the right direction. From juanmayenjm at gmail.com Mon Dec 18 10:42:16 2017 From: juanmayenjm at gmail.com (=?UTF-8?Q?Juan_May=C3=A9n?=) Date: Mon, 18 Dec 2017 09:42:16 -0600 Subject: [Tutor] Welcome to the "Tutor" mailing list In-Reply-To: References: Message-ID: Introduction: Hi everyone I am Juan and I briefly got into coding early fall but then had to stop because my Master's program demanded more time. I had started learning Linux and completing banditoverthewire exercises. Now though I am interested in at least building one small application, I was thinking of building a web crawler, or create a bot that will help me place trades in crypto currency market. All suggestions and recommendations are welcomed!! thanks, Juan M. On Mon, Dec 18, 2017 at 9:34 AM, wrote: > Welcome to the Tutor at python.org mailing list! This list is for folks > who want to ask (and/or answer) questions from folks who wish to learn > how to program with Python. Feel free to ask even the most basic of > questions -- that's what the list is for! > > For best results when asking a question on this list: - Try to write > some code to solve your problem - Show the code you have written - > Describe what the code does and what you want it to do - If the code > generates an error, copy and paste the entire error message, including > the traceback, into your email. - Tell us what OS and Python version > you are using. > > - Don't ask us to do your homework. - Don't assume we know what you > are talking about. If you are having trouble with a third-party > library, include a link to the library home page. > > When replying to a posting: - Use Reply All to reply to the entire > list - Don't top post - put your reply after the text to which you are > replying > > For all posts: - Format your email as plain text, not HTML > > > To post to this list, send your message to: > > tutor at python.org > > General information about the mailing list is at: > > https://mail.python.org/mailman/listinfo/tutor > > If you ever want to unsubscribe or change your options (eg, switch to > or from digest mode, change your password, etc.), visit your > subscription page at: > > https://mail.python.org/mailman/options/tutor/juanmayenjm%40gmail.com > > > You can also make such adjustments via email by sending a message to: > > Tutor-request at python.org > > with the word `help' in the subject or body (don't include the > quotes), and you will get back a message with instructions. > > You must know your password to change your options (including changing > the password, itself) or to unsubscribe without confirmation. It is: > > amazing > > Normally, Mailman will remind you of your python.org mailing list > passwords once every month, although you can disable this if you > prefer. This reminder will also include instructions on how to > unsubscribe or change your account options. There is also a button on > your options page that will email your current password to you. > -- University of Central Arkansas '15 From rls4jc at gmail.com Mon Dec 18 17:09:10 2017 From: rls4jc at gmail.com (Roger Lea Scherer) Date: Mon, 18 Dec 2017 14:09:10 -0800 Subject: [Tutor] Floating decimal question Message-ID: This is my first time in this "forum", please be patient I will do my best. As I was going through a book and came across this challenge, I did what I believe was a success. And I know there are ways of making the decimal place be limited to 2 places, but my question is more of understanding why the following happened. This is the code I wrote in python: bill = float(input("What is the price of the bill?: ")) tip15 = bill*1.15 tip20 = bill*1.20 print("Bill plus 15% gratuity is " + str(tip15)) print("Bill plus 20% gratuity is " + str(tip20)) This is the result I got after I ran the code in an IDE (obviously) and then entered 29.99 in the first line: What is the price of the bill?: 29.99 Bill plus 15% gratuity is 34.488499999999995 Bill plus 20% gratuity is 35.988 My question is why does the 15% gratuity go so far beyond the decimal place when really there should only be 4 places because of multiplication rules, you know, and I do understand sometimes things work behind the scenes that you don't see, but on the 20% gratuity it gives the "right" answer? So I guess I'm just asking why did this happen like this? Thank you. From alan.gauld at yahoo.co.uk Mon Dec 18 19:30:15 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 19 Dec 2017 00:30:15 +0000 Subject: [Tutor] Welcome to the "Tutor" mailing list In-Reply-To: References: Message-ID: On 18/12/17 15:42, Juan May?n wrote: > learning Linux and completing banditoverthewire exercises. Now though I am > interested in at least building one small application, I was thinking of > building a web crawler, or create a bot that will help me place trades in > crypto currency market. > > All suggestions and recommendations are welcomed!! Popular wisdom suggests that the third party package "Requests" is superior to the standard library urllib.request module for web access. You might like to start with its documentation and examples. For parsing the HTML returned you can use ElementTree (etree) or some of the other third party modules. But etree usually suffices. Try writing something and if you get stuck send us the offending code and any error messages(unedited please) Plus any input/output data. -- 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 Mon Dec 18 19:45:55 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 19 Dec 2017 00:45:55 +0000 Subject: [Tutor] Floating decimal question In-Reply-To: References: Message-ID: On 18/12/17 22:09, Roger Lea Scherer wrote: > bill = float(input("What is the price of the bill?: ")) > tip15 = bill*1.15 > tip20 = bill*1.20 > > print("Bill plus 15% gratuity is " + str(tip15)) > print("Bill plus 20% gratuity is " + str(tip20)) > > This is the result > Bill plus 15% gratuity is 34.488499999999995 > Bill plus 20% gratuity is 35.988 > > My question is why does the 15% gratuity go so far beyond the decimal place > when really there should only be 4 places because of multiplication rules, Remember this is binary arithmetic not decimal. The number of decimal points is not something the computer sees. Also, when working with monetary values you should get into the habit of either using the Decimal module or converting to pennies, although that still won't help if multiplying by fractions - you'd need to convert the percents into full figures too. Look up floating point accuracy on Wikipedia they have a good explanation of what you are seeing. https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems -- 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 hristovantoan1 at gmail.com Tue Dec 19 04:47:40 2017 From: hristovantoan1 at gmail.com (Antoan Hristov) Date: Tue, 19 Dec 2017 11:47:40 +0200 Subject: [Tutor] Problem python script Message-ID: Hello, I am using a script which extracts data from internet every Monday, but sometimes I have a problem that the script is not finishing properly. In terminal I stop it with Ctrl-C and the message it gives me is: File "castorama.py", line 255, in main p.map(get_all_data,magasins) File "/usr/lib/python3.5/multiprocessing/pool.py", line 260, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "/usr/lib/python3.5/multiprocessing/pool.py", line 602, in get self.wait(timeout) File "/usr/lib/python3.5/multiprocessing/pool.py", line 599, in wait self._event.wait(timeout) File "/usr/lib/python3.5/threading.py", line 549, in wait Traceback (most recent call last): File "/usr/lib/python3.5/multiprocessing/process.py", line 249, in _bootstrap self.run() File "/usr/lib/python3.5/multiprocessing/process.py", line 93, in run self._target(*self._args, **self._kwargs) File "/usr/lib/python3.5/multiprocessing/pool.py", line 108, in worker task = get() File "/usr/lib/python3.5/multiprocessing/queues.py", line 342, in get with self._rlock: Traceback (most recent call last): File "/usr/lib/python3.5/multiprocessing/synchronize.py", line 96, in __enter__ return self._semlock.__enter__() File "/usr/lib/python3.5/multiprocessing/process.py", line 249, in _bootstrap self.run() KeyboardInterrupt File "/usr/lib/python3.5/multiprocessing/process.py", line 93, in run self._target(*self._args, **self._kwargs) File "/usr/lib/python3.5/multiprocessing/pool.py", line 108, in worker task = get() File "/usr/lib/python3.5/multiprocessing/queues.py", line 342, in get with self._rlock: File "/usr/lib/python3.5/multiprocessing/synchronize.py", line 96, in __enter__ return self._semlock.__enter__() KeyboardInterrupt Traceback (most recent call last): File "/usr/lib/python3.5/multiprocessing/process.py", line 249, in _bootstrap self.run() File "/usr/lib/python3.5/multiprocessing/process.py", line 93, in run self._target(*self._args, **self._kwargs) File "/usr/lib/python3.5/multiprocessing/pool.py", line 108, in worker task = get() File "/usr/lib/python3.5/multiprocessing/queues.py", line 342, in get with self._rlock: File "/usr/lib/python3.5/multiprocessing/synchronize.py", line 96, in __enter__ return self._semlock.__enter__() KeyboardInterrupt signaled = self._cond.wait(timeout) File "/usr/lib/python3.5/threading.py", line 293, in wait waiter.acquire() KeyboardInterrupt Traceback (most recent call last): File "/usr/lib/python3.5/multiprocessing/process.py", line 249, in _bootstrap self.run() File "/usr/lib/python3.5/multiprocessing/process.py", line 93, in run self._target(*self._args, **self._kwargs) File "/usr/lib/python3.5/multiprocessing/pool.py", line 108, in worker task = get() File "/usr/lib/python3.5/multiprocessing/queues.py", line 343, in get res = self._reader.recv_bytes() File "/usr/lib/python3.5/multiprocessing/connection.py", line 216, in recv_bytes buf = self._recv_bytes(maxlength) File "/usr/lib/python3.5/multiprocessing/connection.py", line 407, in _recv_bytes buf = self._recv(4) File "/usr/lib/python3.5/multiprocessing/connection.py", line 379, in _recv chunk = read(handle, remaining) KeyboardInterrupt I am using map function on a list and a pool of processes. I attach a picture that show some information which I extract and I print everytime but as shown the script stopped to print and blocked so the left opportunity is to Ctrc-C. I would be really grateful If you could help me. Have a nice day. Antoan Hristov From alan.gauld at yahoo.co.uk Tue Dec 19 07:06:13 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 19 Dec 2017 12:06:13 +0000 Subject: [Tutor] Problem python script In-Reply-To: References: Message-ID: On 19/12/17 09:47, Antoan Hristov wrote: > I am using a script which extracts data from internet every Monday, but > sometimes I have a problem that the script is not finishing properly. In > terminal I stop it with Ctrl-C and the message it gives me is: It is very hard to comment on code which you cannot see. Digging through the error messages might yield something but since they are triggered by your Ctrl-C rather than a code bug its not likely to be that helpful. -- 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 james at uplinkzero.com Tue Dec 19 07:57:11 2017 From: james at uplinkzero.com (James Chapman) Date: Tue, 19 Dec 2017 12:57:11 +0000 Subject: [Tutor] When do you know you're ready to start applying for jobs? In-Reply-To: References: Message-ID: Why has no one mentioned Github/Gitlab? Set up a free account on either or both platforms, and start committing your code. When applying for jobs potential employers will often want to see what you're capable of even before inviting you for an interview, and many will ask for a github page to see your work and whether you're contributing to open source projects. They'll also want to see if your code is unit tested as they'll want to employ programmers who are happy and able to write unit tests and that understand the value of unit tests. It also goes to show that you understand and know how to use source control effectively as this will be a requirement for any software development company. https://about.gitlab.com/ https://github.com/ ?Gitlab offers better features than github and it's arguable a better git source control platform than github, that said, github has somehow become the defacto standard for open source projects.? At the company where I work, we're also migrating to github enterprise. Demand for python programmers has grown over the years, reflected in the Tiobe index: https://www.tiobe.com/tiobe-index/ If you're able to write and understand what's happening on any of these projects (https://github.com/trending/python) then you're ready to start applying for jobs. Show off your skills via public git profiles and you should have something in no time, especially if you're not fussy! Programmers are in demand! Hope that helps and good luck. James From neilc at norwich.edu Tue Dec 19 09:11:43 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Tue, 19 Dec 2017 14:11:43 +0000 (UTC) Subject: [Tutor] Floating decimal question References: Message-ID: On 2017-12-18, Roger Lea Scherer wrote: > This is my first time in this "forum", please be patient I will do my best. > > As I was going through a book and came across this challenge, I did what I > believe was a success. And I know there are ways of making the decimal > place be limited to 2 places, but my question is more of understanding why > the following happened. > > This is the code I wrote in python: > > bill = float(input("What is the price of the bill?: ")) > tip15 = bill*1.15 > tip20 = bill*1.20 > > print("Bill plus 15% gratuity is " + str(tip15)) > print("Bill plus 20% gratuity is " + str(tip20)) > > This is the result I got after I ran the code in an IDE > (obviously) and then entered 29.99 in the first line: > > What is the price of the bill?: 29.99 > Bill plus 15% gratuity is 34.488499999999995 > Bill plus 20% gratuity is 35.988 > > My question is why does the 15% gratuity go so far beyond the > decimal place when really there should only be 4 places because > of multiplication rules, you know, and I do understand > sometimes things work behind the scenes that you don't see, but > on the 20% gratuity it gives the "right" answer? So I guess I'm > just asking why did this happen like this? Decimal notation cannot represent every rational number. For example, you cannot write 1/3 in a straight-forward way, since the digit 3 repreats infinitely. Alan has given you a link which gives a lot more detail, but the gist is that the floating point representation computers use has an analogous limitation. It feels surprising at first because some of the numbers it can't represent in a finite way do have finite representations in decimal notation. For your specific problem, you can use Python's format function, for example: >>> for i in range(1, 11): print('{:.4f}'.format(1 / i)) 1.0000 0.5000 0.3333 0.2500 0.2000 0.1667 0.1429 0.1250 0.1111 0.1000 -- Neil Cerutti From wrw at mac.com Tue Dec 19 16:09:43 2017 From: wrw at mac.com (William Ray Wing) Date: Tue, 19 Dec 2017 15:09:43 -0600 Subject: [Tutor] Problem python script In-Reply-To: References: Message-ID: Sent from my iPhone > On Dec 19, 2017, at 3:47 AM, Antoan Hristov wrote: > > Hello, > > I am using a script which extracts data from internet every Monday, but > sometimes I have a problem that the script is not finishing properly. In > terminal I stop it with Ctrl-C and the message it gives me is: > File "castorama.py", line 255, in main > p.map(get_all_data,magasins) > As Alan has said, knowing what is going on when the error was triggered by the ^C is difficult to impossible. What you may have to do is insert a fair number of ?progress? statements that are all directed to a log file. Then, even if you have to stop execution with a ^C, you can still see what was happening or where it was spinning its wheels. With that info at your finger tips, you can zoom in with finer resolution and even dump the state of all the relevant variables. Bill > Antoan Hristov > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor From vinrao21 at pds.org Tue Dec 19 19:22:50 2017 From: vinrao21 at pds.org (Vinay Rao) Date: Tue, 19 Dec 2017 19:22:50 -0500 Subject: [Tutor] Code Message-ID: Hi, We need help coding the range formula, and we don?t really know how to do it. This is the formula, R=(V2Sin2theangle)/(g). We are trying to solve for the angle. Thanks, Vinay From robertvstepp at gmail.com Tue Dec 19 22:15:37 2017 From: robertvstepp at gmail.com (boB Stepp) Date: Tue, 19 Dec 2017 21:15:37 -0600 Subject: [Tutor] Code In-Reply-To: References: Message-ID: Welcome to Tutor! We won't do your homework for you, but will help you if you get stuck. Normally you would show us your current best coding effort and we would help you from there. On Tue, Dec 19, 2017 at 6:22 PM, Vinay Rao wrote: > Hi, > > We need help coding the range formula, and we don?t really know how to do it. This is the formula, R=(V2Sin2theangle)/(g). We are trying to solve for the angle. To get you started, I might suggest the following outline of what to do: 1) Put your range formula in proper mathematical form. Assuming your email formatting did not get mangled, you have a little bit of cleanup effort to get the formula right. Example, V is squared not V2. 2) Use your knowledge of algebra and trigonometry to solve for the angle. 3) Express this solution in Python terms, using "*" for multiplication, "/" for division, etc. Use understandable variable names. You will probably want to use the math standard library. Attempt this and if you get into trouble copy and paste both your actual code you tried to run and any error tracebacks into a plain text email and we will endeavor to help you along. HTH! -- boB From steve at pearwood.info Wed Dec 20 10:12:38 2017 From: steve at pearwood.info (Steven D'Aprano) Date: Thu, 21 Dec 2017 02:12:38 +1100 Subject: [Tutor] Code In-Reply-To: References: Message-ID: <20171220151238.GF4215@ando.pearwood.info> On Tue, Dec 19, 2017 at 07:22:50PM -0500, Vinay Rao wrote: > Hi, > > We need help coding the range formula, and we don?t really know how to > do it. This is the formula, R=(V2Sin2theangle)/(g). We are trying to > solve for the angle. That's not a Python problem, that's a basic algebra problem. Write the formula in proper mathematical form, and then use algebra to solve for the angle. If you don't know how to solve the algebra problem, ask your maths teacher for help. -- Steve From cordsen.tim at googlemail.com Thu Dec 21 03:40:43 2017 From: cordsen.tim at googlemail.com (Tim Cordsen) Date: Thu, 21 Dec 2017 09:40:43 +0100 Subject: [Tutor] Problem in python online class Message-ID: Hello everybody, I am doing a python online class and I am lost. The "teacher" is a little chaotic and doesn't provide his code, so everyone must type on their own. Now the class reached a point where I am lost. It is about doing a simple web frontend with a form and saving the data of the form to mongodb. I have the form, but can't see the result in the console. Also there is nothing in mongodb after submitting. Is anybody willing to check my code and tell me where is my mistake? I am quite new to python, but not new to programming. I am mainframe-Cobol-programmer, so the basics of programming are known by me. Thank you in advance, Kind regards, Tim From alan.gauld at yahoo.co.uk Thu Dec 21 04:09:38 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 21 Dec 2017 09:09:38 +0000 Subject: [Tutor] Problem in python online class In-Reply-To: References: Message-ID: On 21/12/17 08:40, Tim Cordsen via Tutor wrote: > ...doesn't provide his code, so everyone must type on their own. Thats not necessarily a bad thing. You only really learn when you type in your own code. Its like muscle memory for the brain and fingers. > web frontend with a form and saving the data of the form to mongodb. I assume you mean a static HTML page containing a form and a simple submit button? There's no Python involved at this stage? Or are you creating the form from Python? > I have the form, but can't see the result in the console. Which console are you referring to? The web browser console? An OS console - in which case what are you running in it? Or is this a Python "console" as part of some kind of IDE? I wouldn't expect you to see the results of a web form submission in any consoles by default. So you must have done something to connect the web browser or server or mongo to a console, but I don't understand which? > Is anybody willing to check my code and tell me where is my mistake? Sure, but could you post both the HTML form as well as the Python code. And also tell us which web framework you are using? CGI, Flask, Pylons, Django, etc? And maybe which web server too? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From designx1000 at gmail.com Fri Dec 22 22:08:14 2017 From: designx1000 at gmail.com (Peter Hodges) Date: Fri, 22 Dec 2017 22:08:14 -0500 Subject: [Tutor] Installing python and numpy on the Mac (OSX) Message-ID: <5507B0E1-729B-4D70-AD18-7CAA724204FE@gmail.com> Hi. I downloaded Python 3.6 from the python site, then followed online directions for pip to install numpy (in users? ?user was in the example). When I start IDLE in the Python 3.6 in Applications and then type import numpy as np I get the following: import numpy as np Traceback (most recent call last): File "", line 1, in import numpy as np ModuleNotFoundError: No module named ?numpy' Does this mean I need to set the $PATH with some new pathname? Or move the numpy directory into the python 3.6 directory? Or? Thanks for any help, Peter From sjeik_appie at hotmail.com Sat Dec 23 04:57:15 2017 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Sat, 23 Dec 2017 09:57:15 +0000 Subject: [Tutor] Installing python and numpy on the Mac (OSX) Message-ID: Op 23 dec. 2017 09:47 schreef Peter Hodges : > > Hi. I downloaded Python 3.6 from the python site, then followed online directions for pip to install numpy (in users? ?user was in the example). > When I start IDLE in the Python 3.6 in Applications and then type import numpy as np I get the following: > import numpy as np > Traceback (most recent call last): > File "", line 1, in > import numpy as np > ModuleNotFoundError: No module named ?numpy' > > Does this mean I need to set the $PATH with some new pathname? > Or move the numpy directory into the python 3.6 directory? > Or? Hi, Perhaps you installed numpy for Python 2? What do you get when you type "python --version"? You could use virtualenv and use python 3 there (with -p), then pip install numpy in that virtualenv. Or, do (without sufficient rights): python3.6 $(which pip) install numpy Untested (I don't own a Mac) From sjeik_appie at hotmail.com Sat Dec 23 10:47:35 2017 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Sat, 23 Dec 2017 15:47:35 +0000 Subject: [Tutor] Problem in python online class Message-ID: On Dec 21, 2017 09:58, Tim Cordsen via Tutor wrote: > > Hello everybody, > I am doing a python online class and I am lost. The "teacher" is a little > chaotic and doesn't provide his code, so everyone must type on their own. > > Now the class reached a point where I am lost. It is about doing a simple > web frontend with a form and saving the data of the form to mongodb. > > I have the form, but can't see the result in the console. Also there is > nothing in mongodb after submitting. > > Is anybody willing to check my code and tell me where is my mistake? > > I am quite new to python, but not new to programming. I am > mainframe-Cobol-programmer, so the basics of programming are known by me. What framework are you using? Can you post the code of your web template, your view function, your form and your model? Have you tried using the pdb debugger (import pdb;pdb.set_trace())? From sjeik_appie at hotmail.com Sat Dec 23 05:11:35 2017 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Sat, 23 Dec 2017 10:11:35 +0000 Subject: [Tutor] Installing python and numpy on the Mac (OSX) Message-ID: Op 23 dec. 2017 09:47 schreef Peter Hodges : > > Hi. I downloaded Python 3.6 from the python site, then followed online directions for pip to install numpy (in users? ?user was in the example). > When I start IDLE in the Python 3.6 in Applications and then type import numpy as np I get the following: > import numpy as np > Traceback (most recent call last): > File "", line 1, in > import numpy as np > ModuleNotFoundError: No module named ?numpy' > > Does this mean I need to set the $PATH with some new pathname? > Or move the numpy directory into the python 3.6 directory? > Or? Or perhaps even easier: https://conda.io/docs/user-guide/install/download.html From anish198519851985 at gmail.com Sun Dec 24 03:12:15 2017 From: anish198519851985 at gmail.com (anish singh) Date: Sun, 24 Dec 2017 00:12:15 -0800 Subject: [Tutor] sort by value and then by key Message-ID: document = "Practice makes perfect. you'll only get Perfect by practice. just practice!" output: [ ["practice", "3"], ["perfect", "2"], ["by", "1"], ["get", "1"], ["just", "1"], ["makes", "1"], ["only", "1"], ["youll", "1"] ] I am supposed to return a list of all unique words in it and their number of occurrences, sorted by the number of occurrences in a descending order. If two or more words have the same count, they should be sorted alphabetically (in an ascending order). However, I am stuck. I have below code which is not working. ---------------------------------------------------------------------------------------- import collections x = collections.OrderedDict() import collections import operator def make_comparator(x, y): if x[1] > y[1]: return 1 elif x[1] < y[1]: return -1 elif x[1] == y[1]: if x > y: return 1 elif x < y: return -1 return 0 document = "Practice makes perfect. you'll only get Perfect by practice. just practice!" words = document.split() d = collections.defaultdict(int) for word in words: word = word.lower() word = [c if c >= 'a' and c <= 'z' else "" for c in word] word = "".join(word) d[word] += 1 output = [] for key, value in sorted(d, cmp = make_comparator(x)): output.append([key, value]) print(output) ---------------------------------------------------------------------------------------- Thanks, From btoddpuls at gmail.com Sat Dec 23 19:14:44 2017 From: btoddpuls at gmail.com (Bruce Todd Puls) Date: Sat, 23 Dec 2017 19:14:44 -0500 Subject: [Tutor] vol 166, issue 20, 1. installing python and numpy on the Mac (OSX) (Peter Hodges) Message-ID: sudo -H python3.6 -m pip install numpy From alan.gauld at yahoo.co.uk Sun Dec 24 03:48:50 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 24 Dec 2017 08:48:50 +0000 Subject: [Tutor] sort by value and then by key In-Reply-To: References: Message-ID: On 24/12/17 08:12, anish singh wrote: > However, I am stuck. I have below code which is not working. Define "not working" Do you get an error message? (show us) If the output different to what you expect (show us) Have you tried printing the intermediate results? For example the dictionary before you sort it? Or what about using the default sort, how close is that? Don't expect us to run your code and check the output. You've already done that so share the information. > ---------------------------------------------------------------------------------------- > > import collections > > x = collections.OrderedDict() > import collections > import operator > > > def make_comparator(x, y): > if x[1] > y[1]: > return 1 > elif x[1] < y[1]: > return -1 > elif x[1] == y[1]: > if x > y: > return 1 > elif x < y: > return -1 > return 0 > > > document = "Practice makes perfect. you'll only get Perfect by > practice. just practice!" > words = document.split() > d = collections.defaultdict(int) > for word in words: > word = word.lower() > word = [c if c >= 'a' and c <= 'z' else "" for c in word] > word = "".join(word) > d[word] += 1 > output = [] > for key, value in sorted(d, cmp = make_comparator(x)): > output.append([key, value]) > print(output) > ----------------------------------------------------------------- -- 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 marcus.luetolf at bluewin.ch Sun Dec 24 10:36:46 2017 From: marcus.luetolf at bluewin.ch (=?iso-8859-1?Q?marcus_l=FCtolf?=) Date: Sun, 24 Dec 2017 16:36:46 +0100 Subject: [Tutor] installation of Python 2.7 an 3.6, feedback Message-ID: <032901d37ccd$02293030$067b9090$@bluewin.ch> dear experts, while working through Alan C. Gould?s excellent update on? Learning to Program? I copied the file echoinput.py from the ?Conversing with the user? section: import sys inp = sys.stdin.readline() while inp.strip != '': print(inp) inp = sys.stdin.readline() in my IDLE 3.6 location and another copied a second file in one of my personal folders in my PC (W 10). If I open echoinput.py in IDLE 3.6 I get the script as written. If I open and edit it in my personal folder it opens in a Python 2.7 window although, I deleted Python 2.7 previously. Further on, if I add a print statement to echoinput.py it gets printed regardless of parenteses or none in the echoinput.py file in my personal folder. What causes this odd behavior ? Finally a may be too late comment on the update of ?Learning to Program : Personally I would appreciate a definition of an instance and in referring to Windows XP Home in the ?Coding Style? section (Note for Windows users) I thought W XP has expired. Marcus Luetolf --- Diese E-Mail wurde von Avast Antivirus-Software auf Viren gepr?ft. https://www.avast.com/antivirus From arj.python at gmail.com Sun Dec 24 11:42:17 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 24 Dec 2017 20:42:17 +0400 Subject: [Tutor] Installing python and numpy on the Mac (OSX) In-Reply-To: <5507B0E1-729B-4D70-AD18-7CAA724204FE@gmail.com> References: <5507B0E1-729B-4D70-AD18-7CAA724204FE@gmail.com> Message-ID: See Anaconda, a py dist packed with sci modules. Comes bundled with lots of goodies ! Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 23 Dec 2017 12:45, "Peter Hodges" wrote: > Hi. I downloaded Python 3.6 from the python site, then followed online > directions for pip to install numpy (in users? ?user was in the example). > When I start IDLE in the Python 3.6 in Applications and then type import > numpy as np I get the following: > import numpy as np > Traceback (most recent call last): > File "", line 1, in > import numpy as np > ModuleNotFoundError: No module named ?numpy' > > Does this mean I need to set the $PATH with some new pathname? > Or move the numpy directory into the python 3.6 directory? > Or? > > Thanks for any help, > Peter > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > From alan.gauld at yahoo.co.uk Sun Dec 24 17:34:08 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 24 Dec 2017 22:34:08 +0000 Subject: [Tutor] installation of Python 2.7 an 3.6, feedback In-Reply-To: <032901d37ccd$02293030$067b9090$@bluewin.ch> References: <032901d37ccd$02293030$067b9090$@bluewin.ch> Message-ID: On 24/12/17 15:36, marcus l?tolf wrote: > while working through Alan C. Gould?s excellent update on? Learning to > Program? I copied OK, First I need to point out that the tutorial content has not changed, it is still the old c2010-12 material. The update is to the structure and cosmetics to make it more mobile friendly. I'm hoping to launch the new site in January and then start a topic by topic update to v3.7 spec. > import sys > > inp = sys.stdin.readline() > while inp.strip != '': notice that should be strip()... with parens. > print(inp) > inp = sys.stdin.readline() > in my IDLE 3.6 location and another copied a second file in one of my > personal folders in my PC (W 10). > > If I open echoinput.py in IDLE 3.6 I get the script as written. > > If I open and edit it in my personal folder it opens in a Python 2.7 window > although, I deleted Python 2.7 previously. Presumably you have a second copy. some PC vendors use Python in their admin tools so it may have been installed when you got the PC. Maybe. > Further on, if I add a print statement to echoinput.py it gets printed > regardless of parenteses or none in the echoinput.py file in my personal folder. Certainly sounds like you are running v2.X > Finally a may be too late comment on the update of ?Learning to Program : > > Personally I would appreciate a definition of an instance Hmm, I thought I did, maybe in the Raw Materials topic, or maybe in the OOP topic. On the other hand instance is a standard English word used in its normal meaning (ie not with a Computer specific meaning) so maybe I didn't. Hmm, there is a very terse explanation in the OOP topic but I think I was relying on the English definition being sufficient. > and in referring to Windows XP Home in the ?Coding Style? section (Note for > Windows users) > > I thought W XP has expired. Indeed it has, at least so far as official support goes. There are still plenty of folks using it. But that is the kind of stuff that will be updated next year- hopefully along with the screen shots etc. Alan G. From anish198519851985 at gmail.com Sun Dec 24 22:46:07 2017 From: anish198519851985 at gmail.com (anish singh) Date: Sun, 24 Dec 2017 19:46:07 -0800 Subject: [Tutor] Tutor Digest, Vol 166, Issue 21 In-Reply-To: References: Message-ID: >> However, I am stuck. I have below code which is not working. I don't know how to achieve this programmatically: sorted by the number of occurrences in a descending order. If two or more words have the same count, they should be sorted alphabetically (in an ascending order). > > Define "not working" > Do you get an error message? (show us) I am not getting any error message but i don't know how to get the expected result. #getting: [('just', 4), ('practice', 3), ('perfect', 2), ('youll', 1), ('makes', 1), ('get', 1), ('by', 1)] #expected: [["just","4"],["practice","3"],["perfect","2"],["makes","1"],["youll","1"],["get","1"],["by","1"]] > If the output different to what you expect (show us) explained above. > > Have you tried printing the intermediate results? I did but I don't know how to get what i am looking for. > For example the dictionary before you sort it? > Or what about using the default sort, how close is that? > > Don't expect us to run your code and check the output. https://paste.pound-python.org/show/NappXV9daDMFz64yA805/ With the above code, i don't know what we can modify this to get expected result as below: #getting: [('just', 4), ('practice', 3), ('perfect', 2), ('youll', 1), ('makes', 1), ('get', 1), ('by', 1)] #expected: [["just","4"],["practice","3"],["perfect","2"],["makes","1"],["youll","1"],["get","1"],["by","1"]] From sehgaldarthsid at gmail.com Mon Dec 25 04:08:13 2017 From: sehgaldarthsid at gmail.com (Siddharth Sehgal) Date: Mon, 25 Dec 2017 13:08:13 +0400 Subject: [Tutor] Hi there, have a question for a side project in physics..... Message-ID: <95764E71-961D-4016-BABE-2455AF9FD751@gmail.com> Hi there I am a novice python user and am a physics masters student. I am trying to use the Sellmeier Equation to calculate a refractive index. The coefficients of this equation are decimals to a large number of sig figs ( i.e B1 = 1.03961212, B2 = 0.231792344, C1 = 6.00069867?10?3 ... and so on) in the sellmeier formula there is a lot of fractions, multiplication and squaring of these numbers. I originally state them as floats. However such a process apparently cannot be done with "floats" like these. What do i do? PLEASE NEED HELP! The actual equation is below screen shotted Many thanks, I look forward to your response, THIS IS NOT HOMEWORK BY THE WAY, I just want to use this program as it saves a lot of writing on paper. Siddharth Sehgal MSc Student in Physics SUNY - Stony Brook University From alan.gauld at yahoo.co.uk Mon Dec 25 04:37:26 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Mon, 25 Dec 2017 09:37:26 +0000 Subject: [Tutor] Tutor Digest, Vol 166, Issue 21 In-Reply-To: References: Message-ID: On 25/12/17 03:46, anish singh wrote: >>> However, I am stuck. I have below code which is not working. > > I don't know how to achieve this programmatically: sorted by the > number of occurrences in a descending order. If two or more words > have the same count, they should be sorted > alphabetically (in an ascending order). There is probably way to write a sort function that will do what I want but personally I'd divide and conquer by putting the results into two chunks. First I'd have a new dictionary keyed by the frequency. And the values in each frequency would be lists sorted alphabetically. So, for your data, it would look like: data = { 4:['just'], 3:['practice'], 2:['perfect'], 1:['by','get','makes','you\'ll'] } > #expected: [["just","4"],["practice","3"],["perfect","2"],["makes","1"],["youll","1"],["get","1"],["by","1"]] Really? I'd expect: [["just","4"],["practice","3"],["perfect","2"],["by","1"],["get","1"],["makes","1"],["you'll","1"]] as I did in the dict above. HTH Alan G. From alan.gauld at yahoo.co.uk Mon Dec 25 04:45:35 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Mon, 25 Dec 2017 09:45:35 +0000 Subject: [Tutor] Hi there, have a question for a side project in physics..... In-Reply-To: <95764E71-961D-4016-BABE-2455AF9FD751@gmail.com> References: <95764E71-961D-4016-BABE-2455AF9FD751@gmail.com> Message-ID: On 25/12/17 09:08, Siddharth Sehgal wrote: > ....physics masters student. I am trying to use the Sellmeier Equation > I originally state them as floats. However such a process apparently > cannot be done with "floats" like these. It can be done just with a large error (although as a physics grad you will know how to calculate the error I assume) > What do i do? PLEASE NEED HELP! There ae several ways and I guess the best will involve using SciPy/numpy features. But since i don't know those I'll suggest the old school way which is to multiply your numbers up until they become integers and take advantage of pythons big int feature. You will need to plug all the multipliers into your formula and work out the final multiplier - but that is just exponent arithmetic so should be doable. Finally adjust your answer by the calculated exponent. As I say there will probably be better solutions in the numpy space and hopefully someone else will tell you about them. > The actual equation is below screen shotted This list does not permit non-text attachments - the server throws them away. Alan G. From steve at pearwood.info Mon Dec 25 07:31:46 2017 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 25 Dec 2017 23:31:46 +1100 Subject: [Tutor] Hi there, have a question for a side project in physics..... In-Reply-To: <95764E71-961D-4016-BABE-2455AF9FD751@gmail.com> References: <95764E71-961D-4016-BABE-2455AF9FD751@gmail.com> Message-ID: <20171225123146.GM4215@ando.pearwood.info> On Mon, Dec 25, 2017 at 01:08:13PM +0400, Siddharth Sehgal wrote: > Hi there > > > I am a novice python user and am a physics masters student. I am > trying to use the Sellmeier Equation to calculate a refractive index. > The coefficients of this equation are decimals to a large number of > sig figs ( i.e B1 = 1.03961212, B2 = 0.231792344, C1 = 6.00069867?10?3 That's not really a lot of significant figures. Python floats are C 64-bit doubles, so they can represent about 15 or 16 significant figures. The numbers you show are only 9 or 10. > ... and so on) in the sellmeier formula there is a lot of fractions, > multiplication and squaring of these numbers. I originally state them > as floats. However such a process apparently cannot be done with > "floats" like these. What makes you think that you cannot use floats for this? Of course floating point maths on computers is not the same as real arithmetic of the Real numbers in mathematics class, and you may need to carefully consider the possible error conditions in your equations, round-off error, and so forth, but in general I would expect that simply using Python as a calculator will be fine for all but the most precise calculations. From steve at pearwood.info Mon Dec 25 07:52:22 2017 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 25 Dec 2017 23:52:22 +1100 Subject: [Tutor] Hi there, have a question for a side project in physics..... In-Reply-To: <95764E71-961D-4016-BABE-2455AF9FD751@gmail.com> References: <95764E71-961D-4016-BABE-2455AF9FD751@gmail.com> Message-ID: <20171225125222.GN4215@ando.pearwood.info> On Mon, Dec 25, 2017 at 01:08:13PM +0400, Siddharth Sehgal wrote: > The actual equation is below screen shotted No it isn't -- either you forgot to attach it, or the mailing list removed it. Do you mean this equation? https://en.wikipedia.org/wiki/Sellmeier_equation I suggest you try using Python and compare your results to those from here: http://www.calctool.org/CALC/phys/optics/sellmeier or from some authoritative source of refractive indexes. Here is my simple test, for borosilicate glass BK7 using the values from Wikipedia. Using the website: refractive index at 590 nm = 1.51670 Using Python, I get: 1.516698697993053 Here is my code. Feel free to use it for any purpose, no credit required (except as needed to meet any academic obligations you may have about collaboration and/or plagiarism). import math def sellmeier(lambd, B1, B2, B3, C1, C2, C3): return 1 + B1*f(lambd, C1) + B2*f(lambd, C2) + B3*f(lambd, C3) def f(x, y): x2 = x**2 return x2/(x2 - y) # Coefficients for BK7 (borosilicate crown glass) result = sellmeier(0.590, # 590nm == 0.590?m 1.03961212, 0.231792344, 1.01046945, 6.00069867e-3, 2.00179144e-2, 103.560653) print(math.sqrt(result)) -- Steve From steve at pearwood.info Mon Dec 25 07:58:15 2017 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 25 Dec 2017 23:58:15 +1100 Subject: [Tutor] Hi there, have a question for a side project in physics..... In-Reply-To: References: <95764E71-961D-4016-BABE-2455AF9FD751@gmail.com> Message-ID: <20171225125814.GO4215@ando.pearwood.info> On Mon, Dec 25, 2017 at 09:45:35AM +0000, Alan Gauld via Tutor wrote: > On 25/12/17 09:08, Siddharth Sehgal wrote: > > >....physics masters student. I am trying to use the Sellmeier Equation > > >I originally state them as floats. However such a process apparently > > >cannot be done with "floats" like these. > > It can be done just with a large error (although as a physics > grad you will know how to calculate the error I assume) I don't think the numbers or equation is so ill-conditioned that the error will be "large", or at least not larger than the experimental uncertainty in the coefficients. Floating point maths is tricky, but it isn't *that* tricky. Especially not for "reasonable" sized numbers, with only nine or ten significant figures. This is the huge advantage of IEEE-754 maths using 64-bit floats, as Python does: most of the time, the obvious formula "just works". -- Steve From tkadm30 at yandex.com Wed Dec 27 18:01:06 2017 From: tkadm30 at yandex.com (Etienne Robillard) Date: Wed, 27 Dec 2017 18:01:06 -0500 Subject: [Tutor] How to create a python extension module from a shared library? Message-ID: <53025d84-eaf1-aa4e-6756-6e87d39fb2dd@yandex.com> Hi all, I want to build a CPython extension module for the libuwsgi.so shared library included in uWSGI. My objective is to allow unconditional access to this shared library using the standard Python interpreter, for introspection purpose and extending uWSGI. I have investigated several ways to do this: 1. ctypes Probably the most straightforward to load the shared library >>> from ctypes import CDLL >>> lib = CDLL('./libuwsgi.so') However, this method does not properly reflect C functions and variables to their respective Python attributes... 2. CFFI/pycparser Next I tried to parse the uwsgi.h file with CFFI and pycparser: >>> from cffi import FFI >>> ffi = FFI() >>> lib = ffi.cdef(open('./uwsgi.h').read()) However, since directives are not supported in CFFI, it's not possible to parse the header file. 3. CFFI/clang For this experiment, I wanted to parse the C header file to generate a Abstract Syntax Tree (AST) using clang: >>> from pycparser import parse_file >>> ast = parse_file('./uwsgi.h', use_cpp=True, cpp_path='clang') >>> ast.show() FileAST: (at None) Ideally, it would be really cool if CFFI could parse a C header and generate a AST with libclang. Another possibility I haven't explored yet is to use cppyy. So, could you please advise on the most robust approach to reflect a shared library into a Python extension module? Regards, Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From __peter__ at web.de Thu Dec 28 15:51:31 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 Dec 2017 21:51:31 +0100 Subject: [Tutor] Tutor Digest, Vol 166, Issue 21 References: Message-ID: anish singh wrote: >>> However, I am stuck. I have below code which is not working. > > I don't know how to achieve this programmatically: sorted by the > number of occurrences in a descending order. If two or more words > have the same count, they should be sorted > alphabetically (in an ascending order). >>> document = "Practice makes perfect, you'll get perfecT by practice. just practice! just just just!!" >>> words = ("".join(c for c in word if "a" <= c <= "z") for word in document.lower().split()) >>> freq = collections.Counter(words) >>> freq Counter({'just': 4, 'practice': 3, 'perfect': 2, 'by': 1, 'get': 1, 'makes': 1, 'youll': 1}) Given that Counter or a similar dict you can first sort by word and then by word frequency: >>> pairs = sorted(freq.items()) # sort alphabetically >>> pairs.sort(key=lambda pair: pair[1], reverse=True) # sort by frequency >>> pairs [('just', 4), ('practice', 3), ('perfect', 2), ('by', 1), ('get', 1), ('makes', 1), ('youll', 1)] This works because Python's sorting algorithm is "stable", i. e. values with the same key stay in the same relative order as before the sorting. While you can also achieve that with a single sorted() call >>> sorted(freq.items(), key=lambda p: (-p[1], p[0])) [('just', 4), ('practice', 3), ('perfect', 2), ('by', 1), ('get', 1), ('makes', 1), ('youll', 1)] the first method is usually clearer. PS: Both approaches also work with comparison functions, e. g. >>> def cmp_freqs((w1, f1), (w2, f2)): ... return -cmp(f1, f2) or cmp(w1, w2) ... >>> sorted(freqs.iteritems(), cmp_freqs) [('just', 4), ('practice', 3), ('perfect', 2), ('by', 1), ('get', 1), ('makes', 1), ('youll', 1)] but this is (1) usually less efficient (2) limited to Python 2 so I can't recommend the cmp-based solution. From jpkelman at gmail.com Fri Dec 29 11:43:42 2017 From: jpkelman at gmail.com (Jay Kelman) Date: Fri, 29 Dec 2017 10:43:42 -0600 Subject: [Tutor] IDLE Message-ID: I?m a beginner. I downloaded Python and when I look at IDLE it tells me to update TCL. I downloaded updated Active TCL and installed it but can?t figure how to use update to get IDLE corrected. Any help? From alan.gauld at yahoo.co.uk Fri Dec 29 13:28:34 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 29 Dec 2017 18:28:34 +0000 Subject: [Tutor] IDLE In-Reply-To: References: Message-ID: On 29/12/17 16:43, Jay Kelman wrote: > I downloaded Python and when I look at IDLE it tells me to update TCL. Are you using a Mac by any chance? I seem to recall this used to be a common issue with MacOS. If you google for "IDLE MacOS Tcl" you should find several links telling you how to fix it. If not a Mac then I'm stumped it should all work fine. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From mats at wichmann.us Fri Dec 29 15:53:57 2017 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 29 Dec 2017 13:53:57 -0700 Subject: [Tutor] IDLE In-Reply-To: References: Message-ID: <35910c99-be04-173e-e9d3-e06a0f5c646b@wichmann.us> On 12/29/2017 11:28 AM, Alan Gauld via Tutor wrote: > On 29/12/17 16:43, Jay Kelman wrote: >> I downloaded Python and when I look at IDLE it tells me to update TCL. > > Are you using a Mac by any chance? I seem to recall this used to > be a common issue with MacOS. If you google for "IDLE MacOS > Tcl" you should find several links telling you how to fix it. > > If not a Mac then I'm stumped it should all work fine. > This Mac issue is definitely still current - yes there is information to solve it, but people are having constant problems getting it to not complain, we get an orgoing stream of these over at the python.org webmaster alias, which isn't even supposed to be for Python problems. It seems what is on the web about this isn't simple enough, complete enough, or whatever. Just a note: it's not certain that you will ever hit the problems, and if you do, you certainly don't have to use IDLE to be happy and productive with Python. IDLE != Python. There are many many other editors/development environments that can be used. A bunch are listed on the Python wiki: https://wiki.python.org/moin/IntegratedDevelopmentEnvironments https://wiki.python.org/moin/PythonEditors From Sunnlotus at aol.com Fri Dec 29 16:20:20 2017 From: Sunnlotus at aol.com (Rex) Date: Fri, 29 Dec 2017 16:20:20 -0500 Subject: [Tutor] IDLE In-Reply-To: <35910c99-be04-173e-e9d3-e06a0f5c646b@wichmann.us> References: <35910c99-be04-173e-e9d3-e06a0f5c646b@wichmann.us> Message-ID: <7BD0E73E-B63D-47F7-9034-43902523668C@aol.com> I am a beginner and am using PyCharm as my editor. It?s great and free. It also provides some very nice courses that work within the editor. Google PyCharm.edu Sent from my iPhone > On Dec 29, 2017, at 3:53 PM, Mats Wichmann wrote: > >> On 12/29/2017 11:28 AM, Alan Gauld via Tutor wrote: >>> On 29/12/17 16:43, Jay Kelman wrote: >>> I downloaded Python and when I look at IDLE it tells me to update TCL. >> >> Are you using a Mac by any chance? I seem to recall this used to >> be a common issue with MacOS. If you google for "IDLE MacOS >> Tcl" you should find several links telling you how to fix it. >> >> If not a Mac then I'm stumped it should all work fine. >> > > This Mac issue is definitely still current - yes there is information to > solve it, but people are having constant problems getting it to not > complain, we get an orgoing stream of these over at the python.org > webmaster alias, which isn't even supposed to be for Python problems. It > seems what is on the web about this isn't simple enough, complete > enough, or whatever. > > > Just a note: it's not certain that you will ever hit the problems, and > if you do, you certainly don't have to use IDLE to be happy and > productive with Python. IDLE != Python. There are many many other > editors/development environments that can be used. A bunch are listed > on the Python wiki: > > https://wiki.python.org/moin/IntegratedDevelopmentEnvironments > https://wiki.python.org/moin/PythonEditors > > > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor From nelsonjonkane6 at live.com Fri Dec 29 17:21:01 2017 From: nelsonjonkane6 at live.com (nelson jon kane) Date: Fri, 29 Dec 2017 22:21:01 +0000 Subject: [Tutor] IDLE In-Reply-To: <35910c99-be04-173e-e9d3-e06a0f5c646b@wichmann.us> References: , <35910c99-be04-173e-e9d3-e06a0f5c646b@wichmann.us> Message-ID: I spent a lot of time watching 18 different Python tutorials made by "The Bad Tutorials." I realized finally that they were not for me, because in my opinion, the speaker on the videos skips steps. Also, he had his own personal name "put in" to his Python, but on my version, it just says the words "User Name," and "User Name" can't be changed on my version. So, I'm looking for a new series of videos. I'm going to have to start at the very beginning all over again. Without recommending your own company or product ? who has a free series of YouTube videos on Python in which the speaker does NOT leave out steps in the video? Thanks! ________________________________ From: Tutor on behalf of Mats Wichmann Sent: Friday, December 29, 2017 3:53 PM To: tutor at python.org Subject: Re: [Tutor] IDLE On 12/29/2017 11:28 AM, Alan Gauld via Tutor wrote: > On 29/12/17 16:43, Jay Kelman wrote: >> I downloaded Python and when I look at IDLE it tells me to update TCL. > > Are you using a Mac by any chance? I seem to recall this used to > be a common issue with MacOS. If you google for "IDLE MacOS > Tcl" you should find several links telling you how to fix it. > > If not a Mac then I'm stumped it should all work fine. > This Mac issue is definitely still current - yes there is information to solve it, but people are having constant problems getting it to not complain, we get an orgoing stream of these over at the python.org webmaster alias, which isn't even supposed to be for Python problems. It seems what is on the web about this isn't simple enough, complete enough, or whatever. Just a note: it's not certain that you will ever hit the problems, and if you do, you certainly don't have to use IDLE to be happy and productive with Python. IDLE != Python. There are many many other editors/development environments that can be used. A bunch are listed on the Python wiki: https://wiki.python.org/moin/IntegratedDevelopmentEnvironments https://wiki.python.org/moin/PythonEditors _______________________________________________ Tutor maillist - Tutor at python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor Tutor Info Page - Python mail.python.org Your email address: Your name (optional): You may enter a privacy password below. This provides only mild security, but should prevent others from messing with ... From alan.gauld at yahoo.co.uk Sat Dec 30 04:07:10 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sat, 30 Dec 2017 09:07:10 +0000 Subject: [Tutor] IDLE In-Reply-To: References: <35910c99-be04-173e-e9d3-e06a0f5c646b@wichmann.us> Message-ID: On 29/12/17 22:21, nelson jon kane wrote: > ..., he had his own personal name "put in" to his Python, I have no idea what you mean by that. Python is an interpreter that executes your code. It doesn't have a "User Name" in it. In interactive mode it displays a prompt which is usually >>> although you could change that if you really wanted to. But it doesn't say "User Name" anywhere. I therefore assume you are talking about some kind of development tool rather than Python itself. Where did you get your "Python"? What OS are you using? What does it say in the window title bar? Or maybe you can send a link to the videos so we can see this tool? > So, I'm looking for a new series of videos. Videos are good for getting a feel for things and understanding concepts but IMHO they are not good for details. You don't have time to follow along by typing in each line - and if you keep pausing the video you lose continuity. And you need to type the code to learn a programming language. So I'd recommend using one of the many online web tutorials supplemented by videos. -- 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 leamhall at gmail.com Sat Dec 30 06:39:48 2017 From: leamhall at gmail.com (Leam Hall) Date: Sat, 30 Dec 2017 06:39:48 -0500 Subject: [Tutor] IDLE In-Reply-To: References: <35910c99-be04-173e-e9d3-e06a0f5c646b@wichmann.us> Message-ID: On 12/30/2017 04:07 AM, Alan Gauld via Tutor wrote: > Videos are good for getting a feel for things and > understanding concepts but IMHO they are not good > for details. This is how I learn coding languages. Watch a video series for a little bit and then find a written tutorial to work through. Getting the "big picture" quickly helps provide a context and then digging deeply into the actual code really helps learning. And yeah, I'll plug Alan's tutorial. I can't think of any reason not to use it. Leam From random832 at fastmail.com Sat Dec 30 13:13:46 2017 From: random832 at fastmail.com (Random832) Date: Sat, 30 Dec 2017 13:13:46 -0500 Subject: [Tutor] IDLE In-Reply-To: References: <35910c99-be04-173e-e9d3-e06a0f5c646b@wichmann.us> Message-ID: <1514657626.2205210.1219724072.3657D4C0@webmail.messagingengine.com> On Sat, Dec 30, 2017, at 04:07, Alan Gauld via Tutor wrote: > On 29/12/17 22:21, nelson jon kane wrote: > > > ..., he had his own personal name "put in" to his Python, > > I have no idea what you mean by that. > Python is an interpreter that executes your code. > It doesn't have a "User Name" in it. > In interactive mode it displays a prompt which > is usually >>> although you could change that > if you really wanted to. But it doesn't say > "User Name" anywhere. > > I therefore assume you are talking about some > kind of development tool rather than Python itself. I skimmed through the first couple videos, the only place I saw the creator's name was that his home directory was "C:\Users\(name)", which showed up in the filenames in the title bar and the windows command prompt. But that has nothing to do with Python really, it's just how his Windows is set up. From nelsonjonkane6 at live.com Sat Dec 30 10:53:54 2017 From: nelsonjonkane6 at live.com (nelson jon kane) Date: Sat, 30 Dec 2017 15:53:54 +0000 Subject: [Tutor] Fw: IDLE In-Reply-To: References: <35910c99-be04-173e-e9d3-e06a0f5c646b@wichmann.us> , Message-ID: Thanks. What do you mean when you say "find a written tutorial"? ________________________________ From: Tutor on behalf of Leam Hall Sent: Saturday, December 30, 2017 6:39 AM To: tutor at python.org Subject: Re: [Tutor] IDLE On 12/30/2017 04:07 AM, Alan Gauld via Tutor wrote: > Videos are good for getting a feel for things and > understanding concepts but IMHO they are not good > for details. This is how I learn coding languages. Watch a video series for a little bit and then find a written tutorial to work through. Getting the "big picture" quickly helps provide a context and then digging deeply into the actual code really helps learning. And yeah, I'll plug Alan's tutorial. I can't think of any reason not to use it. Leam _______________________________________________ Tutor maillist - Tutor at python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor Tutor Info Page - Python mail.python.org Your email address: Your name (optional): You may enter a privacy password below. This provides only mild security, but should prevent others from messing with ... From robertvstepp at gmail.com Sun Dec 31 19:15:59 2017 From: robertvstepp at gmail.com (boB Stepp) Date: Sun, 31 Dec 2017 18:15:59 -0600 Subject: [Tutor] Finding written and video tutorials for Python [Was: IDLE] Message-ID: I am renaming this thread as it has drifted off its original subject. On Sat, Dec 30, 2017 at 9:53 AM, nelson jon kane wrote: > Thanks. What do you mean when you say "find a written tutorial"? > > > ________________________________ > From: Tutor on behalf of Leam Hall > Sent: Saturday, December 30, 2017 6:39 AM > To: tutor at python.org > Subject: Re: [Tutor] IDLE > > On 12/30/2017 04:07 AM, Alan Gauld via Tutor wrote: > >> Videos are good for getting a feel for things and >> understanding concepts but IMHO they are not good >> for details. > > This is how I learn coding languages. Watch a video series for a little > bit and then find a written tutorial to work through. Getting the "big > picture" quickly helps provide a context and then digging deeply into > the actual code really helps learning. What Alan and Leam are suggesting is to use a written, non-video tutorial as your main learning tool. If you truly wish to learn to program you must write code, run it, inevitably get errors, correct the errors, get more errors, correct those, etc., until you get a finished program that does what you desire. The struggle in doing this is where the real learning occurs. It is helpful starting out to have a resource that presents the information in a logical, organized way optimized for your learning. Whatever resource you use will illustrate a topic with actual code. You should type that code in yourself and try to run it. If it works you should play around with it yourself until you are certain you fully understand that code snippet and what each piece of it does. If it doesn't run then you should debug it until it does run and then play around with it for full understanding. This interactive process of reading/watching someone else's code and then trying it out yourself is more difficult to accomplish with a video. But with a book, a written webpage, etc., it is easy to do. Alan has a web resource: http://www.alan-g.me.uk/ that you could use as a written tutorial. Use version 3 for Python 3 as that is what is current. Other resources for people without previous programming experience are given on Python's official website at: https://wiki.python.org/moin/BeginnersGuide/NonProgrammers And of course you can search for others. Do whatever you find works best for how you learn, but whatever you do, make sure you write and debug code. This is where the real learning occurs. -- boB From alan.gauld at yahoo.co.uk Sun Dec 31 20:01:52 2017 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Mon, 1 Jan 2018 01:01:52 +0000 Subject: [Tutor] Fw: IDLE In-Reply-To: References: <35910c99-be04-173e-e9d3-e06a0f5c646b@wichmann.us> Message-ID: On 30/12/17 15:53, nelson jon kane wrote: > Thanks. What do you mean when you say "find a written tutorial"? One that is written as opposed to a video. In other words a web site or book. -- 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 robertvstepp at gmail.com Sun Dec 31 21:53:49 2017 From: robertvstepp at gmail.com (boB Stepp) Date: Sun, 31 Dec 2017 20:53:49 -0600 Subject: [Tutor] Is len(a_list) a computed value or a stored attribute of a_list? Message-ID: I was wondering if len(a_list) is computed on the fly or is it a stored attribute of the a_list object? And is the answer the same for both Python 2 and 3? -- boB From steve at pearwood.info Sun Dec 31 22:36:19 2017 From: steve at pearwood.info (Steven D'Aprano) Date: Mon, 1 Jan 2018 14:36:19 +1100 Subject: [Tutor] Is len(a_list) a computed value or a stored attribute of a_list? In-Reply-To: References: Message-ID: <20180101033619.GX4215@ando.pearwood.info> On Sun, Dec 31, 2017 at 08:53:49PM -0600, boB Stepp wrote: > I was wondering if len(a_list) is computed on the fly or is it a > stored attribute of the a_list object? And is the answer the same for > both Python 2 and 3? Technically the Python language doesn't make any guarantees about this, but in practice it is a stored attribute of the list (as well as other built-ins like tuples, strings, dicts and sets). The answer is the same for both Python 2 and 3, and all the major Python implementations (CPython, IronPython, Jython, PyPy). But technically I guess it counts as a "quality of implementation" marker: crappy Python interpreters might count the items in a list on the fly, good ones will store it as a pre-computed attribute. In practice, it is probably fine to assume that calling len() on built-ins is fast, but for third-party sequences and collections it might not be. -- Steve