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.
['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?
into a snag in which I am getting the wrong output from my class.
output:python matchlist.py ./test ./test/list.txt
['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?