How to Write Python programs better and faster

Source: Internet
Author: User
Tags plone

The following is a valuable suggestion for programming learners who have never learned programming or are not a computer professional. Writing Python programs is one of the best choices, it is recommended that beginners learn programming from Python first.

The most intermediate part is about unittest settings. First, set the python file compiler to pyunit. Article 2 set the make operation of the python file to execute a command such as python./alltests. py.

In the command mode of VIM, type: make press enter to test the entire module. If you prefer Gvim, you can also click the make shortcut button on the toolbar to perform this operation. Article 3 name it test *. the make operation of The py file is set to only execute the test file, so that when we write a specific test program, we do not need to run all the test code every time.

In the above settings, writing the last few lines of the Python program ensures that when I write a new file, Vim will automatically select a template file for me based on the file name, in this way, I need to enter less code. You can download the complete one I used.

The vimrc file also contains the template files used in the previous configuration: skeleton. py, test. py, and alltests. py. The above settings are all used in my own Linux, and all the path names are in Linux/Unix format. If necessary, you can use the Windows path name to replace them, for example:

 
 
  1. autocmd FileType python setlocal makeprg=\"C:\\Program\ Files\\Plone 2\\Python\\python\"\ ./alltests.py  
  2. autocmd BufNewFile,BufRead test*.py setlocal makeprg=\"C:\\Program\ Files\\Plone 2\\Python\\python\"\ % 

Add the full path to the Python to be called. It should be noted that any space in this area should appear in the form of escape, that is, the front should be added with a backslash \; other special characters should also be escaped accordingly, for example, the Windows style path separator \ and double quotation marks (if the file name and path to be used in Windows contain spaces, remember to enclose them with double quotation marks ).

Note: I have found that the command line for compiling Python program operations and calling in Vim 6.1 is incorrect. It cannot capture all the output of the program, and the output of PyUnit is also affected by this bug. We recommend that you use the latest version of Vim. For example, this bug has been fixed in 6.3.

[BOTTOM] [TOP] Code is automatically completed. In addition, I also use [WWW] pydiction, which is a pretty good script automatically completed by Python code. To use this function, I put it in ~ /. Vim/tools directory, and add the following settings in. vimrc:

 
 
  1. "Python auto-complete code
  2. "Typing the following (in insert mode ):
  3. "OS. lis<Ctrl-n> 
  4. "Will expand:
  5. "OS. listdir (
  6. "Python auto-completion function, just re-press Ctrl-N.
  7. If has ("autocmd ")
  8. Autocmd FileType python set complete + = k ~ /. Vim/tools/pydiction
  9. Endif
  1. How to embed Python into C ++ applications?
  2. In-depth discussion of Ruby and Python syntax comparison
  3. Introduction to Python
  4. Python Learning Experience: version, IDE selection and coding Solutions
  5. Analysis of Python GIL and thread security

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.