Skip to content

Commit 258294e

Browse files
committed
Project now accepts dictionary path as command line argument
- Modified lang.py to include dictionary path as command line argument - Renamed lang.csv to template_dict.csv as a dictionary example
1 parent ded63a9 commit 258294e

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ You don't need to "install" anything special. Just make sure you have Python 3 (
2727
2. **File Input:**
2828

2929
Create a `.tpy` file containing your translatable code (e.g., `example.tpy`). Then, run the compiler with the
30-
filename as an argument:
30+
file path, and the dictionary path as command line arguments:
3131

3232
```bash
33-
python lang.py example.tpy
33+
python lang.py script.tpy dict.csv
3434
```
3535

3636
## Example
@@ -56,7 +56,7 @@ You don't need to "install" anything special. Just make sure you have Python 3 (
5656

5757
3. Run It:
5858
```bash
59-
python lang.py hello.tpy
59+
python lang.py hello.tpy dict.csv
6060
```
6161

6262
4. Output:

lang.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def get_translations() -> dict[str, str]:
5757

5858
translations: dict[str, str] = {}
5959

60-
with open('lang.csv', encoding='utf-8', newline='') as f:
60+
# second command line argument is a dictionary path
61+
with open(sys.argv[2], encoding='utf-8', newline='') as f:
6162
reader = csv.reader(f)
6263
for row in reader:
6364
translations[row[0]] = row[1]
@@ -109,7 +110,7 @@ def run_program(program: str) -> None:
109110
def main() -> None:
110111
"""Main function: handles file input."""
111112

112-
if len(sys.argv) == 1:
113+
if len(sys.argv) < 3:
113114
raise IOError('Must Provide Additional Arguments')
114115

115116
# Read code from file
@@ -123,7 +124,7 @@ def main() -> None:
123124

124125
python_program = translate_program(code)
125126

126-
if len(sys.argv) == 2:
127+
if len(sys.argv) == 3:
127128
run_program(python_program)
128129
return
129130

File renamed without changes.

0 commit comments

Comments
 (0)