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


Groups > comp.lang.python > #45515

Re: python script is not running

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 <python-python-list@m.gmane.org>
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 <tjreedy@udel.edu>
Subject Re: python script is not running
Date Sat, 18 May 2013 12:35:19 -0400
References <bb111639-6a94-4151-a153-9bbebe75a4ea@googlegroups.com>
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 <bb111639-6a94-4151-a153-9bbebe75a4ea@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1806.1368894928.3114.python-list@python.org> (permalink)
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

Show key headers only | 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