Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45515

Re: python script is not running

From Terry Jan Reedy <tjreedy@udel.edu>
Subject Re: python script is not running
Date 2013-05-18 12:35 -0400
References <bb111639-6a94-4151-a153-9bbebe75a4ea@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1806.1368894928.3114.python-list@python.org> (permalink)

Show all headers | View raw


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()

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

python script is not running Avnesh Shakya <avnesh.nitk@gmail.com> - 2013-05-18 03:12 -0700
  Re: python script is not running Chris Angelico <rosuav@gmail.com> - 2013-05-18 23:28 +1000
    Re: python script is not running Roy Smith <roy@panix.com> - 2013-05-18 09:44 -0400
  Re: python script is not running Terry Jan Reedy <tjreedy@udel.edu> - 2013-05-18 12:35 -0400
  Re: python script is not running woooee <woooee@gmail.com> - 2013-05-18 10:35 -0700
    Re: python script is not running Chris Angelico <rosuav@gmail.com> - 2013-05-19 03:59 +1000
    Re: python script is not running Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-05-18 20:43 +0200
    Re: python script is not running Chris Angelico <rosuav@gmail.com> - 2013-05-19 09:33 +1000

csiph-web