Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'argument': 0.05; 'json': 0.07; 'sys': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:script': 0.09; 'python': 0.11; 'def': 0.12; '(do': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sys.stdout': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'script': 0.25; 'pass': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'file': 0.32; 'run': 0.32; 'info': 0.35; 'but': 0.35; 'add': 0.35; 'really': 0.36; 'hi,': 0.36; 'to:addr:python-list': 0.38; 'generating': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'future': 0.60; 'received:173': 0.61; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Jan Reedy Subject: Re: python script is not running Date: Sat, 18 May 2013 12:35:19 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368894928 news.xs4all.nl 15960 [2001:888:2000:d::a6]:36078 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45515 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()