> The way I'm reading your code, it's not the generator that's the > difference here. Consider these lines: > > > for item in doc['meeting']['race']: > > > > def return_files(file_list): > > for filename in sorted(file_list, *attribs): > > for item in doc([attribs]): > > Firstly, did you mean for *attribs to be part of the signature of > return_files? As it is, it's being given to sorted(), which won't work > (the other args to sorted are keyword-only). > > Assuming that to be the case, what you're trying to do is subscript an > object with a variable set of attributes: > > return_files(files, "meeting", "race') > > That can best be done with a little loop: > > def return_files(file_list, *attribs): > ... > for attr in attribs: > doc = doc[attr] > for item in doc: > > If that's not what you want, can you further clarify the question? > > ChrisA
Thanks ChrisA, what I am wanting to do is to create a generator for my file input to only pull the file when the last has processed. Then have my separate functions to process the files as required as each will have different attribute combinations and processing. My thinking is that having been reading SQLAlchemy I will be creating the models to represent the tables and the relationships. Therefore if I had 3 tables for name and people attributes, another for location(meeting) details and a central table for event details, then if the generator pulls a file I can parse it with each function. Each function would update the model and then call back to the generator for another file. My concern is that as some process in each table will be longish it is better to keep that separate and just call them from a main function. Maybe the generator should just stop at parsing the file at the root XML level so that each calling function can then hook up from its node. Is that clear or a massive brain dump? Sayth -- https://mail.python.org/mailman/listinfo/python-list