Created
January 5, 2017 02:27
-
-
Save mdengler/63826f02744f23e29389ca5d50eeeb94 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python | |
import json | |
import random | |
filename = "test.json" | |
x = [{"ID": i, | |
"xxx": "".join(["f"] * random.randint(1, 20)), | |
"yyy": "".join(["f"] * random.randint(1, 20))} | |
for i in range(20)] | |
with open(filename, "wb") as fh: | |
for d in x: | |
fh.write(json.dumps(d) + "\n") | |
X = dict() | |
with open(filename, 'r') as f: | |
for line in f: | |
print(line) | |
data = json.loads(line) | |
if data['xxx'] is not None and data['yyy'] is not None: | |
X[data['ID']] = len(data['xxx']) / len(data['yyy']) # this line is the problem | |
print(X) |
Author
mdengler
commented
Jan 5, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment