Skip to content

Commit

Permalink
Update load_data_.py to use pkutil
Browse files Browse the repository at this point in the history
  • Loading branch information
marcharper authored Mar 8, 2024
1 parent 36464a7 commit 8a35b30
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions axelrod/load_data_.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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"):
Expand Down

0 comments on commit 8a35b30

Please sign in to comment.