1# Basic syntax:
2import glob # Package for Unix-style pathname pattern expansion
3import os # Python operating system interface
4
5directory = '/path/to/directory/with/files/'
6# Obtain list of filenames that end in .txt in the directory
7all_files = glob.glob(os.path.join(directory, "*.txt"))
8# Where os.path.join creates the os-specific path to each file
9
10# Import data however you like. To append data in a single pandas
11# dataframe and a single list, you can do:
12your_list = [ ]
13for filename in all_files:
14 dataframe = pd.read_csv(filename, index_col=None, header=0, sep="\t")
15 your_list.append(dataframe)
1from inspect import isclass
2from pkgutil import iter_modules
3from pathlib import Path
4from importlib import import_module
5
6# iterate through the modules in the current package
7package_dir = Path(__file__).resolve().parent
8for (_, module_name, _) in iter_modules([package_dir]):
9
10 # import the module and iterate through its attributes
11 module = import_module(f"{__name__}.{module_name}")
12 for attribute_name in dir(module):
13 attribute = getattr(module, attribute_name)
14
15 if isclass(attribute):
16 # Add the class to this package's variables
17 globals()[attribute_name] = attribute
18