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() -
#!/usr/bin/python
-
# Filename: md5makr_test4.py
-
-
import sys, os, os.path, glob, md5, ConfigParser
-
-
config = ConfigParser.ConfigParser()
-
config.read('md5makr.ini')
-
-
outputfilname = config.get('general', 'outputfile')
-
f = file(outputfilname,'wt')
-
fileconfig = config.get('general', 'inputfiles')
-
-
fl = file(fileconfig,'r')
-
fileData = fl.read()
-
-
for f1 in glob.glob(fileData):
-
filelist = f1
-
-
for fn in filelist:
-
data = file(fn,'rb').read()
-
hexstring = md5.md5(data).hexdigest()
-
f.write(fn + '\t' + hexstring + '/n')
-
-
f.close()
Any insight or help would be appreciated.
3 2726
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() -
filelist=[]
-
for f1 in glob.glob(fileData):
-
print f1
-
filelist.append(f1)
-
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() -
filelist=[]
-
for f1 in glob.glob(fileData):
-
print f1
-
filelist.append(f1)
-
Thanks. I'll give it a shot.
Thanks. I'll give it a shot.
Once you know that works,
it's even tighter if you use a list comprehension: -
fileList = [f1 for f1 in glob.glob(filedata)]
-
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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
...
|
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
|
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...
|
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...
|
by: MackS |
last post by:
Hello everyone
Consider the following
>>> l =
>>> for i in l:
.... i = i + 1
....
>>> l
|
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)):...
|
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]
|
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...
|
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...
|
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...
|
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...
|
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)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
|
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...
|
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...
| |