That doesn't work. I just get an error: x = eval(line.strip('\n')) File "<string>", line 1 [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})]
SyntaxError: unexpected EOF while parsing any other ideas? Bruno Desthuilliers wrote: > manstey wrote: > > Hi, > > > > I have a text file called a.txt: > > > > # comments > > [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})] > > [('recId', 5), ('parse', {'pos': u'np', 'gen': u'm'})] > > [('recId', 7 ), ('parse', {'pos': u'np', 'gen': u'm'})] > > > > I read it using this: > > > > filAnsMorph = codecs.open('a.txt', 'r', 'utf-8') # Initialise input > > file > > dicAnsMorph = {} > > for line in filAnsMorph: > > if line[0] != '#': # Get rid of comment lines > > x = eval(line) > > dicAnsMorph[x[0][1]] = x[1][1] # recid is key, parse dict is > > value > > > > But it crashes every time on x = eval(line). Why is this? If I change > > a.txt to: > > > > # comments > > [('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})] > > > > it works fine. Why doesn't it work with multiple lines? it's driving me > > crazy! > > try with: > x = eval(line.strip('\n')) > > > -- > bruno desthuilliers > python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for > p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list