See how a minor change to your commit message style can make you a better programmer.
Format: <type>(<scope>): <subject>
<scope>
is optional
# Loading all lines of a file into memory | |
with open("large_data.txt", "r") as file: | |
lines = file.readlines() | |
for line in lines: | |
# Processing each line | |
pass |
def function(): | |
print("Start of the function") | |
try: | |
# ... main code of the function ... | |
except Exception as e: | |
print(f"Error in function: {e}") | |
def another_function(): | |
print("Start of the function") | |
try: |
# Global variables for a product | |
product_name = "Product X" | |
product_price = 100 | |
def display_product(): | |
print(f"{product_name} costs ${product_price}") | |
def apply_discount(discount): | |
global product_price | |
product_price -= discount |
# Repetitive code without functions | |
print("Processing data for client A") | |
# ... specific processing for client A ... | |
print("Saving results for client A") | |
print("Processing data for client B") | |
# ... specific processing for client B ... | |
print("Saving results for client B") |
# Calculating squares of even numbers with an imperative loop | |
numbers = [1, 2, 3, 4, 5] | |
even_squares = [] | |
for n in numbers: | |
if n % 2 == 0: | |
square = n * n | |
even_squares.append(square) |
from flask import Flask | |
from flask_sqlalchemy import SQLAlchemy | |
def create_app(config: str=None): | |
app = Flask(__name__, instance_relative_config=True) | |
if config is None: | |
app.config.from_pyfile('dev.py') | |
else: | |
logger.debug('Using %s as configuration', config) | |
app.config.from_pyfile(config) |