Re: [Tutor] Any 'graphical' ways of learning Python
Hi Mike and everyone who replied to the tutor question re: GUI ideas for Python. Really value all the ideas and suggestions...that is very helpful! Thanks for taking time to reply with so much great information. We're just in wind down mode/rush for our close of school year ...but will really enjoy looking through all the various links and ideas as I prepare the coding course for 2019. Will use them, to upskill myself too. Thanks so much! - Matthew Polack On Fri, Dec 7, 2018 at 6:05 AM Mike Barnett wrote: > Oh, one more thing on this topic... there are tutorial videos available > for PySimpleGUI, both basic and advanced. > > Basic 5 video series: > https://www.youtube.com/playlist?list=PLl8dD0doyrvHMoJGTdMtgLuHymaqJVjzt > > Additional 9 in-depth videos: > https://www.youtube.com/playlist?list=PLl8dD0doyrvHMoJGTdMtgLuHymaqJVjzt > > > -mike > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- **Disclaimer: *Whilst every attempt has been made to ensure that material contained in this email is free from computer viruses or other defects, the attached files are provided, and may only be used, on the basis that the user assumes all responsibility for use of the material transmitted. This email is intended only for the use of the individual or entity named above and may contain information that is confidential and privileged. If you are not the intended recipient, please note that any dissemination, distribution or copying of this email is strictly prohibited. If you have received this email in error, please notify us immediately by return email or telephone +61 3 5382 2529** and destroy the original message.* ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Increase performance of the script
Hi All, I used your solution , however found a strange issue with deque : I am using python 2.6.6: >>> import collections >>> d = collections.deque('abcdefg') >>> print 'Deque:', d File "", line 1 print 'Deque:', d ^ SyntaxError: invalid syntax >>> print ('Deque:', d) Deque: deque(['a', 'b', 'c', 'd', 'e', 'f', 'g']) >>> print d File "", line 1 print d ^ SyntaxError: invalid syntax >>> print (d) deque(['a', 'b', 'c', 'd', 'e', 'f', 'g']) In python 2.6 print statement work as print "Solution" however after import collection I have to use print with print("Solution") is this a known issue ? Please let me know . Thanks, On Mon, Dec 10, 2018 at 10:30 PM wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > Today's Topics: > >1. Re: Increase performance of the script (Peter Otten) >2. Re: Increase performance of the script (Steven D'Aprano) >3. Re: Increase performance of the script (Steven D'Aprano) > > > > -- Forwarded message -- > From: Peter Otten <__pete...@web.de> > To: tutor@python.org > Cc: > Bcc: > Date: Sun, 09 Dec 2018 21:17:53 +0100 > Subject: Re: [Tutor] Increase performance of the script > Asad wrote: > > > Hi All , > > > > I have the following code to search for an error and prin the > > solution . > > > > /A/B/file1.log size may vary from 5MB -5 GB > > > > f4 = open (r" /A/B/file1.log ", 'r' ) > > string2=f4.readlines() > > Do not read the complete file into memory. Read one line at a time and > keep > only those lines around that you may have to look at again. > > > for i in range(len(string2)): > > position=i > > lastposition =position+1 > > while True: > > if re.search('Calling rdbms/admin',string2[lastposition]): > > break > > elif lastposition==len(string2)-1: > > break > > else: > > lastposition += 1 > > You are trying to find a group of lines. The way you do it for a file of > the > structure > > foo > bar > baz > end-of-group-1 > ham > spam > end-of-group-2 > > you find the groups > > foo > bar > baz > end-of-group-1 > > bar > baz > end-of-group-1 > > baz > end-of-group-1 > > ham > spam > end-of-group-2 > > spam > end-of-group-2 > > That looks like a lot of redundancy which you can probably avoid. But > wait... > > > > errorcheck=string2[position:lastposition] > > for i in range ( len ( errorcheck ) ): > > if re.search ( r'"error(.)*13?"', errorcheck[i] ): > > print "Reason of error \n", errorcheck[i] > > print "script \n" , string2[position] > > print "block of code \n" > > print errorcheck[i-3] > > print errorcheck[i-2] > > print errorcheck[i-1] > > print errorcheck[i] > > print "Solution :\n" > > print "Verify the list of objects belonging to Database " > > break > > else: > > continue > > break > > you throw away almost all the hard work to look for the line containing > those four lines? It looks like you only need the > "error...13" lines, the three lines that precede it and the last > "Calling..." line occuring before the "error...13". > > > The problem I am facing in performance issue it takes some minutes to > > print out the solution . Please advice if there can be performance > > enhancements to this script . > > If you want to learn the Python way you should try hard to write your > scripts without a single > > for i in range(...): > ... > > loop. This style is usually the last resort, it may work for small > datasets, > but as soon as you have to deal with large files performance dives. > Even worse, these loops tend to make your code hard to debug. > > Below is a suggestion for an implementation of what your code seems to be > doing that only remembers the four recent lines and works with a single > loop. If that saves you some time use that time to clean the scripts you > have lying around from occurences of "for i in range(): ..." ;) > > > from __future__ import print_function > > import re > import sys > from collections import deque > > > def show(prompt, *values): > print(prompt) > for value in values: > print(" {}".format(value.rstrip("\n"))) > > > def process(filename): > tail = deque(maxlen=4) # the last four lines > script = None > with open(filename) as instream: > for line in instream: > tail.append(line) > if "Calling rdbms/admin" in line: >
[Tutor] print statement vs print() function, was Re: Increase performance of the script
Asad wrote: > Hi All, > > I used your solution , however found a strange issue with deque > : > > I am using python 2.6.6: Consider switching to Python 3; my code as posted already works with that. import collections d = collections.deque('abcdefg') print 'Deque:', d > File "", line 1 > print 'Deque:', d > ^ > SyntaxError: invalid syntax This is the effect of a from __future__ import print_function import. Once that is used print becomes a function and has to be invoked as such. If you don't want this remove the "from __future__ print_function" statement and remove the parentheses from all print-s (or at least those with multiple arguments). Note that in default Python 2 print("foo", "bar") works both with and without and parens, but the parens constitute a tuple. So >>> print "foo", "bar" # print statement with two args foo bar >>> print ("foo", "bar") # print statement with a single tuple arg ('foo', 'bar') >>> from __future__ import print_function >>> print "foo", "bar" # illegal, print() is now a function File "", line 1 print "foo", "bar" ^ SyntaxError: invalid syntax >>> print("foo", "bar") # invoke print() function with two args foo bar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Increase performance of the script
On Tue, Dec 11, 2018 at 09:07:58PM +0530, Asad wrote: > Hi All, > > I used your solution , however found a strange issue with deque : No you haven't. You found a *syntax error*, as the exception says: > >>> print 'Deque:', d > File "", line 1 > print 'Deque:', d > ^ > SyntaxError: invalid syntax which means the error occurs before the interpreter runs the code. You could replace the above line with any similar line: print 'Not a deque', 1.2345 and you will get the same error. When you are faced with an error in the interactive interpreter, you should try different things to see how they effect the problem. Does the problem go away if you use a float instead of a deque? If you change the string, does the problem go away? If you swap the order, does the problem go away? What if you use a single value instead of two? This is called "debugging", and as a programmer, you need to learn how to do this. [...] > In python 2.6 print statement work as print "Solution" > however after import collection I have to use print with print("Solution") > is this a known issue ? As Peter says, you must have run from __future__ import print_function to see this behaviour. This has nothing to do with import collection. You can debug that for yourself by exiting the interactive interpreter, starting it up again, and trying to print before and after importing collection. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor