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').r ead() I get a IOError: (2, 'No such file or directory', 'c')
Traceback (innermost last):
File "c:\Python examples\md5mak r_test4.py", line 1, in ?
#!/usr/bin/python
File "c:\Python examples\md5mak r_test4.py", line 20, in ?
data = file(fn,'rb').r ead() -
#!/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 2748 bartonc 6,596
Recognized Expert Expert
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.
bartonc 6,596
Recognized Expert Expert
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 equivalent to
>>> for x in :
but is shorter and easier to read. basically, the if works as a filter for
|
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
C:\Temp>dir /b *.
|
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
useful for list/generator comprehensions, for example being able to write something like:
instead of the less elegant explicit loop version that has to check for the length of each sequence.
What do you think ?
George
|
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 syntax" error, of course):
for i in c if <test>:
print i*2
| |
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)):
tmp.extend(*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 it doesn't work! i can't use glob wildcard with linecache
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |