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


Groups > comp.lang.python > #30311

RE: Redirecting STDOUT to a Python Variable

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ramit.prasad@jpmorgan.com>
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:Python': 0.05; '[],': 0.07; '__name__': 0.07; 'completeness': 0.07; 'except:': 0.07; 'suppose': 0.07; 'sys,': 0.07; 'try:': 0.07; 'received:155': 0.09; 'def': 0.10; "'%s'": 0.16; "'__main__':": 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'exc_type,': 0.16; 'exc_value,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:159.53.110': 0.16; 'received:159.53.110.174': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:sj2.jpmchase.com': 0.16; 'received:svr.bankone.net': 0.16; 'securities,': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.17; 'to:name:python-list@python.org': 0.20; 'import': 0.21; "skip:' 40": 0.22; 'received:169.254': 0.24; 'script': 0.24; 'header:In- Reply-To:1': 0.25; 'accuracy': 0.27; 'run': 0.28; 'coded': 0.29; "skip:' 50": 0.29; 'use?': 0.29; 'received:169': 0.29; "skip:' 10": 0.30; 'header:Received:8': 0.30; 'could': 0.32; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'text': 0.34; 'charset:us- ascii': 0.36; 'problems': 0.36; 'why': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'email addr:gmail.com': 0.63; 'information,': 0.63; 'url:email': 0.63; 'more': 0.63; 'legal': 0.65; 'subject': 0.66; 'purchase': 0.67; 'sale': 0.76; 'captures': 0.84; 'received:169.254.8': 0.84
X-DKIM OpenDKIM Filter v2.1.3 sj2.jpmchase.com q8RH9PA8031349
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1348765766; bh=kFLshUTy+0JjQ1FOKXu8p7l7yvQjx0Jzw2inF6x7hKo=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=em1r/MMGjipBEwwVsvsqsfrBwGPUZuR4ULRdlJvl8Zag9mrb943RJT2oAfHYtZKTC S+bTZ/UBhtavxfU+etoxOjvwdtFHrsAzb9JsagaCWaHQMv0W7Za8SzXr+Z3ydLkV/q yKDhTDdGJKvEGBAKyA06JYwwpp17idiz/dqxc4f0=
From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
To "python-list@python.org" <python-list@python.org>
Subject RE: Redirecting STDOUT to a Python Variable
Thread-Topic Redirecting STDOUT to a Python Variable
Thread-Index AQHNmQ2pBN1iJzn9x0Se6I1X13ZmY5eXzbiAgAalRPA=
Date Thu, 27 Sep 2012 17:09:05 +0000
References <7e934b64-ec84-48c8-a4bb-a2272f1449a4@u26g2000yqu.googlegroups.com> <4c206409$0$14147$c3e8da3@news.astraweb.com> <8cabc9bb-5ae0-41fa-86b6-0a184192e601@googlegroups.com> <505ebc65$0$6891$e4fe514c@news2.news.xs4all.nl>
In-Reply-To <505ebc65$0$6891$e4fe514c@news2.news.xs4all.nl>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [10.67.79.47]
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-DLP-FWD Yes
Content-Type text/plain; charset="us-ascii"
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.1501.1348765906.27098.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348765906 news.xs4all.nl 6900 [2001:888:2000:d::a6]:42296
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:30311

Show key headers only | View raw


Hans Mulder wrote:
> On 22/09/12 23:57:52, ross.marsden@gmail.com wrote:
> > To capture the traceback, so to put it in a log, I use this
> >
> > import traceback
> >
> > def get_traceback(): # obtain and return the traceback
> >     exc_type, exc_value, exc_traceback = sys.exc_info()
> >     return ''.join(traceback.format_exception(exc_type, exc_value,
> exc_traceback))
> 
> This could be coded more succinctly as
> 
> import sys, traceback
> 
> def get_traceback(): # obtain and return the traceback
>     return ''.join(traceback.format_exception(*sys.exc_info()))

Why not just use?

      return traceback.format_exc()

> 
> > Suppose I have a script run by the scheduler, this captures the traceback
> form any problems and emails them.
> >
> > if __name__ == '__main__':
> >     try:
> >         Runs_unattended()
> >     except:
> >         send_mail(send_from = yourEmailAddress,
> >               send_to = [ yourEmailAddress ], subject = 'Runs_unattended',
> >               text = '%s' % get_traceback(),
> >               files = [], server=yourLocalSMTP)
> 
> Errhm, '%s' % get_traceback() is equiavalent to get_traceback()
> How about:
> 
> if __name__ == '__main__':
>     try:
>         Runs_unattended()
>     except:
>         send_mail(send_from = yourEmailAddress,
>               send_to = [ yourEmailAddress ],
>               subject = 'Runs_unattended',
>               text = get_traceback(),
>               files = [],
>               server=yourLocalSMTP)
> 

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

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


Thread

Re: Redirecting STDOUT to a Python Variable ross.marsden@gmail.com - 2012-09-22 14:57 -0700
  Re: Redirecting STDOUT to a Python Variable Hans Mulder <hansmu@xs4all.nl> - 2012-09-23 09:38 +0200
    RE: Redirecting STDOUT to a Python Variable "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-09-27 17:09 +0000

csiph-web