1. InstallationPython3 version directly performs pip install ipdb command installationpython2.7 version needs to specify the version of IPDBPip Install ipdb==0.10.2After the equals sign is the version, because the PIP install ipdb is the latest version installed by default, now the IPDB needs Python3 supportSo python2.
Tags: mes Microsoft stdout enters HTTP targe nbsp not function pdb/ipdb modules /pdb/ipdb module The main role of PDB and IPDB is for single-step debugging of Python programs, and Python debugging can refer to links. Here is a simple example of using 1 Import ipdb
2
3 i = 0
4 while i:
5 Print (i)
6
Install sudo pip install ipdb
use the first method python-m ipdb xxx.py Step into the second method of inserting two sentences where a breakpoint is needed
From ipdb import set_trace
set_trace ()1 2
1 2 after running the program, it will interrupt the program at the time of execution to Set_trace () and a prompt ipdb
1. InstallationPip Install ipdb1. functionPython-m ipdb xxx.pyInside the program:From ipdb ImportSet_trace Set_trace ()3. Common commands
ENTER(Repeat Last command)
cContinue to
l(Find where it is currently located)
s(Go to subroutine)
r(run until subroutine ends)
!
hHelp
A (RGS) prints the parameters of the current function
J (UMP) lets the program jump to the specified number
Tags: ipdb==>InstallationPip Install ipdb==> Use---> python-m ipdb xxx.pyInside the program:From ipdb import Set_traceset_trace ()Enter (repeat last command) C (continue) L (find where it is currently) s (go to subroutine) R (run until subroutine ends)! Debugging a Python program with
Tags: python pdb trace debugPoetry is a melancholy medium, and the poet's mission is lonely;--North "The Rose of Time"Learning is a deep ballad, and our task is to enjoy him. --Little Q "20161203"------------------------------------------------------------------------------------------------Learn C + +, the teacher taught us to have GDB debugging tools, in the work will often use;When learning the shell, the manager let me see the "-X" Tracking debugging parameters, I use every day;After learnin
def test_long_call(): s = Sweetness() with patch.object(s, "slow_remote_call", return_value="some_data"): result = s.slow_remote_call() assert result == "some_data"
Okay, let's try again:
(test)jhaddad@jons-mac-pro ~VIRTUAL_ENV/src$ nosetests test_mock.py .----------------------------------------------------------------------Ran 1 test in 0.001s OK
Much better. Remember, this example has been simply simplified. In my personal opin
): SLE EP (Ten) return "Some_data" # Lets pretend we get this back from our remote API call Def test_long_call (): s = Sweet Ness () with Patch.object (S, "Slow_remote_call", return_value= "Some_data"): result = S.slow_remote_call () assert result = = "Some_data"
OK, let's try it again:
(test) Jhaddad@jons-mac-pro ~virtual_env/src$ nosetests test_mock.py .---------------------------------------- -----------------------------
where an exception occurs, while keeping the stack and variables intact.
Conclusion: it has the best user experience in the debugger and is particularly useful for Stack tracing.
Ipdb
The last one is ipdb in iPython. Like its * pdb brothers, its interface is a simple command line and its help system is worth further research. What makes this product different is that it uses an iPython shell, so all the t
(OS. popen ("/usr/bin/curl http://ip.taobao.com/service/getIpInfo.php? Ip = % s "% ip). readline () ['data']'''Conn = httplib. HTTPConnection ('IP .taobao.com ')Def getIpCountry (ip ):Conn. request ('GET', '/service/getIpInfo. php? Ip = % s' % ip)R1 = conn. getresponse ()If r1.status = 200:Return json. loads (r1.read () ['data']Else:Return "Error"# Analyze the access. log file and convert it to a python arrayFile. write (u "field description: ip access times data ip country City isp number prov
.taobao.com ')Def getIpCountry (ip ):Conn. request ('get', '/service/getIpInfo. php? Ip = % s' % ip)R1 = conn. getresponse ()If r1.status = 200:Return json. loads (r1.read () ['data']Else:Return "Error"# Analyze the access. log File and convert it to a python ArrayFile. write (u "field Description: ip access times data ip country city isp number province region \ n ")IpDb = []For I in cmd ('''/usr/bin/awk '{print $1}' % s | sort | uniq-c ''' % LogFil
takes a certain amount of time, then that's a good thing.Pip install nose-progressive and add--with-progressive to your nosetestsDebugging
Ipdb is a great tool and I've used it to find out a lot of weird bugs. Pip Install ipdb Install the tool, and then import ipdb in your code; Ipdb.set_trace (), and then you'll get a good interactive tip when your program is
The remote debugging Python program primarily uses logging and PDB for debugging. On the one hand there is no permission to install IPDB, on the other hand it cannot be debugged locally.
How to useThe PDB is a module that comes with Python, so no additional installation is required. If you need more advanced debugging, you can try IPDB. Insert a breakpoint where you want to debug:import pdb;pdb.set_trace()
):Conn.request (' GET ', '/service/getipinfo.php?ip=%s '% IP)R1=conn.getresponse ()if R1.status = = 200:Return Json.loads (R1.read ()) [' Data ']ElseReturn "Error"#将access. log file for analysis and to Python arrayFile.write (U "field Description: IP access times according to IP country city's ISP number province area \ n")Ipdb=[]For i in cmd ('/usr/bin/awk ' {print $} '%s |sort |uniq-c "% LogFile):ip = I.strip (). Split (")Ipdb.append (IP)#通过taobao p
create a virtual environment
mkvirtualenv [Virtual Environment name]View the current virtual environment directory
WorkonSwitching Virtual Environments
Workon [Virtual Environment name]Exit Virtual Environment
DeactivateDelete (Use caution)
rmvirtualenv [Virtual Environment name]
Python version 2 development
Creating a Python2 Virtual development environment
Mkvirtualenv-p/usr/bin/python2.7 py2
Use the python2.7+django1.7.8 environment, you should install the follo
and you can use it to track the program remotely.
A better debugger
Direct substitution of PDB:
IPDB (Easy_install ipdb) – Similar to Ipython (with auto-complete, display color, etc.)
Pudb (Easy_install pudb) – based on curses (similar GUI interface), ideal for browsing source code
Remote Debugger
Installation method:
sudo apt-get install winpdb
Replace the previous pdb.set_trace () in the following way:
I
First, using the PDB http://blog.csdn.net/wyb_009/article/details/8896744Second, using GDBTo configure GDB Pythin support First, the following steps are required:1, modify the Python-2.6/misc/gdbinit, will while $_i Revision changed to while $_i 2, in the document: ~/.gdbinit, add the following content SOURCE Python-2.6/misc/gdbinitDebugging methods GDB python Run true_false.pyThird, the use of ipdbInstallation method: IPDB (Easy_install
remotely track programs.
Better debugger
Direct replacement of pdb:
Ipdb (easy_install ipdb)-similar to ipython (automatic completion, display color, etc)
Pudb (easy_install pudb)-based on curses (similar to the GUI interface), especially suitable for browsing source code
Remote debugger
Installation method:
Sudo apt-get install winpdb
Replace the previous pdb. set_trace () with the following method ():
im
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.