Difference between revisions of "Python"

From Healthcare Robotics Wiki
Jump to: navigation, search
(HRL Coding Standards)
(HRL Coding Standards)
Line 1: Line 1:
 
== HRL Coding Standards ==
 
== HRL Coding Standards ==
* In general, we follow the official python coding standards ([http://www.python.org/dev/peps/pep-0008/ Python standards]) but we will summarize here the relevant key points.
+
In general, we follow the official python coding standards ([http://www.python.org/dev/peps/pep-0008/ Python standards]) but we will summarize here the relevant key points.
** Every indent is 4 spaces, replace '''all''' tabs with spaces.
+
* Every indent is 4 spaces, replace '''all''' tabs with spaces.
** ClassName, method_name, _private_name
+
* ClassName, method_name, _private_name
** Use classes sparingly, please try to define functions whenever possible.  Functions should not be more than a page or two long unless there is an extremely good reason to do so.
+
* Use classes sparingly, please try to define functions whenever possible.  Functions should not be more than a page or two long unless there is an extremely good reason to do so.
** Instead of using inheritance, use [http://en.wikipedia.org/wiki/Duck_typing duck typing] (i.e. define interfaces based on conventions)
+
* Instead of using inheritance, use [http://en.wikipedia.org/wiki/Duck_typing duck typing] (i.e. define interfaces based on conventions)
** With numpy, use matrices instead of arrays, all vectors should be column vectors.
+
* With numpy, use matrices instead of arrays, all vectors should be column vectors.
** We use doxygen styled comments:
+
* We use doxygen styled comments:
 
   ##
 
   ##
 
   # some comments
 
   # some comments
Line 14: Line 14:
 
   def my_function(a, b):
 
   def my_function(a, b):
 
       return b*a
 
       return b*a
** Use default parameters sparingly
+
* Use default parameters sparingly
** We use python 2.5.2
+
* We use python 2.5.2
** Use whitespace to separate functional parts of code, but '''do not''' use them misleadingly.  This is misleading:
+
* Use whitespace to separate functional parts of code, but '''do not''' use them misleadingly.  This is misleading:
 
         self.size_image = highgui.cvQueryFrame(self.capture)
 
         self.size_image = highgui.cvQueryFrame(self.capture)
         self.size = cv.cvGetSize( self.size_image )
+
         self.size = cv.cvGetSize( self.size_image )<br><br> 
 
+
         self.color = cam_param['color']<br><br>
         self.color = cam_param['color']
+
 
+
 
         self.intrinsic_cvmat = cv.cvCreateMat(3,3,cv.CV_32FC1)
 
         self.intrinsic_cvmat = cv.cvCreateMat(3,3,cv.CV_32FC1)
 
         self.distortion_cvmat = cv.cvCreateMat(1,4,cv.CV_32FC1)
 
         self.distortion_cvmat = cv.cvCreateMat(1,4,cv.CV_32FC1)

Revision as of 21:37, 20 November 2009

HRL Coding Standards

In general, we follow the official python coding standards (Python standards) but we will summarize here the relevant key points.

  • Every indent is 4 spaces, replace all tabs with spaces.
  • ClassName, method_name, _private_name
  • Use classes sparingly, please try to define functions whenever possible. Functions should not be more than a page or two long unless there is an extremely good reason to do so.
  • Instead of using inheritance, use duck typing (i.e. define interfaces based on conventions)
  • With numpy, use matrices instead of arrays, all vectors should be column vectors.
  • We use doxygen styled comments:
 ##
 # some comments
 # @param a is 3x1 point in coordinate frame C
 # @param b is a 3x3 rotation matrix
 # @return a 3x1 vector rotated by b
 def my_function(a, b):
     return b*a
  • Use default parameters sparingly
  • We use python 2.5.2
  • Use whitespace to separate functional parts of code, but do not use them misleadingly. This is misleading:
       self.size_image = highgui.cvQueryFrame(self.capture)
       self.size = cv.cvGetSize( self.size_image )

self.color = cam_param['color']

self.intrinsic_cvmat = cv.cvCreateMat(3,3,cv.CV_32FC1) self.distortion_cvmat = cv.cvCreateMat(1,4,cv.CV_32FC1)

The below would be preferred if there are not obvious separations:

       self.size_image = highgui.cvQueryFrame(self.capture)
       self.size = cv.cvGetSize( self.size_image )
       self.color = cam_param['color']
       self.intrinsic_cvmat = cv.cvCreateMat(3,3,cv.CV_32FC1)
       self.distortion_cvmat = cv.cvCreateMat(1,4,cv.CV_32FC1)

learning python

math, science, numerical, etc.

opencv

efficiency