# The idea of the with statement is to scope your resource and make clean up
# operations on its destruction. In this case, we're operating with file
# descriptor. Sure it's more interesting for writing files, but this example
# is good enough to demonstrate main ideas of with statement.
with open('list.json', 'r') as f:
data = f.read()
lines = data.split('\n')
print "Total symbols: {symbols}\nTotal lines: {lines}".format(
symbols=len(data),
lines=len(lines)
)
[
[
{
"filename": "000.00-38-parrots.html",
"attr": {
"data-background": "media/38-popugaev-large-5.jpg"
}
},
{
"filename": "001.00-why-python.html",
"attr": {
"data-background": "media/011-monty-python-flying-circus-theredlist.jpg"
}
},
"002.00-why-did-you-heard-about-python.html",
"003.00-why-its-so-populat.html",
{
"filename": "004.00-languages-statistics.html",
"attr": {
"data-background": "media/languags-2015.png"
}
},
"004.01-languages-statistics.html"
],
[
{
"filename": "005.00-interpreters.html",
"attr": {
"data-background": "media/l-interprete-de-sydney-pollack-2005.jpg"
}
},
"005.01-cpython-interpreter.html",
"005.02-cpython-interpreter.html",
"005.03-ipython-interpreter.html",
"005.04-ipython-interpreter.html",
"005.05-bpython-interpreter.html",
"005.06-bpython-interpreter.html"
],
[
{
"filename": "006.00-variables.html",
"attr": {
"data-background": "media/shutterstock_100409059.jpg"
}
},
"006.01-identifiers.html",
"006.02-reserved-identifiers.html",
"006.03-variables.html"
],
[
{
"filename": "007.00-data-types.html",
"attr": {
"data-background": "media/USB_types_2l.jpg"
}
},
"007.01-numeric-types.html",
"007.02-implicit-conversions.html",
"007.03-explicit-conversions.html",
{
"filename": "007.04-string-type.html",
"attr": {
"data-background": "media/string-type.jpg"
}
},
"007.05-string-definition.html",
"007.06-string-operations.html",
"007.07-strings-immutability.html",
{
"filename": "007.08-native-data-structures.html",
"attr": {
"data-background": "media/native-data-structures.jpg"
}
},
"007.09-list-definition.html",
"007.10-list-operations.html",
"007.11-list-methods.html",
"007.12-tuple-definition.html",
"007.13-dict-definition.html",
"007.14-dict-methods.html",
"007.15-set-definition.html"
],
[
{
"filename": "008.00-scripting.html",
"attr": {
"data-background": "media/scripting.jpg"
}
},
"008.01-python-modules.html",
"008.02-import.html"
],
[
{
"filename": "009.00-blocks.html",
"attr": {
"data-background": "media/blocks.jpg"
}
},
"009.01-definition-of-block-identation.html",
{
"filename": "009.02-blocks-example.html",
"attr": {
"data-background": "media/block-definition.png",
"data-background-size": "100%"
}
},
"009.03-if-else-statement.html",
"009.04-inline-if-else-statement.html",
"009.05-for-loop-statement.html",
"009.06-for-else-statement.html",
"009.07-while-else-statement.html",
"009.08-special-instructions.html"
],
[
{
"filename": "010.00-functions.html",
"attr": {
"data-background": "media/functions.jpg"
}
},
"010.01-statement-definition.html",
"010.02-default-arguments.html",
"010.03-keyword-arguments.html",
"010.04-arguments-summary.html",
"010.05-function-inheritance.html",
"010.06-yield-generator.html",
"010.07-yield-example.html",
"010.08-yield-operation-explanation.html",
"010.09-couple-values-return.html",
"010.10-multiple-values-return-visualization.html",
"010.11-lambda.html"
],
[
{
"filename": "011.00-io.html",
"attr": {
"data-background": "media/io.jpg"
}
},
"011.01-screen-io.html",
"011.02-string-formating.html",
"011.03-string-format-method.html",
"011.04-files-io.html",
"011.05-read-write-files.html",
"011.06-with-statement.html",
{
"filename": "011.07-JSON-library.html",
"attr": {
"data-background": "media/json-lib.png",
"data-background-size": "90%"
}
}
],
[
{
"filename": "012.00-external-programs.html",
"attr": {
"data-background": "media/external-programs.jpg"
}
},
"012.01-subprocess-popen.html",
"012.02-subprocess-check-call.html",
"012.03-subprocess-check-output.html",
"012.04-subprocess-arguments.html",
"012.05-sys-argv.html",
{
"filename": "012.06-sys-argv-example.html",
"attr": {
"data-background": "media/sys-argv-example.png",
"data-background-size": "60%"
}
}
],
[
{
"filename": "013.00-classes.html",
"attr": {
"data-background": "media/classes.jpg"
}
},
{
"filename": "013.01-creating-class.html",
"attr": {
"data-background": "media/class-statement.png",
"data-background-size": "70%"
}
},
"013.02-accessing-attributes-dot.html",
"013.03-accessing-attributes-func.html",
"013.04-built-in-class-attributes.html",
"013.05-destroying-object.html",
"013.06-class-inheritance.html",
"013.07-overriding-methods.html",
"013.08-data-hiding.html"
],
[
{
"filename": "014.00-error-handling.html",
"attr": {
"data-background": "media/error-handling.jpg"
}
},
"014.01-syntax-errors.html",
"014.02-exceptions.html",
{
"filename": "014.03-try-except-else-statement.html",
"attr": {
"data-background": "media/try-except-else.png",
"data-background-size": "70%"
}
},
"014.04-try-finally-statement.html"
],
[
{
"filename": "017.00-the-end.html",
"attr": {
"data-background": "media/the-end.jpg"
}
}
]
]