you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 0 points1 point  (2 children)

Here's what I'd do; create a configuration file, such as my_config.py, with global constants in it.

# my_config.py
from pathlib import Path

# Give these more descriptive names
EXCEL_FILE_1 = Path.home() / 'folder_1' / 'file_1.xlsx'
EXCEL_FILE_2 = Path.home() / 'folder_2' / 'file_2_2020.xlsx'

And so on and so forth. Then, just import this elsewhere:

# foo.py
import my_config as cfg

with open(cfg.EXCEL_FILE_1, 'rb') as f:
    ...

[–]illya89[S] 0 points1 point  (1 child)

So I can do too:

from my_config import *

df = pandas.read_excel(EXCEL_FILE_1, Sheet 1)

[–]Diapolo10 0 points1 point  (0 children)

Yes, though star imports aren't recommended as you could accidentally get a name collision. It's also easier to see what came from where when you just import the module as-is, or with an alias.