
May 28th, 2004, 09:13 AM
|
 |
PHP ninja
|
|
Join Date: Jul 2003
Location: Melbourne, Australia
Posts: 20
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Creating a list of tuples
I am trying to populate a list ot tuples on the fly from a file but keep running into these errors:
Code:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "forum.py", line 84, in getPosts
posts[0] = [(details[0],(details[1],details[2],details[3]),post)]
IndexError: list assignment index out of range
Here is and simplified example of what i am trying to do:
Code:
def getDetails(path, id):
"Returns a list of user details in file "
f = open(path + id + ".info", "r")
index = 0
posts = []
line = f.readline()
while line != "":
line = f.readline()
details = string.split(line[:-1], ",")
posts[index] = [(details[0],(details[1],details[2],details[3]),details[4])]
index += 1
f.close()
return posts
Can somebody help I seem to be stuck
|