How many times have you been stuck in a situation where you have to change someone else's code? If you're part of a development team, you're more than you want to be in this situation. However, Python has a neat debugging feature (like most other languages), which is handy in this case. This is a quick tutorial and hopefully it will make your coding life easier.1. A messy procedure
For the purposes of this tutorial, let's look at the following simple
DebuggerDuring software development, there is always one or more errors, including syntax and logic. For syntax errors, the python interpreter can easily detect them. In this case, it will stop running the program and give an error prompt. For logical errors, the interpreter will be overwhelmed, and the program will continue to run, but the running result will be wrong. Therefore, we often need to debug th
Programmers can write a program at a time and the probability of normal operation is very small, basically no more than 1%. There will always be a variety of bugs to fix. Some bugs are simple, look at the error message and know that some bugs are complicated, we need to know which variables are correct, and which values are wrong, so a full set of debug programs is required to fix the bug. In programming, this method is called
Python print right triangle, equi triangle, diamond, square code, python equi-edge
Triangle
Isosceles right triangle 1 2.7
# Coding: utf-8rows = int (raw_input ('number of input columns: ') I = j = k = 1 # declare variable, I used to control the outer loop (number of rows in the graph ), j is used to control the number of spaces, k is used to control the number o
Use the commands in the PDB module in Python to debug the Python code tutorial, pythonpdb
How many times have you had to change others' code? If you are a member of a development team, you may encounter more times than you want. However, Python has a neat debugging feature (like most other languages), which is very con
This article discusses how to use PDB to debug Python without convenient ide tools. Program Source code example For example, there is a program to simulate tax calculation :#! /Usr/bin/Python Def debug_demo (VAL ): If Val Print "Level 1"Print 0Elif Val
; import pdb>>> import testPdb>>> pdb.run('testPdb.test()')
Insert a program into the code
It is commonly used to insert a program in the middle of the program. compared to hitting a breakpoint in the general IDE and then starting debug, this method ishardcodeOf
if __name__ == "__main__": a = 1 import pdb pdb.set_trace() b = 2 c = a + b print(c)
Then run the script normally:python testPdb.pyArrivedpdb.se
This article mainly introduces the use of PDB modules to debug Python program instances, this article focuses on the Pdb.run () function, Pdb.runeval () function, Pdb.runcall () function, Pdb.set_trace () The use of functions and the PDB debugging commands and so on content, the need for friends can refer to the following
In Python, syntax errors can be found by
():Pdb. set_trace ()For I in range (1, 5 ):Print I# N p c is supported here(Pdb) nThe IDE built by pydev + eclipse cannot enter the single-step debugging status debug as --> python run does not stay at the breakpoint, nor jump into debug
It's so professional that I have never played it.Also, I am very surprised, does
, and only the result of all true,and operations is True.An OR operation is an operation, as long as one of the true,or operation results is True.The not operation is a non-operation, which is a single-mesh operator that turns true to False,false to true.Five, null valueThe null value is a special value in Python, denoted by none. None cannot be understood as 0, because 0 is meaningful, and none is a special null value.The
and try again:import logginglogging.basicConfig(level=logging.INFO)See the output:call last): File "err.py", line 8, in module> print 10 / nZeroDivisionError: integer division or modulo by zeroThis is logging the benefit that allows you to specify the level of logging information, there,, and debug info so on warning error several levels, when we specify level=INFO , it logging.debug will not work. Simila
Python basics-for Loop (use for loop to print 9-9 multiplication tables of different formats), python --
# Square output 9-9 multiplication table for I in range (): for j in range ):# % 2d is used to place the result of multiplication in two places. The output result is more elegant. After all, some results are single digits, and some are ten digits, reserved spa
Python _ does not need to print 1-1000 cyclically, and python prints 1-1000Question: I can print the 1000 numbers from 1 to on the screen. Do not use cyclic or conditional statements. Do not use them? : Operator. You are not allowed to use the method of listing output statements in the source code. For example, if you
Don't say a word, just cut to the chase.The print statement can output the specified text to the screen. For example, the output of ' Hello, world ', implemented in code as follows:>>> print ' Hello, world 'Attention:1. When we write code in a python interactive environment,,>>> is the prompt for the Python interpreter
Basic Python tutorial 2-3: print a sentence in the "box" with the correct width. Basic python tutorial
Sample Code:# Obtain the sentence lengthSentence = input ('plese input a sentence: ') # He's very naughty boyScreen_width = 100# Getting the length of TextText_width = len (sentence)# Text widthBox_width = text_width + 10# Calculate the number of free formats on
Python Linux debugging
Python is a dynamic language, and the compiler does not check the runtime syntax. These low-level problems often result in low debugging efficiency. Previously, debugging on Linux servers was done through print and error reporting. Python's built-in PDB is a powerful tool for debugging.
Let's create a new test Script: shell code.
Touc
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.