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

Add forgotten encode #1763

Merged
merged 4 commits into from
Dec 5, 2017
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
9 changes: 4 additions & 5 deletions gensim/scripts/segment_wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ def segment_and_write_all_articles(file_path, output_file, min_article_character
Number of parallel workers, max(1, multiprocessing.cpu_count() - 1) if None.

"""
if output_file is not None:
if output_file is None:
outfile = getattr(sys.stdout, 'buffer', sys.stdout) # we want write bytes, so for py3 we used 'buffer'
else:
outfile = smart_open(output_file, 'wb')

try:
Expand All @@ -120,10 +122,7 @@ def segment_and_write_all_articles(file_path, output_file, min_article_character
output_data["section_texts"].append(section_content)
if (idx + 1) % 100000 == 0:
logger.info("processed #%d articles (at %r now)", idx + 1, article_title)
if output_file is None:
sys.stdout.write(json.dumps(output_data) + "\n")
else:
outfile.write((json.dumps(output_data) + "\n").encode())
outfile.write((json.dumps(output_data) + "\n").encode('utf-8'))
finally:
if output_file is not None:
outfile.close()
Expand Down