newb comment request
__peter__ at web.de
Thu Nov 27 10:05:09 CET 2003
> Im a newb to dev and python... my first sefl assigned mission was to read
> a pickled file containing a list with DB like data and convert this to
> MySQL... So i wrote my first module which reads this pickled file and
> writes an XML file with list of tables and fields (... next step will the
> module who creates the tables according to details found in the XML file).
> If anyone has some minutes to spare, suggestions and comments would be
> verry much appreciated to help me make my next modules better.. and not
> starting with bad habit :)
I would suggest that you repost the script without the excessive comments.
Most programmers find Python very readable, your comments actually make it
harder to parse for the human eye.
Also, make it work if you can, or point to the actual errors that you cannot
fix yourself. Provide actual test data in your post instead of the
unpickling code, so that others can easily reproduce your errors.
Only then you should ask for improvements.
Object oriented programming is about programming against interfaces, so
exessive type checking is a strong hint to design errors.
Avoid using global variables in your functions; rather pass them explicitly
Where is valuesD introduced?
"%s" % str(1.23)
is the same as
"%s" % 1.23
type(value) is not types.NoneType
is the same as
value is not None
Module level code is habitually wrapped like so:
if __name__ == "__main__":
infile = open('cached-objects-Python-pickled-sample', 'rb')
_data = pickle.load(infile)
# process _data...
That way, you can import the module as well as use it as a standalone
I'm sure, there is more, but then again, clean up the comments, try to make
it work, and then repost.
More information about the Python-list