When something goes wrong with your code instead of using standard debugging techniques such as print statements use debugging tools. I found two great tools for debugging.
1.using code module: This is very useful if your code working with out errors but dint give expected result.The code module has a function interact() which stops the program execution and opens a interactive python console that inherits the local scope of the line where the interact() method is called. In that console you can print variable values(instead of placing print statements in your code),examine the state of your code and fix the bug. Place the following line in your code where you want console to start.
import code code.interact(local=locals())
To exit the interactive console and continue with execution use Ctrl+D or Ctrl+Z or exit(). Lets have a look at following example.
#file: inc.py def testing(): print 'before interact' a=10 b=20 c=a+b import code; code.interact(local=locals()) print 'after interact' testing()
The output is shown below:
ramya@ramya-ws:~/Desktop$ python inc.py before interact Python 2.7.4 (default, Sep 26 2013, 03:20:26) [GCC 4.7.3] on linux2 Type 'help', 'copyright', 'credits' or 'license' for more information. (InteractiveConsole) >>> print c 30 >>> print a 10 >>> print b 20 >>> after interact ramya@ramya-ws:~/Desktop$
Micropyramid is a software development and cloud consulting partner for enterprise businesses across the world. We work on python, Django, Salesforce, Angular, Reactjs, React Native, MySQL, PostgreSQL, Docker, Linux, Ansible, git, amazon web services. We are Amazon and salesforce consulting partner with 5 years of cloud architect experience. We develop e-commerce, retail, banking, machine learning, CMS, CRM web and mobile applications.
Django-CRM :Customer relationship management based on Django
Django-blog-it : django blog with complete customization and ready to use with one click installer Edit
Django-webpacker : A django compressor tool
Django-MFA : Multi Factor Authentication
Docker-box : Web Interface to manage full blown docker containers and imagesMore...