inkedmn
05-01-2002, 07:44 PM
ok, the html search thing is working (thanks to Strike :)), and now i'm trying to write a class that will search the text file all that stuff was written to. Basically, the text file is 2.5mb of these:
Username: Someuser
Member Number: 100
Email: me@yomomma.com
ICQ: 123456789
AIM: AIMMEMBERNAME
all formatted exactly the same way. now, for the search class...
here's what i want it to do:
the constructor just initializes a series of variables, nothing more.
the first method is supposed to open the text file and read each line (one at a time) into memory, check for the string "Username:" and add that plus whatever's after it to a dictionary as key:value.
that last part isn't working. i try to print using some test code and i get an empty dictionary.
here's the code:
import string, sys
class LnoSearch:
def __init__(self, name='', memnum=''):
self.name = name
self.user = self.name.lower()
self.memnum = memnum
self.list = []
def parseFile(self, file):
data = open(file, 'r')
listitem = -1
for line in data.readline():
word = line.split(' ')
dict = {}
if word[0] == 'Username:':
print 'ok1'
dict[word[0]] = word[1]
self.list.append(dict)
listitem += 1
any ideas?
thanks...
Username: Someuser
Member Number: 100
Email: me@yomomma.com
ICQ: 123456789
AIM: AIMMEMBERNAME
all formatted exactly the same way. now, for the search class...
here's what i want it to do:
the constructor just initializes a series of variables, nothing more.
the first method is supposed to open the text file and read each line (one at a time) into memory, check for the string "Username:" and add that plus whatever's after it to a dictionary as key:value.
that last part isn't working. i try to print using some test code and i get an empty dictionary.
here's the code:
import string, sys
class LnoSearch:
def __init__(self, name='', memnum=''):
self.name = name
self.user = self.name.lower()
self.memnum = memnum
self.list = []
def parseFile(self, file):
data = open(file, 'r')
listitem = -1
for line in data.readline():
word = line.split(' ')
dict = {}
if word[0] == 'Username:':
print 'ok1'
dict[word[0]] = word[1]
self.list.append(dict)
listitem += 1
any ideas?
thanks...