2012年4月30日 星期一

Python - a study note

Reference : http://www.rexx.com/~dkuhlman/python_book_01.html
  • Naming
    • Allowed characters in a name: a-z A-Z 0-9 underscore, and must begin with a letter or underscore.
    • Names and identifiers are case sensitive.
    • Identifiers can be of unlimited length.Special names, customizing, etc. -- Usually begin and end in double underscores.
    • Special name classes -- Single and double underscores.
      • Leading double underscores -- Name mangling for method names.
      • Leading single underscore -- Suggests a "private" method name in a class. Not imported by "from module import *".
      • Trailing single underscore -- Sometimes used to avoid a conflict with a keyword, for example, class_.
    • Naming conventions -- Not rigid, but here is one set of recommendations:
      • Modules and packages -- all lower case.
      • Globals and constants -- Upper case.
      • Class names -- Bumpy caps with initial upper.
      • Method and function names -- All lower case with words separated by underscores.
      • Local variables -- Lower case (possibly with underscore between words) or bumpy caps with initial lower or your choice.
  • No declaration or data type definition is needed/used.
  • Block
    • Python represents block structure and nested block structure with indentation, not with begin and end brackets
    • The statements which go together must have the same indentation. Each such set of statements is called a block.
    • The empty block -- Use the pass no-op statement.
  • DocStrings : A doc string is a quoted string at the beginning of a module, function, class, or method.We can use triple-quoting to create doc strings that span multiple lines.
    • Doc strings can be viewed with several tools, e.g. help(),obj.__doc__, and, in IPython, a question mark (?) after a name will produce help.
  • Statement
    • while running:
          guess = int(raw_input('Enter an integer : '))
          if guess == number:
             print 'Congratulations, you guessed it.'
             running = False # this causes the while loop to stop
          elif guess < number:
             print 'No, it is a little higher than that.'
             continue

          else:
             print 'No, it is a little lower than that.'
             break

      else:
          print 'The while loop is over.'
      # Do anything else you want to do here
      print 'Done'
    • for i in range(1, 5):
         print i
      else:
         print 'The for loop is over'

Python Development with Eclipse

  1. extract Eclipse : eclipse-java-indigo-win32_32bit.zip
  2. Install PyDev plugin for Eclipse
    1. Help/Install New Software
    2. Add Repository : PyDev - http://pydev.org/updates
    3. select [PyDev] => [Next]/[Next]/Accept license/[Finish] => select trust certificate/[OK]
    4. Restart Eclipse
  3. Configuration PyDev
    1. Window/Preferences
    2. Select PyDev/Interpreter - Python => press [Auto Config] (ps. precondition : python installed) => [OK]
    1. Install UML modeling for phthon Feature (Using TextUML Toolkit + Acceleo)
      1. Install TextUML Toolkit
        1. Help/Install New Software
        2. Add Repository : TextUML Toolkit - http://abstratt.com/update/
        3. select All => [Next]/[Next]/Accept license/[Finish]
      2. Install Acceleo code generator – http://acceleo.org/update/
        1. Help/Install New Software
        2. Add Repository : Acceleo code generator – http://acceleo.org/update/
        3. select Acceleo => [Next]/[Next]/Accept license/[Finish]
      3. Install Acceleo code generation modules
          1. Help/Install New Software
          2. Add Repository : Acceleo code generation modules - http://acceleo.org/modules/update
          3. select Acceleo Modules Experimental/Ecore to Python code generator => [Next]/[Next]/Accept license/[Finish]
    2. Use PyDev to develop python
      1. Window/Open Perspective/Other => select PyDev/[OK]
      2. File/New/PyDev Project
      3. Project name : scm_build, Grammer version : 2.6 => [Finish]
    3. Create Python UML
      1. New/Other => Acceleo/Module Luncher [Next] Encore to Python => [Next]
      2. Encore Model : /scm_build/module/scm_build.ecore
        Output folder : /scm_build/out
        Error Log file : /scm_build/error.log

    [Solved]Can't connect BoxNet Dav network drive in Windows XP

    1. Start up WebClient service in Windows Service
    2. connect net drive by file://www.box.net/dav