From: Noel O'B. <bao...@gm...> - 2007-07-09 09:24:45
|
On 09/07/07, Karol Langner <kar...@kn...> wrote: > 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. For the record, the output from Pickle *is* platform-independent (it's actually just an ASCII file); the output from the faster cPickle is *not* platform-independent (it's a binary file). > 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 Exactly. Although I wouldn't called it ParsedData, as the information didn't necessarily come from a parsing. Why not just call it something like cclibData, or ccData (although we don't want to get confused with Creative Commons)? > 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 > |