Return correct path if windows or linux I have been trying to code something simple where I call a class with different functions to different paths,
if I call etc:
from lib.utils import GetAllPaths

path = GetAllPaths()
path.test()

with following code:
class GetAllPaths:
    &quot;&quot;&quot;
    Return file and paths directions
    &quot;&quot;&quot;

    if platform == &quot;win32&quot;:

        def test(self):
            return &quot;C:\\Users\\test.py&quot;

        def test2(self):
            return &quot;C:\\Users\\test2.py&quot;

        def test_flag(self):
            # new_manual_url.flag
            return &quot;C:\\Users\\*test.flag&quot;

        def kill_flag(self):
            # kill_*.txt
            return &quot;C:\\Users\\*kill_*.flag&quot;

        def restart(self):
            # start_*.txt
            return &quot;C:\\Users\\*start_*.flag&quot;

    elif platform == &quot;linux&quot; or platform == &quot;linux2&quot;:

        def test(self):
            return &quot;/home/test.py&quot;

        def test2(self):
            return &quot;/home/test2.py&quot;

        def test_flag(self):
            return &quot;/home/*test.flag&quot;

        def kill_flag(self):
            return &quot;/home/*kill_*.flag&quot;

        def restart(self):
            return &quot;/home/*start_*.flag&quot;

My problem here is that I run sometimes my code through Linux and sometimes through Windows, so I have created a if else statement if the script is ran through Linux or Windows,
however I do see huge potential to short this code by alot but I don't know how to apply it where I can choose etc if its linux then use the correct path of &quot;test&quot; for linux or if its windows then use the correct path of &quot;test&quot; for windows
I think you can lean on a class-variable to create your base paths, and then define the functions to use that variable:
import os
from sys import platform

class GetAllPaths:
    &quot;&quot;&quot;
    Return file and paths directions
    &quot;&quot;&quot;

    if platform == &quot;win32&quot;:
        root = 'C:\\Users'
    elif platform == 'linux':
        root = '/home'
    else:
        # Probably raise an exception here
        raise Exception(f&quot;Platform {platform} not supported&quot;)

    def test(self):
        return os.path.join(self.root, &quot;test.py&quot;)

    def test2(self):
        return os.path.join(self.root, &quot;test2.py&quot;)

    def test_flag(self):
        # new_manual_url.flag
        return os.path.join(self.root, &quot;*test.flag&quot;)

    def kill_flag(self):
        # kill_*.txt
        return os.path.join(self.root, &quot;*kill_*.flag&quot;)

    def restart(self):
        # start_*.txt
        return os.path.join(self.root, &quot;*start_*.flag&quot;)

Furthermore, you'll notice that I'm using os.path.join, this way you don't have to worry about hard-coding the path separators.
Even more DRY would be to use a decorator on each of these functions which cuts down on repeated code:
import os
from functools import wraps
from sys import platform


class GetAllPaths:
    if platform == &quot;win32&quot;:
        root = 'C:\\Users'
    elif platform == 'linux':
        root = '/home'
    else:
        # Probably raise an exception here
        raise Exception(f&quot;Platform {platform} not supported&quot;)

    def _add_platform(f):
        @wraps(f)
        def wrapper(self):
            path = f(self)
            return os.path.join(self.root, path)
        return wrapper

    
    @_add_platform
    def test(self):
        return &quot;test.py&quot;

    
    @_add_platform
    def test2(self):
        return &quot;test2.py&quot;


    @_add_platform
    def test_flag(self):
        # new_manual_url.flag
        return &quot;*test.flag&quot;


    @_add_platform
    def kill_flag(self):
        # kill_*.txt
        return &quot;*kill_*.flag&quot;


    @_add_platform
    def restart(self):
        # start_*.txt
        return &quot;*start_*.flag&quot;

Ditch the class
Realistically, you don't need the class here. You can identify this by looking at how your functions are utilized. There's not any class or instance specific information being passed to your functions (decorator notwithstanding). This means that your class and a module are fairly indistinguishable. To see this without a class, you might put all of this code into a new file, say get_all_paths.py:
# get_all_paths.py
import os
from functools import wraps
from sys import platform


if platform == &quot;win32&quot;:
    root = 'C:\\Users'
elif platform == 'linux':
    root = '/home'
else:
    # Probably raise an exception here
    raise Exception(f&quot;Platform {platform} not supported&quot;)


def add_platform(f):
    @wraps(f)
    def wrapper(*args, **kwargs):
        path = f(*args, **kwargs)
        return os.path.join(root, path)
    return wrapper


@add_platform
def test():
    return &quot;test.py&quot;


@add_platform
def test2():
    return &quot;test2.py&quot;


@add_platform
def test_flag():
    # new_manual_url.flag
    return &quot;*test.flag&quot;


@add_platform
def kill_flag():
    # kill_*.txt
    return &quot;*kill_*.flag&quot;


@add_platform
def restart():
    # start_*.txt
    return &quot;*start_*.flag&quot;


Where now, you can use your functions through a global import:
import get_all_paths as g

g.test()
'/home/test.py'
```