Monday, December 5, 2016

Online compiler for Python


http://www.learnpython.org/en/Modules_and_Packages

Packages for Python



Check out the full list of built-in modules in the Python standard library: 

https://docs.python.org/2/library/


Source: http://www.learnpython.org/en/Modules_and_Packages

To import a module, we use the import command. 






Parsing values from Json

12/5/16

http://stackoverflow.com/questions/2835559/parsing-values-from-a-json-file-in-python


[] are for lists, {} are for dictionaries.
Here's how your JSON file should look:
{
    "maps": [
        {
            "id": "blabla",
            "iscategorical": "0"
        },
        {
            "id": "blabla",
            "iscategorical": "0"
        }
    ],
    "masks": {
        "id": "valore"
    },
    "om_points": "value",
    "parameters": {
        "id": "valore"
    }
}
Then you can use your code:
import json
from pprint import pprint

with open('data.json') as data_file:    
    data = json.load(data_file)

pprint(data)
- With data, you can now also find values like so:
data["maps"][0]["id"] ...... here [0] because maps has values in [..]. If [0] not used it will throw string - int error.
data["masks"]["id"]
data["om_points"]
 

- How I can get the number of elements in node of JSON data?




down vote
accepted
import json

json_data = json.dumps({
  "result":[
    {
      "run":[
        {
          "action":"stop"
        },
        {
          "action":"start"
        },
        {
          "action":"start"
        }
      ],
      "find": "true"
    }
  ]
})

item_dict = json.loads(json_data)
print len(item_dict['result'][0]['run'])
Convert it in dict.

Tuesday, November 29, 2016

Python installations



https://www.python.org/downloads/release/python-352/  ---- 

Windows x86-64 web-based installer


http://www.pydev.org/manual_101_install.html


https://www.python.org/downloads/release/python-352/


http://www.jetbrains.com/pycharm/download/download-thanks.html?platform=windows&code=PCC
this is the editor
first one is python (like java)
2nd one is like escaplase
editor
 


In detail:

 
- Install windows version of python interpreter from the link https://www.python.org/downloads/release/python-352/
 
- Now after Interpreter is installed, you need editor or IDE to write python scripts. For this you can use "Pycharm" or "pydev" or you could also use just putty( or command prompt).
 
 
pydev is the eclipse addin.

I normally use Pycharm but I decided to have a look at Pydev again in eclipse 4.5.2.
Wow. pydev is really good. Pycharm has lots of added value features like managing the python interpreter modules etc, but for coding and debugging pydev is good. It seems so much slicker now, good inspections, debugging, code completion.