From: Karol L. <kar...@kn...> - 2007-07-09 08:06:52
|
On Monday 25 June 2007 07:15, Noel O'Boyle wrote: > Actually, this makes me realise that we need to separate the parser > from the parsed data. Yikes! I think I always knew that this was a > possibility, but I never really thought about reading in data. The > parsers will need to create an instance of CalculationResults or > something, whose attributes will be aonames, etc. One of the > additional benefits of this, is that the data can simply be pickled to > a file, which is what you (Karol) should be using for your own scripts > for communicating between Python programs (see 'pickle' in the > standard library). > > Noel Yes! This is something I mentioned some time ago, in a slightly different context. I tried pickling some time ago, and some parser attributes (logger, progress) were crashing it - with this kind of separation pickling would be possible without additional hacks. Also, I don't think the output from pickle is platform-independent, so I can't freely move it between the computers I do calculation on - here a text format is the safest. Let's see if we are thinking along the same lines here. The parser would create a blank ParsedData object as an attribute in its parse() method, and possible return that object (return self.data)? So the syntax for using the parsers would need to change, to something like: >>> myparser = ccopen("....") >>> mydata = myparser.parse() >>> dir(mydata) ['aoname', 'natom', ....] >>> mydata is myparser.data True It strikes me that this does not require many changes in the code! It does imply, however, a general change in the way the parser is used. The ParsedData class can then a method for dumping to json or whatever. I wonder if there is a way to do this without changing the present syntax for parsing. Cheers, Karol -- written by Karol Langner Mon Jul 9 09:28:32 EDT 2007 |