creating lists based on parsed items

Jason White jwhite at casl.umd.edu
Wed Jun 6 18:24:54 CEST 2007


Hello all ... 

Sorry for jumping in and askig with 0 lurk-time.

I am trying to do what (I think) should be fairly straightforward. I have a list of items that i want to sort into buckets. in item 1 of each line is the object I want to sort and in item 2 is the name of the bucket. I am making it dynamic however (so I don't know the bucket names in advance).

I've spent a few hours in the archives and several sites (hate to consider my google search history against the term 'python' right now ... anyhoo ...) This is what I've pieced together so far.


       ## varName is the name of the bucket that I got out of the split line (comma separated)
       try:
            eval (varName + '.append("' + items[0] + '")')
        except NameError:
            ##print 'could not use ' + varName
            eval (varName + ' = []')
            print 'created ' + varName + 'as list'
        
        cmd2 = varName + '.append("' + items[0] + '")'
        print eval(cmd2)

What I get back is:

Traceback (most recent call last):
  File "./dict_2_slex.py", line 25, in ?
    eval (varName + ' = []')
  File "<string>", line 1
    noun = []
         ^ 
Any help for a python newb?!?

TIA,

Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070606/504a7cfd/attachment.html>


More information about the Python-list mailing list