Converting dictionary to JSON

json.dumps() converts a dictionary to str object, not a json(dict) object! So you have to load your str into a dict to use it by using json.loads() method See json.dumps() as a save method and json.loads() as a retrieve method. This is the code sample which might help you understand it more:

Python ‘If not’ syntax [duplicate]

Yes, if bar is not None is more explicit, and thus better, assuming it is indeed what you want. That’s not always the case, there are subtle differences: if not bar: will execute if bar is any kind of zero or empty container, or False. Many people do use not bar where they really do … Read more

Cannot find module cv2 when using OpenCV

I have installed OpenCV on the Occidentalis operating system (a variant of Raspbian) on a Raspberry Pi, using jayrambhia’s script found here. It installed version 2.4.5. When I try import cv2 in a Python program, I get the following message: The file cv2.so is stored in /usr/local/lib/python2.7/site-packages/… There are also folders in /usr/local/lib called python3.2 … Read more

Cannot find module cv2 when using OpenCV

First do run these commands inside Terminal/CMD: Then the issue for the instruction below will be resolved For windows if you have anaconda installed, you can simply do or if you are on linux you can do : or Link1 Link2 For python3.5+ check these links : Link3 , Link4 Update:if you use anaconda, you may simply use this … Read more

TypeError: ‘int’ object is not callable

Somewhere else in your code you have something that looks like this: Then when you write that is interpreted as meaning a function call on the object bound to round, which is an int. And that fails. The problem is whatever code binds an int to the name round. Find that and remove it.

Pip freeze vs. pip list

When you are using a virtualenv, you can specify a requirements.txt file to install all the dependencies. A typical usage: The packages need to be in a specific format for pip to understand, which is That is the “requirements format”. Here, django==1.4.2 implies install django version 1.4.2 (even though the latest is 1.6.x). If you … Read more

working of \n in python [duplicate]

There are two functions that give an object’s string representation, repr() and str(). The former is designed to convert the object to as-code string, while the latter gives user-friendly string. When you input the variable name in the command line, repr() is used, and \n character is shown as \n (as-code). When you use print, … Read more