Re: [Tutor] Psyco module
It only runs on Intel 386-compatible processors. Once we know what CPU you are using then we can figure it out better. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sorting a dictionary on a value in a list.
On Dec 6, 2008, at 12:41 AM, Lie Ryan wrote: In most cases, in processing involving networking, the bottleneck is the network speed itself. To speed things up by optimizing your own code might not make your download significantly faster (getting 60 seconds faster is great for scripts that usually runs for 70 seconds, but is a waste of development time for scripts that usually run for 1 hour) Usually a multi-threading downloader might be a better chance to improvement, especially for 1) downloading from different site, 2) the remote sites have speed limit, 3) you have faster download link than the server can gives In this particular case everything is on the local network. This is actually part of a hadoop map/reduce system I am learning, so reducing cpu is of high value. if network pull times become and issue the cluster can be expanded and the time between pulls can be reduced. As of this morning I am being directed to make the reducer usable both in the mapper and then again as a reducer. This has forced me to rework everything to work so that it can be called as a module. I have never learned java so that wasn't' an option and the more I am working with it python seems to be the perfect fit for hadoop type work. Really fun stuff. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] File IO flush
Hello All, I was playing around with the zipfile module and wrote a simple script to unzip a zip file. I then looked around on the internet and found the recipe 252508 [1] on the active state cookbook website. In this recipe the author calls flush() and then close() on a file object being written to disk. Now I understand what flush does but would close() also flush the buffers to disk? Thanks Sander [1] http://code.activestate.com/recipes/252508/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] File IO flush
On Mon, Dec 8, 2008 at 12:15 PM, Sander Sweers [EMAIL PROTECTED] wrote: Hello All, I was playing around with the zipfile module and wrote a simple script to unzip a zip file. I then looked around on the internet and found the recipe 252508 [1] on the active state cookbook website. In this recipe the author calls flush() and then close() on a file object being written to disk. Now I understand what flush does but would close() also flush the buffers to disk? Yes, close() will flush first; AFAIK there is no reason to call flush() immediately before close() on the same file object. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] rrdtool examples.
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jeremiah Jester wrote: Is anyone on here using the python-rrdtool module for graphing and analysis? If so, do you have some sample scripts you could show me. There doesn't seem to be a lot out there as far as real world python examples. Thanks, JJ Actually, I was just playing around with the rrdtool library for python last week. It turns out that you basically just use the command line options as options for the different method calls (like create()). All you really have to do is check out the man pages for rrdtool to have all the documentation you need for the rrdtool python module. You literally pass in the command line opts just as they would appear on the command line. Here is a quick little script that I whipped up for playing purposes: - #!/usr/bin/env python import rrdtool , time , random stime = int(time.time()) - 5 * 86400 dpoints = 1000 etime = stime + (dpoints * 300) fname = 'test.rrd' gfname = 'test.png' rrdtool.create('test.rrd' , '--start' , str(stime) , 'DS:speed:COUNTER:600:U:U' , 'RRA:AVERAGE:0.5:1:576' , 'RRA:AVERAGE:0.5:6:336' ) ctime = stime cmiles = 0 for i in xrange(dpoints): bump = random.randint(1 , 20) cmiles += bump ctime += 300 rrdtool.update(fname , '%d:%d' % (ctime , cmiles)) rrdtool.graph(gfname , '--start' , str(etime - (24 * 3600)) , '--end' , str(etime) , '--vertical-label' , 'Speed m/h' , '--imgformat' , 'PNG' , '--title' , 'Speeds' , '--lower-limit' , '0' , 'DEF:myspeed=%s:speed:AVERAGE' % fname , 'CDEF:mph=myspeed,3600,*' , 'VDEF:msmax=mph,MAXIMUM' , 'VDEF:msavg=mph,AVERAGE' , 'VDEF:msmin=mph,MINIMUM' , 'VDEF:mspct=mph,95,PERCENT' , 'LINE1:mph#FF:My Speed' , r'GPRINT:msmax:Max\: %6.1lf mph' , r'GPRINT:msavg:Avg\: %6.1lf mph' , r'GPRINT:msmin:Min\: %6.1lf mph\l' , r'GPRINT:mspct:95th Perc\: %6.1lf mph\l' ) - That, coupled with the rrdtool man pages (which are very good, complete with examples) should be enough to get you started. - -- Jay Deiman \033:wq! -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkk9YNwACgkQQ0lr+ZVKSBiWTQCgoBuzQVeRHBlrJ7GONQAL0RFT qOwAn3cnbZot0q1qGf6mOFHS8QgQc53o =h7CZ -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] rrdtool examples.
Thanks Jay. This helps! JJ On Mon, 2008-12-08 at 10:01 -0800, Jay Deiman wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jeremiah Jester wrote: Is anyone on here using the python-rrdtool module for graphing and analysis? If so, do you have some sample scripts you could show me. There doesn't seem to be a lot out there as far as real world python examples. Thanks, JJ Actually, I was just playing around with the rrdtool library for python last week. It turns out that you basically just use the command line options as options for the different method calls (like create()). All you really have to do is check out the man pages for rrdtool to have all the documentation you need for the rrdtool python module. You literally pass in the command line opts just as they would appear on the command line. Here is a quick little script that I whipped up for playing purposes: - #!/usr/bin/env python import rrdtool , time , random stime = int(time.time()) - 5 * 86400 dpoints = 1000 etime = stime + (dpoints * 300) fname = 'test.rrd' gfname = 'test.png' rrdtool.create('test.rrd' , '--start' , str(stime) , 'DS:speed:COUNTER:600:U:U' , 'RRA:AVERAGE:0.5:1:576' , 'RRA:AVERAGE:0.5:6:336' ) ctime = stime cmiles = 0 for i in xrange(dpoints): bump = random.randint(1 , 20) cmiles += bump ctime += 300 rrdtool.update(fname , '%d:%d' % (ctime , cmiles)) rrdtool.graph(gfname , '--start' , str(etime - (24 * 3600)) , '--end' , str(etime) , '--vertical-label' , 'Speed m/h' , '--imgformat' , 'PNG' , '--title' , 'Speeds' , '--lower-limit' , '0' , 'DEF:myspeed=%s:speed:AVERAGE' % fname , 'CDEF:mph=myspeed,3600,*' , 'VDEF:msmax=mph,MAXIMUM' , 'VDEF:msavg=mph,AVERAGE' , 'VDEF:msmin=mph,MINIMUM' , 'VDEF:mspct=mph,95,PERCENT' , 'LINE1:mph#FF:My Speed' , r'GPRINT:msmax:Max\: %6.1lf mph' , r'GPRINT:msavg:Avg\: %6.1lf mph' , r'GPRINT:msmin:Min\: %6.1lf mph\l' , r'GPRINT:mspct:95th Perc\: %6.1lf mph\l' ) - That, coupled with the rrdtool man pages (which are very good, complete with examples) should be enough to get you started. - -- Jay Deiman \033:wq! -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkk9YNwACgkQQ0lr+ZVKSBiWTQCgoBuzQVeRHBlrJ7GONQAL0RFT qOwAn3cnbZot0q1qGf6mOFHS8QgQc53o =h7CZ -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Disclaimer: The information contained in this transmission, including any attachments, may contain confidential information of Panasonic Avionics Corporation. This transmission is intended only for the use of the addressee(s) listed above. Unauthorized review, dissemination or other use of the information contained in this transmission is strictly prohibited. If you have received this transmission in error or have reason to believe you are not authorized to receive it, please notify the sender by return email and promptly delete the transmission. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] list.index() question
Hi again! (Now that everyone was so helpful the first time you'll never get rid of me!) I had a question about using the index() function on a list -- as I walk the directory path, I want to see if a directory contains any files ending in a certain type ... if it does, I wanna do some stuff ... if not, I would like to move on ... . for dirpath, subFolders, files in os.walk(rootDir): try: i = files.index(*.flac) #how do I make it search for files that end in .flac ? for file in files: #do some things in here to sort my files except ValueError: pass Basically: how do I make it match *.flac ? I couldn't find anything on google (searching for python index just gets me a lot of indexes of python docs - wink) Thanks again, Damon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list.index() question
On 09/12/2008, Damon Timm [EMAIL PROTECTED] wrote: Basically: how do I make it match *.flac ? I couldn't find anything on google (searching for python index just gets me a lot of indexes of python docs - wink) Hi Damon, The fnmatch module will help here. It basically implements unix-style filename patterns. For example: import os import fnmatch files = os.listdir('.') flac_files = fnmatch(files, '*.flac') So, to test whether you have any flac files, you can just test whether fnmatch(files, '*.flac') is empty. If you wanted to roll your own solution (the fnmatch module is a bit obscure, I think), you could do something with os.path.splitext: files = os.listdir('.') extensions = [os.path.splitext(f)[1] for f in files] if '.flac' in extensions: print 'FLAC files found!' HTH! -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list.index() question
Damon Timm [EMAIL PROTECTED] wrote walk the directory path, I want to see if a directory contains any files ending in a certain type ... if it does, I wanna do some stuff Check out the glob module. for dirpath, subFolders, files in os.walk(rootDir): try: i = files.index(*.flac) #how do I make it search for files that end in .flac ? If yu call glob.glob() with the dirpath you will get a list of all the flac files in the current dir. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list.index() question
On Mon, Dec 8, 2008 at 7:05 PM, Damon Timm [EMAIL PROTECTED] wrote: Hi again! (Now that everyone was so helpful the first time you'll never get rid of me!) That's fine, pretty soon you'll be answering other people's questions :-) I had a question about using the index() function on a list -- as I walk the directory path, I want to see if a directory contains any files ending in a certain type ... if it does, I wanna do some stuff ... if not, I would like to move on ... . index() searches for a specific matching item, it doesn't have any wildcard ability. for dirpath, subFolders, files in os.walk(rootDir): try: i = files.index(*.flac) #how do I make it search for files that end in .flac ? for file in files: #do some things in here to sort my files except ValueError: pass I'm not sure what you want to do, but if you just want to operate on files that end with .flac, you can just say for file in files: if not file.endswith('.flac'): continue though 'file' is not a good variable name, there is a builtin of that name. Basically: how do I make it match *.flac ? I couldn't find anything on google (searching for python index just gets me a lot of indexes of python docs - wink) There is actually an index: http://docs.python.org/genindex.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] list.index() question
On Mon, Dec 8, 2008 at 7:55 PM, Kent Johnson [EMAIL PROTECTED] wrote: index() searches for a specific matching item, it doesn't have any wildcard ability. Ah ha! There is actually an index: http://docs.python.org/genindex.html Heh heh - and the info I was looking for is at: http://docs.python.org/library/stdtypes.html#index-584 ... I've become google dependent ... if it's not on google I don't know where to look. Thanks for the .endswith() tip. On 12/8/08 7:47 PM, Alan Gauld wrote: Check out the glob module. for dirpath, subFolders, files in os.walk(rootDir): try: i = files.index(*.flac) #how do I make it search for files that end in .flac ? If yu call glob.glob() with the dirpath you will get a list of all the flac files in the current dir. Heading to check out glob.glob() now ... On 12/8/08 7:29 PM, John Fouhy wrote: The fnmatch module will help here. It basically implements unix-style filename patterns. For example: import os import fnmatch files = os.listdir('.') flac_files = fnmatch(files, '*.flac') So, to test whether you have any flac files, you can just test whether fnmatch(files, '*.flac') is empty. If you wanted to roll your own solution (the fnmatch module is a bit obscure, I think), you could do something with os.path.splitext: files = os.listdir('.') extensions = [os.path.splitext(f)[1] for f in files] if '.flac' in extensions: print 'FLAC files found!' And then to look at fnmatch! Thanks for the direction -- on my way ... On 12/8/08 7:55 PM, Kent Johnson wrote: On Mon, Dec 8, 2008 at 7:05 PM, Damon Timm [EMAIL PROTECTED] wrote: Hi again! (Now that everyone was so helpful the first time you'll never get rid of me!) That's fine, pretty soon you'll be answering other people's questions :-) Not quite there yet ... one day, maybe. I can show people where the index for index is! Damon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor