More List Comparison Help

B

Bucco

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?
 
B

Bucco

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top