469,304 Members | 2,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

More List Comparison Help

I have taken into advice what was mentioned earlier, but I have run
into a snag in which I am getting the wrong output from my class.
python matchlist.py ./test ./test/list.txt
output:
['list.txt', 'test1.txt', 'test2.txt']
set(['test1'])
['', '/', 't', 'e', 's', 't']

The first line of output correctly displays the list of file names in
the argv[1] directory.
The second line of output correctly displays the set list from
readlines on list.txt.
The third line of out put should be the same as the 1st line minus the
extenxions in the file names.

Here is the code:

import os
from sys import argv

class MatchList:
def __init__(self, dirList, fileList):
self.dirList = os.listdir(dirList)
self.fileList = set(open(fileList, 'r').readlines())
self.matchList = []
self.retList = []
self.rut = []
def match(self):
for item in dirList:
rut = os.path.splitext(item)[0]
self.matchList.append(rut)
print self.matchList
def testPrint(self):
print self.dirList
print self.fileList
self.match()

if __name__ == '__main__':
if len(argv) == 3:
dirList = argv[1]
fileListName = argv[2]
match = MatchList(dirList, fileListName)
match.testPrint()

What I want to happen is produce a list of the filenames minus the
extensions so that I can set that list. Once that list is set, I can
subtract the set list from the readlines function and then use the
difference list to determine what files are missing form the directory.

Thanks in advance:)
SA

P.S. Is there a special way to include code in my postings so that it
looks different from the rest of the text in the posting?

Aug 21 '06 #1
1 1335
Nevermind. I found my own error. I referenced the input values
instead of the class object self. That is what I get for staring at
the code too long.

Thanks:)

SA

Aug 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Craig Keightley | last post: by
2 posts views Thread by Balaji. M. | last post: by
39 posts views Thread by Antoon Pardon | last post: by
8 posts views Thread by Rajesh | last post: by
5 posts views Thread by akameswaran | last post: by
3 posts views Thread by ASP Developer | last post: by
9 posts views Thread by Sheldon | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.