473,800 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trying to loop glob/md5 [list comprehension solution]

3 New Member
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()
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 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()

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
jdjohns74
3 New Member
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 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:

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
2524
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
15
3088
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 *.
6
1496
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
2611
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
10
1665
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
6
1941
by: MackS | last post by:
Hello everyone Consider the following >>> l = >>> for i in l: .... i = i + 1 .... >>> l
19
1747
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)
14
28307
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
2414
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
0
9551
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,...
0
10504
Oralloy
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...
0
10274
jinu1996
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...
1
10251
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,...
0
9085
agi2029
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...
1
7576
isladogs
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...
0
6811
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();...
0
5469
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...
1
4149
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

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.