Reading code

You can learn a lot from reading other people’s code. Take a look at the code for carbon_calculator.py: https://github.com/lucydot/scripts/blob/master/bitsbobs/carbon_calculator.py.

You will recognise some of the Python syntax used, other parts you may not recognise (though we will cover this syntax by the end of the course).

a) Using the internet (Python documentation, stack overflow, tutorials) can you unpick what the function read_file does? Could explain this to a non-expert?

b) When this script is run from the command line, the function carbon_calculator is called. Using the internet can you unpick what this function does (and so what the programme does as a whole)? Could you explain this to a non-expert?

c) Can you suggest ways in which the carbon_calculator.py programme might be improved?


Back to Python part one.