Skip to content

Instantly share code, notes, and snippets.

@codeAshu
Created February 1, 2019 09:06

Revisions

  1. codeAshu created this gist Feb 1, 2019.
    32 changes: 32 additions & 0 deletions fileread.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    import json

    input_ls = []
    f = open('inputTraining.txt')

    for line in iter(f):
    try:
    input_ls.append(json.loads(line))
    except ValueError:
    print line +'is not a proper json line'
    f.close()

    nCount = input_ls[0]
    input_ls = input_ls[1:]

    if len(input_ls) != nCount :
    print 'Data is not correct, pls check!'


    calvin = []
    hobbes = []
    for c in input_ls:
    calvin.append(c.get('calvin'))
    hobbes.append(c.get('hobbes'))

    target = []
    f = open('outputTraining.txt')
    for line in iter(f):
    line = line.replace('\n','')
    target.append(line)
    f.close()
    print len(target)