Skip to content

Commit a50cff0

Browse files
authored
Merge pull request #98 from ManualForArchipelago/csv-helper
Helper function for loading a csv file. People might find this useful for hooks
2 parents a73fb4b + 806dc4a commit a50cff0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Helpers.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import csv
12
import os
23
import pkgutil
34
import json
45

5-
from BaseClasses import MultiWorld, Item, Location
6+
from BaseClasses import MultiWorld, Item
67
from typing import Optional, List, TYPE_CHECKING
78
from worlds.AutoWorld import World
89
from .hooks.Helpers import before_is_category_enabled, before_is_item_enabled, before_is_location_enabled
@@ -24,6 +25,17 @@ def load_data_file(*args) -> dict:
2425

2526
return filedata
2627

28+
def load_data_csv(*args) -> list[dict]:
29+
fname = os.path.join("data", *args)
30+
31+
try:
32+
lines = pkgutil.get_data(__name__, fname).decode().splitlines()
33+
except:
34+
lines = []
35+
filedata = list(csv.DictReader(lines))
36+
37+
return filedata
38+
2739
def is_option_enabled(multiworld: MultiWorld, player: int, name: str) -> bool:
2840
return get_option_value(multiworld, player, name) > 0
2941

0 commit comments

Comments
 (0)