projecthowto/code/README.md

1.4 KiB

Structure of a script

  1. Initially you should specify which packages you use in the scripts
import pathlib      # Packages that are provided from python

import numpy as np  # Packages that are downloaded, specified in the requierements.txt

import myscript     # Scripts from your Project/Pipeline
  1. Next your code for the specific problem that you are trying to solve, all written code should be containded in a function/classes It should contain a main function with is calling all individual function to solve the problem.
def load_data(path):
  with open(path, "r") as f:
    f.read()
  return f

def main(path):
  load_data(path)
  1. If the script is a standalone script, it can be run by calling python myscript.py it should contain...
if __name__ == "__main__":
  path = "../data/README.md"
  main(path)

Tips and tricks

  • Plotting scripts should be named the same as the output figure for easier backtracking
  • Plotting scripts should start with plot, so that one can create a bash script for that executes all plot* scripts
  • If you use a directory for managing specific task, in python it is called a module, you neeed a init.py file in the directory more in packagehowto

Naming conventions

  • Use snake_case for functions and variables

Documentation

  • Use docstrings for all functions and classes