Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and Optimization:: constants.py #264

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,25 @@

imported_regex = re.compile('^\s*\$import\s*(?P<extension>.*)\s*::\s*(?P<instruction>.*)', re.M)

causes = []
with open("causes.csv") as f:
csv_reader = csv.reader(f, skipinitialspace=True)
for row in csv_reader:
causes.append((int(row[0], 0), row[1]))
csrs = []
with open("csrs.csv") as f:
csv_reader = csv.reader(f, skipinitialspace=True)
for row in csv_reader:
csrs.append((int(row[0], 0), row[1]))
csrs32 = []
with open("csrs32.csv") as f:
csv_reader = csv.reader(f, skipinitialspace=True)
for row in csv_reader:
csrs32.append((int(row[0], 0), row[1]))
def read_csv(filename):
"""
Reads a CSV file and returns a list of tuples.
Each tuple contains an integer value (from the first column) and a string (from the second column).

Args:
filename (str): The name of the CSV file to read.

Returns:
list of tuple: A list of (int, str) tuples extracted from the CSV file.
"""
with open(filename) as f:
csv_reader = csv.reader(f, skipinitialspace=True)
return [(int(row[0], 0), row[1]) for row in csv_reader]

causes = read_csv("causes.csv")
csrs = read_csv("csrs.csv")
csrs32 = read_csv("csrs32.csv")

arg_lut = {}
with open("arg_lut.csv") as f:
csv_reader = csv.reader(f, skipinitialspace=True)
Expand Down
Loading