diff --git a/axelrod/load_data_.py b/axelrod/load_data_.py index eff61a564..45107b50a 100644 --- a/axelrod/load_data_.py +++ b/axelrod/load_data_.py @@ -1,12 +1,7 @@ import pathlib from typing import Dict, List, Text, Tuple -try: - # For Python >= 3.9 - from importlib import resources -except ImportError: - # Try backported to Python < 3.7 `importlib_resources`. - import importlib_resources as resources +import pkgutil def axl_filename(path: pathlib.Path) -> pathlib.Path: """Given a path under Axelrod/, return absolute filepath. @@ -29,13 +24,7 @@ def load_file(filename: str, directory: str) -> List[List[str]]: """Loads a data file stored in the Axelrod library's data subdirectory, likely for parameters for a strategy.""" - try: - path = (resources.files(directory) / filename) - with path.open("r") as f: - data = f.read() - except AttributeError: - # Python < 3.9, fall back to method deprecated in 3.11. - data = resources.read_text(directory, filename) + data = pkgutil.get_data(__name__, directory / filename) rows = [] for line in data.split("\n"):