473,322 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

trying to loop glob/md5 [list comprehension solution]

I've never written a Python program before and I'm trying to read a config file with file path/names (eg. c:\\python24\\*.dll, ... *.exe) to create an ouput file of filename + md5 values. I'm confused. I'm trying to lern how to use Wing IDE and step through the Stack Data. It seems to be working but on the
for fn in filelist:
data = file(fn,'rb').read()
I get a
IOError: (2, 'No such file or directory', 'c')

Traceback (innermost last):

File "c:\Python examples\md5makr_test4.py", line 1, in ?
#!/usr/bin/python
File "c:\Python examples\md5makr_test4.py", line 20, in ?
data = file(fn,'rb').read()
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2. # Filename: md5makr_test4.py
  3.  
  4. import sys, os, os.path, glob, md5, ConfigParser
  5.  
  6. config = ConfigParser.ConfigParser()
  7. config.read('md5makr.ini')
  8.  
  9. outputfilname = config.get('general', 'outputfile')
  10. f = file(outputfilname,'wt')
  11. fileconfig = config.get('general', 'inputfiles')
  12.  
  13. fl = file(fileconfig,'r')
  14. fileData = fl.read()
  15.  
  16. for f1 in glob.glob(fileData):
  17.   filelist = f1
  18.  
  19. for fn in filelist:
  20.   data = file(fn,'rb').read()
  21.   hexstring = md5.md5(data).hexdigest()
  22.   f.write(fn + '\t' + hexstring + '/n')
  23.  
  24. f.close()
Any insight or help would be appreciated.
Sep 27 '06 #1
3 2726
bartonc
6,596 Expert 4TB
In order to make a list in a loop you must append to an empty list.
Use print statements to see what your data looks like; you may need to extract only a piece of glob.glob()

Expand|Select|Wrap|Line Numbers
  1. filelist=[]
  2. for f1 in glob.glob(fileData):
  3.     print f1
  4.     filelist.append(f1)
  5.  
Sep 27 '06 #2
In order to make a list in a loop you must append to an empty list.
Use print statements to see what your data looks like; you may need to extract only a piece of glob.glob()

Expand|Select|Wrap|Line Numbers
  1. filelist=[]
  2. for f1 in glob.glob(fileData):
  3.     print f1
  4.     filelist.append(f1)
  5.  
Thanks. I'll give it a shot.
Sep 27 '06 #3
bartonc
6,596 Expert 4TB
Thanks. I'll give it a shot.
Once you know that works,
it's even tighter if you use a list comprehension:

Expand|Select|Wrap|Line Numbers
  1. fileList = [f1 for f1 in glob.glob(filedata)]
  2.  
Nov 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ryan Lowe | last post by:
i thought id ask here before wirting a PEP, if people thought it would be a good enhancement to allow if clauses in regular for-statements like so: >>> for x in y if x < 10 : is semantically...
15
by: Georgy Pruss | last post by:
On Windows XP glob.glob doesn't work properly for files without extensions. E.g. C:\Temp contains 4 files: 2 with extensions, 2 without. C:\Temp>dir /b * aaaaa.aaa bbbbb.bbb ccccc ddddd ...
6
by: Eric | last post by:
Pythonistas, I seem at a loss for a List Comprehension syntax that will do what I want. I have a list of string position spans: >>> breaks the first pair representing: someString
16
by: George Sakkis | last post by:
I'm sure there must have been a past thread about this topic but I don't know how to find it: How about extending the "for <X> in" syntax so that X can include default arguments ? This would be very...
10
by: s.lipnevich | last post by:
Hi All, I apologize if this was brought up before, I couldn't find any "prior art" :-). On more than one occasion, I found myself wanting to use a "conditional loop" like this (with "Invalid...
6
by: MackS | last post by:
Hello everyone Consider the following >>> l = >>> for i in l: .... i = i + 1 .... >>> l
19
by: bvdp | last post by:
Please help my poor brain :) Every time I try to do a list comprehension I find I just don't comprehend ... Anyway, I have the following bit of code: seq = tmp = for a in range(len(seq)):...
14
by: erikcw | last post by:
Hi, I'm trying to turn o list of objects into a dictionary using a list comprehension. Something like entries = {} = d.id] for d in links]
5
by: jo3c | last post by:
hi everyone happy new year! im a newbie to python i have a question by using linecache and glob how do i read a specific line from a file in a batch and then insert it into database? because...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.