python script is not running
Terry Jan Reedy
tjreedy at udel.edu
Sat May 18 12:35:19 EDT 2013
On 5/18/2013 6:12 AM, Avnesh Shakya wrote:
> hi,
> i want to run python script which generating data into json fromat, I am using crontab, but it's not executing...
> my python code--
> try.py --
>
> import json
> import simplejson as json
> import sys
>
> def tryJson():
> saved = sys.stdout
> correctFile = file('data.json', 'a+')
> sys.stdout = correctFile
Don't need to change stdout.
> result = []
> i = 1
> for i in range(5):
> info = {
> 'a': i+1,
> 'b': i+2,
> 'c': i+3,
> }
> result.append(info)
What is you want to add print result for debugging?
> if result:
> print json.dumps(result, indent=6)
Either use print >> correctFile, correctFile.write (do you really want
the extra '\n' that print adds?), or, do the future import of print as
function and pass correctFile as the file argument
> sys.stdout = saved
> correctFile.close()
> tryJson()
More information about the Python-list
mailing list