"Alan Gauld" wrote
class Item(object):
def __init__(self, aFile):
data = aFile.readline().strip().split(:)
setattr(self, data[0], data[1])
The last two lines should of course be repeated 3 times...
Either in a loop or - for just 3 items - maybe hard coded...
items = []
f =
"Stefan Lesicnik" wrote
I have a file that has text in a certain format. Lets assume
'''
name: stefan
id: 12345
color: blue
name: joe
id: 54321
color: red
'''
The format is predictable. I understand for non predictable text, you
would
have to use pyparser or the like to build a match.
T
vince spicer wrote:
you can build a dictionary and keep the active key, again this would only
work in predictable data
users = {}
name = None
for line in file:
key, value = [x.strip() for x in line.split(":")]
if key == "name":
name = data[1]
users[name] = {}
else:
you can build a dictionary and keep the active key, again this would only
work in predictable data
users = {}
name = None
for line in file:
key, value = [x.strip() for x in line.split(":")]
if key == "name":
name = data[1]
users[name] = {}
else:
users[name][d
Hi Guys,
It seems like this keeps coming up (for me anyways), and i'm never sure how
to do it. I'm very new to programming...
I have a file that has text in a certain format. Lets assume
'''
name: stefan
id: 12345
color: blue
name: joe
id: 54321
color: red
'''
The format is predictable. I unde