Python Tools Utilities
Python Tools Utilities
T he standard library comes with a number of modules that can be used both as modules and as command-line utilities.
Example:
#!/usr/bin/python import dis def sum(): vara = 10 varb = 20 sum = vara + varb print "vara + varb = %d" % sum # Call dis function for the function. dis.dis(sum)
10
0 (None)
Example:
Before you try to run pdb.py, set your path properly to Python lib directory. So let us try with above example sum.py:
$pdb.py sum.py > /test/sum.py(3)<module>() -> import dis (Pdb) n > /test/sum.py(5)<module>() -> def sum(): (Pdb) n >/test/sum.py(14)<module>() -> dis.dis(sum) (Pdb) n 6 0 LOAD_CONST 3 STORE_FAST 7 9 6 LOAD_CONST 9 STORE_FAST 12 15 18 19 22 25 28 29 30 31 34 LOAD_FAST LOAD_FAST BINARY_ADD STORE_FAST LOAD_CONST LOAD_FAST BINARY_MODULO PRINT_ITEM PRINT_NEWLINE LOAD_CONST RETURN_VALUE
1 (10) 0 (vara) 2 (20) 1 (varb) 0 (vara) 1 (varb) 2 (sum) 3 ('vara + varb = %d') 2 (sum)
10
0 (None)
Example:
Let us try to profile the following prog ram:
#!/usr/bin/python vara = 10 varb = 20 sum = vara + varb print "vara + varb = %d" % sum
way that throws off indentation, no matter what tab size you're using , the nanny complains:
Example:
Let us try to profile the following prog ram:
#!/usr/bin/python vara = 10 varb = 20 sum = vara + varb print "vara + varb = %d" % sum
If you would try a correct file with tabnanny.py, then it won't complain as follows:
$tabnanny.py -v sum.py 'sum.py': Clean bill of health.