len wrote: > Hi all > > I have a file that I receive from another party which is basicly a csv > file containing the following type of information; > > Tagname Scope Value > "first_name","POL01","John" > "last_name","POL01","Doe" > "birthday","POL01","04/03/61" > etc > > I need to convert this file info into my file format used in my > application. > > I have been given a file from the other company that gives me all of > the tagname that could be used and their scope. I want to build a > table which would have all of the various tagnames, scope, and put a > fieldname equivalent in the fieldname in my file structure in my > application. Then read through the vendors csv file index into my > table file and get the field name of where to move the data into my > data structure. > > Here is my question? basicly I need to get the data referenced by > fieldname variable in my table and then use that data as a variable > name in a python assignment statement. Thus changing the actual python > code at each iteration through the lines in the csv file. > > for i in tagfile > find tagname in tagtable > > *** the following line of code would change through each iteration *** > myfirst = value > > *** next iteration > mylast = value > > *** next iteration > mybirth = value > > etc > > I hope this make sense. I remember seeing something like this > somewhere. >
You need to define the problem much better than you have in your two postings so far. Give a small realistic sample of input file and the relevant parts of the xref file plus (the main missing component so far) the actual OUTPUT that you desire from that input. Then we can talk about implementatiion. However while we're waiting, wtite this on your whiteboard: (1) *DO* use the csv module; DIY approaches blow up spectacularly when presented with data which has embedded commas and quotes, and don't say it can't happen because it does. (2) *DON'T* pay any attention to suggestions that you should use exec or eval. The likelihood that your problem *needs* that "the following line of code would change through each iteration" is very small. The likelihood that the solution can be written in a straight-forward manner is high. What are your "SQL files"? Do you mean insert scripts that you will use to inject the transformed incoming into a database, or something else? Again, a short *example* of what you are referring to would help. HTH, John -- http://mail.python.org/mailman/listinfo/python-list