[Tutor] dictionary looping problem
Hello, I'm trying to gather a list of files and md5 hash them to do a checksum. I've created a function for each dictionary. However, when i print out the dictionary I don't get all the items. Any ideas? Thanks< JJ CODE: #!/usr/bin/python import os import md5 import sys source={} target={} source_path="/path/source" target_path="/path/target" def gather_files(dir,dict): os.chdir(dir) names=os.listdir(dir) for filename in names: hash=os.system("md5 "+ filename) dict[hash] = filename print dict gather_files(source_path,source) gather_files(target_path,target) OUTPUT: # python new.py b481bb58b296a62d744d3006d0156f61 1 e07910a06a086c83ba41827aa00b26ed 3 749a92a5ba327db2f2711b1a8d3cc0ab 2 {0: '2'} b481bb58b296a62d744d3006d0156f61 1 e6139f93eb47c9fe7eb7fc5ddb586511 3 7ce1a3a4baf75dea4397e36c97e1fc0b 2 {0: '2'} 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
Re: [Tutor] dictionary looping problem
Thanks for clearing this up for me. On Tue, 2008-12-02 at 13:25 -0800, Steve Willoughby wrote: > On Tue, Dec 02, 2008 at 01:08:09PM -0800, Jeremiah Jester wrote: > > Hello, > > > > I'm trying to gather a list of files and md5 hash them to do a > checksum. > > I've created a function for each dictionary. However, when i print > out > > the dictionary I don't get all the items. Any ideas? > > Yep. Don't use os.system() there. > > 1. you're running the "md5" program externally when you don't need to, >since Python has the ability to compute md5 checksums on its own, >which you already know because you imported that module at the top >of your script (and then didn't use). > > 2. The return value from os.system() is NOT the hash, so what you're >storing in the dictionary is not going to be that unique, and so >each call which yields the same return value (0, usually) will >overwrite that element in the dict. > > -- > Steve Willoughby| Using billion-dollar satellites > [EMAIL PROTECTED] | to hunt for Tupperware. > > > 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] rrdtool examples.
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 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
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] curl and python
I'm trying to get curl to traverse a remote http directory get all page names and do some processing on these file with python. For starters, i need to get the directory listing in an array from the domain. Any ideas on how to do this? Thanks, JJ 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