2. Keywords

2.1. pass

  • Avoid error when you don't specify the body of a block

Listing 94. Exceptions has all the content needed inherited from Exception class. You need something to avoid IndentationError
class MyError(Exception):


print('hello')
# IndentationError: expected an indented block
class MyError(Exception):
    pass


print('hello')
# hello

2.2. __file__

print(__file__)
# /src/my_file.py
from os.path import dirname


print(f'Working directory: {dirname(__file__)}')
# Working directory: /src
from os.path import dirname, join


path = join(dirname(__file__), 'main.py')

print(f'My file: {path}')
# My file: /src/main.py