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

for python3 support #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
convert to string either to byte
  • Loading branch information
Artem Tomyuk committed Jul 31, 2017
commit 489d3ac5c2ca00adaffa570ee03c24ccf81ce984
4 changes: 2 additions & 2 deletions es2csv.py
Original file line number Diff line number Diff line change
@@ -216,7 +216,7 @@ def write_to_csv(self):
if self.num_results > 0:
self.num_results = sum(1 for line in open(self.tmp_file, 'r'))
if self.num_results > 0:
output_file = open(self.opts.output_file, 'a')
output_file = open(self.opts.output_file, 'a', encoding='utf-8')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this?

csv_writer = csv.DictWriter(output_file, fieldnames=self.csv_headers, delimiter=self.opts.delimiter)
csv_writer.writeheader()
timer = 0
@@ -234,7 +234,7 @@ def write_to_csv(self):
timer += 1
bar.update(timer)
line_as_dict = json.loads(line)
line_dict_utf8 = {k: v.encode('utf8') if isinstance(v, str) else v for k, v in line_as_dict.items()}
line_dict_utf8 = {k: v if isinstance(v, str) else v for k, v in line_as_dict.items()}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to lose python2.7 support after this? Will unicode symbols be parsed correctly and wrote to file?

csv_writer.writerow(line_dict_utf8)
output_file.close()
bar.finish()