01 Debugging and Development
Debugging to do, the easiest way is to print, if it does not work well with a printa two p (pprint), you need to import the library
From pprint import pprint
1 From pprint import pprint 2 a = (( ' x ' , ' y ' , 2), ( ' one ' , ' two ' , { ' 1 ' : 2, ' 3 ' : 4}), ( ' love ' , ' fair ' , { ' 1 ' : 2, ' 2 ' : 4}), ' joy ' , ' renewjoy ',{'1 ' : 2, ' 2 ' : 4 }) 3 print ( ' print: \ n ' , a) 4 print ( ' pprint: ' ) 5 pprint (a)
result:
1 print: 2 (('x', 'y', 2), ('one', 'two', {'1': 2, '3': 4}), ('love', 'fair', {'1': 2, '2': 4}), 'joy', 'renewjoy', {'1': 2, '2': 4}) 3 pprint: 4 (('x', 'y', 2), 5 ('one', 'two', {'1': 2, '3': 4}), 6 ('love', 'fair', {'1': 2, '2': 4}), 7 'joy', 8 'renewjoy', 9 {'1': 2, '2': 4})
Compare 02 code
Compare 2.git
git diff old.py new.py (personally do not like)
1 -print "niaho python2" 2 -print "niaho python2" 3 +print("niaho python2") 4 +print("niaho python2")
Compare 2.cdiff
pip install cdiff
diff -u old.py new.py | cdiff (feeling okay)
--- old.py 2019-06-08 10:57:14.091261538 +0800 +++ new.py 2019-06-08 10:58:32.254261665 +0800 @@ -1,2 +1,2 @@ -print "niaho python2" +print("niaho python2") -print "niaho python2" +print("niaho python2")
03 layout and formatting
1 beautify format
pip install yapf
yapf old.py old.py after> new.py # will beautify the place new.py
yapf -i old.py # use -i changes directly on the source file
2. landscaping layout
pip install isort
isort -ls old.py # directly on the source file layout beautification
04 aid
1.man manual
If you forget the sort of usage in linux, you can check the man pages man sort , you finally found the
-i file in ASCII output
2.cheat Cheat Sheet
Quite the man streamlined version of the manual, use the manual manh almost cheat sort
05 practical recommendation
1. Create a temporary server (python comes)
python3 -m http.server 6789
2. Distributed Task Queue -> celery + flower
3. Automated code release -> fabric
4. tool to monitor the process of -> supervisor