Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {"setup": "test", "punchline": "ok", "numOfRatings": 0, "sumOfRatings": 0},
- {"setup": "test2", "punchline": "ok2", "numOfRatings": 0, "sumOfRatings": 0}
- {"setup": "test", "punchline": "ok", "numOfRatings": 0, "sumOfRatings": 0}
- {"setup": "test2", "punchline": "ok2", "numOfRatings": 0, "sumOfRatings": 0}
- def dicts_from_file(file):
- dicts_from_file = []
- with open(file,'r') as inf:
- for line in inf:
- dicts_from_file.append(eval(line))
- return dicts_from_file
- def get_setups(dicts):
- setups = []
- for dict in dicts:
- for key in dict:
- if key == "setup":
- setups.append(dict[key])
- return setups
- print get_setups(dicts_from_file("data.txt"))
- f = open('data')
- for line in f:
- d = ast.literal_eval(line)[0]
- print d['setup']
- f = open('data')
- for line in f:
- d = ast.literal_eval(line)
- print d['setup']
- def get_setup_from_file(file_name):
- result = []
- f = open(file_name, "r")
- for line in f.xreadlines():
- # or line_dict = json.loads(line)
- line_dict = eval(line) # if line end witch ',', try eval(line[0:-1])
- result.append(line_dict["setup"])
- return result
- with open(file,'r') as file_input:
- for line in file_input:
- print eval(line).get("setup")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement