473,378 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 1422
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Craig Keightley | last post by:
is it possible to compare acomma separated list aginst another eg comma list 1 => 1,2,3,4,5 comma list 2 => 3,5 can you check that 3 is in both, and 5 is in both, therfore they match??? the...
41
by: Xah Lee | last post by:
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of...
2
by: Balaji. M. | last post by:
Hi All, Help me to sort out the contents in the list box. The list box contains data elements like <first name> + <middle name> + <last name> as "Balaji Muthu Varathan" I want to sort it...
39
by: Antoon Pardon | last post by:
I was wondering how people would feel if the cmp function and the __cmp__ method would be a bit more generalised. The problem now is that the cmp protocol has no way to indicate two objects are...
8
by: Rajesh | last post by:
Question :An element in a sorted list can be found in O(log n) time via binary search. But suppose I rotate the sorted list at some pivot unknown to you beforehand. So for instance, 1 2 3 4 5 might...
5
by: akameswaran | last post by:
Disclaimer - I recognize this is not a practical exercise. There are many implementations around that would do the job better, more efficiently (Meaning in C) or whatever. I caught some thread...
3
by: ASP Developer | last post by:
I have a generic list of objects. These objects have a text field that contains a letter for the first character and numbers for the next three. For example, "A001". I need to sort these by...
9
by: Sheldon | last post by:
Hi, I am trying to understand linked lists and the different ways to write a linked list and double linked list. I have been trying to get this function called insert_word to work but to no...
12
by: Godzilla | last post by:
Hello, I'm trying to find a way to convert an integer (8-bits long for starters) and converting them to a list, e.g.: num = 255 numList = with the first element of the list being the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.