Fix main.py to correctly build JSON from english/german files#411
Open
kunghun-jeong wants to merge 1 commit intoagwaBom:mainfrom
Open
Fix main.py to correctly build JSON from english/german files#411kunghun-jeong wants to merge 1 commit intoagwaBom:mainfrom
kunghun-jeong wants to merge 1 commit intoagwaBom:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
a) What line of code you changed
path_to_file_list (around line 5–10):
open(path, 'w')andreturn linesto reading the file in 'r' mode and returning
a list of lines without newline characters.
train_file_list_to_json (around line 15–30):
and now use
json.dumps({"English": en, "German": de}, ensure_ascii=False)to generate valid JSON strings.
write_file_list (around line 30–40):
to opening in 'w' mode and writing each element of file_list
followed by '\n'.
main (around line 40+):
read by
path_to_file_list, and then passed intotrain_file_list_to_json, and the result is writtento
concated.jsonusingwrite_file_list.b) Why it is a wrong code
path_to_file_list opened the file in write mode and never read it,
returning an undefined variable
lines, so it could not work asa function that “reads a file and returns a list of lines”.
train_file_list_to_json did not produce valid JSON format and also
used only "German" as a key in the template, which does not match
the required {"English": "...", "German": "..."} structure.
write_file_list opened the output file in read mode and wrote only
newline characters, so the result file did not contain any actual data.
In main, the functions were called with wrong arguments
(e.g., passing a path string into train_file_list_to_json) so the
script could not correctly read input files and build concated.json.