Small ape circle python learning - Notes

With further study, before long, you'll be able to write complex of thousands or even tens of thousands of lines of code in it, some of the code you spend a long time to write, and after a few days to see a return, he discovered not read, Haha, this is too normal. In addition, you will find later in the work, a project mostly done by several or even dozens of people working together, you have to call the code written by someone else, others also with you, if the code does not add a comment, you have I can not read, let alone others, so write and beaten. Therefore, in order to avoid such embarrassing things happen, we must increase the readability of your code.

Note the code division multi-line and single-line comments, with a single line comment #, the comment may be multi-line three pairs of double quotes“”” “””

Here for everyone to see the comment section of the standard code, ignore the meaning of the code

  1. def subclass_exception(name, parents, module, attached_to=None):
  2. """
  3. Create exception subclass. Used by ModelBase below.
  4. If 'attached_to' is supplied, the exception will be created in a way that
  5. allows it to be pickled, assuming the returned exception class will be added
  6. as an attribute to the 'attached_to' class.
  7. """
  8. class_dict = {'__module__': module}
  9. if attached_to is not None:
  10. def __reduce__(self):
  11. # Exceptions are special - they've got state that isn't
  12. # in self.__dict__. We assume it is all in self.args.
  13. return (unpickle_inner_exception, (attached_to, name), self.args)
  14. def __setstate__(self, args):
  15. self.args = args
  16. class_dict['__reduce__'] = __reduce__
  17. class_dict['__setstate__'] = __setstate__
  18. return type(name, parents, class_dict)

Code comments principles:


    1. Not all the code to add comments, or just need to find it difficult to understand the important part to add a comment to their own

    1. Comments can either Chinese or English, but never Pinyin oh

    1. Not only to give their comments to see, but also to others, so please write carefully

 

 

Guess you like

Origin www.cnblogs.com/lele234/p/11242324.html