More List Comparison Help

Discussion in 'Python' started by Bucco, Aug 21, 2006.

  1. Bucco

    Bucco Guest

    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?
     
    Bucco, Aug 21, 2006
    #1
    1. Advertising

  2. Bucco

    Bucco Guest

    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
     
    Bucco, Aug 21, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keith
    Replies:
    8
    Views:
    3,840
  2. Michael
    Replies:
    4
    Views:
    473
    Matt Hammond
    Jun 26, 2006
  3. Robert Klemme

    With a Ruby Yell: more, more more!

    Robert Klemme, Sep 28, 2005, in forum: Ruby
    Replies:
    5
    Views:
    242
    Jeff Wood
    Sep 29, 2005
  4. Dave Woodworth

    more efficient date range comparison

    Dave Woodworth, Apr 12, 2009, in forum: Ruby
    Replies:
    7
    Views:
    162
    Dave Woodworth
    Apr 16, 2009
  5. Deepu
    Replies:
    1
    Views:
    268
    ccc31807
    Feb 7, 2011
Loading...

Share This Page