More List Comparison Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bucco

    #1

    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(dirL ist)
    self.fileList = set(open(fileLi st, 'r').readlines( ))
    self.matchList = []
    self.retList = []
    self.rut = []
    def match(self):
    for item in dirList:
    rut = os.path.splitex t(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(dirLi st, 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?

  • Bucco

    #2
    Re: More List Comparison Help

    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

    Comment

    Working...