Locating an image file in a pyGame I am writing a simple game with pyGame.

Structure-wise, I have separated my game into several files:


main.py # the main runner, it loads up the environment
class_tank.py # it defines the player-controlled tank class
class_shell.py # it defines the shells that shoot from the player's tank
class_mob.py # it defines the enemies


The relationship of the modules above is:


main.py imports class_tank.py, class_shell.py and class_mob.py
all of class_tank.py, class_shell.py and class_mob.py are subclasses of pygame.Sprite.sprite. 


Currently, I noticed that I am repeating myself by having the following code snippets in all four files:

current_path = os.path.dirname(os.path.realpath(__file__))
resource_path = os.path.join(current_path, 'Resources')
img_folder_path = os.path.join(resource_path, 'Images')
bg_img_path = os.path.join(img_folder_path, "xxxx.png")


xxxx.png is the image I need to load for the background (main.py), for the player (class_tank.py), for bullets (class_shell.py) and for enemies (class_mob.py).

Logically, this code snippet does belong to each of the file, but is there any elegant way to not repeat myself? The only way I can think of is to define an additional helper class.
You don't necessarily need classes in Python. The helper class approach is the same direction as I would go, just with a plain module.
Basically, your resource_path and img_folder_path are constants, so I would simply create a module constants.py with the following:

import os

RESOURCE_PATH = os.path.join(os.path.realpath(__file__), 'Resources')
IMG_FOLDER_PATH = os.path.join(resource_path, 'Images')


You can then simply import constants.py everywhere you need to know those paths.