PYTHON Learn Getting Started--eclipse installing Pydev plugins and debugging

Source: Internet
Author: User

Run the program

There are two ways to run the Python source program, taking example.py as an example:

example.py Code:

[Python]View Plaincopyprint?
  1. #!/usr/bin/env python
  2. #-*-Coding:utf-8-*-
  3. # ithomer.net
  4. A = 1
  5. def display ():
  6. print ("Hello Ithomer")
  7. Global A
  8. Print ("a =%d"% a)
  9. A = 2
  10. Print ("a =%d"% a)
  11. if __name__ = = ' __main__ ':
  12. Display ()

    • Operation Result:
    • Hello Ithomer
      A = 1
      A = 2
    • Method 1: In the Pydev package Explorer, double-click example.py, select Run as---Python Run, menu bar, run
    • Method 2: In the Pydev package Explorer, right-example.py, select Run as--Python run in the popup menu bar

Both of these methods are the basic methods of running the source program.

Code Coverage

Pydev also provides a unique run as Python coverage of the source program, which not only shows the results of the program, but also shows the code coverage during the program's run. To view the coverage of your code, you first need to open the code coverage, and in the Pydev perspective, select Windows, Show View, code coverage

In the left column of the pop-up view, you can see three buttons, "Choose folder to analyze", "Clear" and "Refresh"

Click "Choose folder to analyze" with the left mouse button, and in the pop-up folder Selection window, select the package that contains the program you want to run, and click Ok. This way, all the source programs in this package are displayed in the left column.

Next, take example.py as an example to see the results of the Run as Python Coverage feature. Select Run as, Python Coverage, which shows the results of the program running in console console. Switch to the Code Coverage Results view that you just opened, and click Example.py in the left column.

The coverage in the process of running the code is clearly displayed in the right column.

Double-click the example.py in the left column, and the code that is not covered is marked with an eye-catching error mark in the editor.

If you turn off the code coverage Results view, the overwrite information is not lost, and reopening the view can also show this information. You can clear these overwrite information after the program runs only by clicking the Clear button in the left column.

Debug program

Debugging is an essential part of the program development process, the following still take example.py as an example, describes how to use the Pydev debugging capabilities.

Debugging starts with adding breakpoints and there are three ways to set breakpoints:

    • 1) Double-click on the left gray blank Bar of the ruler bar in the editor to add a breakpoint to a line

2) Right-click on the ruler bar and select "Add Breakpoint" in the popup menu bar.
3) Move the mouse to the line of code where you want to add a breakpoint, use the shortcut key CTRL+F10, and select "Add Breakpoint" in the popup menu bar to add a breakpoint.

After adding a breakpoint, select Debug As, Python Run to start the debugger, pop up a dialog box asking if you want to switch to the debugger perspective, click Yes to display debug mode, such as:

In the process of debugging the program, a few common shortcuts are as follows:

    • Stepping into step into:f5
    • Single Step Skip step Over:f6
    • Single step back to step RETURN:F7
    • Start Resume:f8 again.

In console console, displays the execution result of the code before the breakpoint. If you want to see the value of a variable, take variable A as an example, you can manually type a line of code "a" in the console, and then press the Enter key two times, indicating the value of the variable (for example)

In debug mode, to view the value of an expression, select the right mouse button and select Watch. The expression panel pops up, showing the value of the corresponding variable or expression.

You can set the properties of a breakpoint if you want to have a breakpoint that has already been added under certain conditions to be valid. Right-click in the ruler bar of the editor and select Breakpoint Properties in the menu bar that pops up.

In the window that appears, select the check box "Enable", enter the criteria you want to meet, and click Ok.

In this way, when you re-execute the program debugging, the breakpoint is valid only if the condition is met, for example, jump directly to the condition "a = = 2"

PYTHON Learn Getting Started--eclipse installing Pydev plugins and debugging

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.