newbie write to file question

Rob E remm1 at member.fsf.org
Sun Dec 4 11:17:00 EST 2005


> I'm not sure what I'm
> missing so I'd appreciate some advice.
You question is pretty general and I'm not going to go over this in any
great detail, but I will make a few comments. 

*  In your if section use if ... else constructs not all the strange if 
   and then not if blocks.  Also get rid of all those unneeded if's with the 
   pass in them.  They do nothing.
*  You may want to put the heart of the code in a separate function or if 
   you need persistance, use a class.  Optional and depends on how complex
   your analysis code is going to be.  Generally one function should not
   be two deep in terms of block nesting for readabilily
   and maintainability.
*  the table initialization i.e. table = {} was outside of your main file
   scan loop, that seemed strange to me since I think you were doing this
   file by file.
*  your log writing code was indented below the the if sub_three is None:
   if block which means that it's inside that block -- that's probably not
   what you want.  Remember python defines blocks by indentation.  The
   indentation is a nice feature because python blocking is in fact like
   it looks (unlike C++).  
*  if your parsing XML and maybe SGML the python library has some special 
   tools for this.  You might want to look at the lib or search the net.

Take care,
Rob




More information about the Python-list mailing list