Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4284
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <1011_wxy@163.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.022 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; 'context': 0.04; 'sys': 0.04; 'email name:': 0.09; 'etc.),': 0.09; 'finally:': 0.09; 'necessary,': 0.09; 'skip:& 70': 0.09; 'written': 0.12; 'def': 0.13; "'w')": 0.16; 'orig_stdout': 0.16; 'rachel': 0.16; 'received:220.181.13': 0.16; 'stringio': 0.16; 'sys.stdout': 0.16; '>': 0.18; 'yield': 0.19; 'subject:help': 0.19; 'cc:2**0': 0.20; 'cc:addr:python-list': 0.22; 'objects': 0.24; 'chris': 0.27; 'url:mailman': 0.27; 'closing': 0.29; 'cc:addr:python.org': 0.31; 'it.': 0.31; 'import': 0.32; 'thank': 0.32; 'url:listinfo': 0.33; 'someone': 0.33; 'data.': 0.33; 'got': 0.34; 'files,': 0.35; 'try:': 0.35; 'case,': 0.36; 'skip:o 20': 0.37; 'url:python': 0.37; 'user': 0.38; 'files': 0.38; 'url:org': 0.38; 'help': 0.39; 'much.': 0.39; 'received:220': 0.60; 'best': 0.60; 'happen': 0.61; 'to:2**2': 0.61; 'order': 0.61; 'dear': 0.64; 'kinds': 0.67; 'subjectcharset:utf-8': 0.70; 'received:220.181': 0.72; 'skip:\xe5 10': 0.73; 'from:addr:163.com': 0.77; 'received:163.com': 0.77; 'schrieb': 0.84; 'url:nbsp': 0.84; 'subject:your': 0.85; 'abstracts': 0.91 |
| Date | Fri, 29 Apr 2011 09:31:02 +0800 |
| From | "1011_wxy"<1011_wxy@163.com> |
| To | "Thomas Rachel"<nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>, "Jean-Michel Pichavant"<jeanmichel@sequans.com>, "Chris Rebert"<clp2@rebertia.com> |
| Subject | 回复: Re: Need your help |
| MIME-Version | 1.0 |
| Content-Type | multipart/alternative; boundary="__=_Part_Boundary_005_002766.015314" |
| X-Mailer | NetEase Flash Mail 2.0.2.30 |
| X-Priority | 3 (Normal) |
| X-Originating-IP | [220.248.57.11] |
| X-CM-TRANSID | 6cKowKBr9fRZFLpNHCMAAA--.1475W |
| X-CM-SenderInfo | yrqrisxz01qiywtou0bp/1tbiNRgwR0kStHQBLgABsv |
| X-Coremail-Antispam | 1U5529EdanIXcx71UUUUU7vcSsGvfC2KfnxnUU== |
| Cc | python-list <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| 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.973.1304041527.9059.python-list@python.org> (permalink) |
| Lines | 101 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1304041527 news.xs4all.nl 41110 [::ffff:82.94.164.166]:38502 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:4284 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Dear Thomas,JM,Chris Rebert:
I got it. Thank you very very very much.
Best Regards
2011-04-29
1011_wxy
发件人: Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
发送时间: 2011-04-28 21:26
主 题: Re: Need your help
收件人: python-list@python.org
Am 28.04.2011 13:14, schrieb Chris Rebert:
> import a, b, sys
> def c():
> orig_stdout = sys.stdout
> sys.stdout = open('my_log_file.log', 'w')
> a.a()
> b.b()
> sys.stdout.close()
> sys.stdout = orig_stdout
>
>
> Someone may have written a with-statement context manager that
> abstracts away the swapping.
@contextlib.contextmanager
def swap_stdout(target):
orig_stdout = sys.stdout
sys.stdout = target
try:
yield target
finally:
sys.stdout = orig_stdout
In this case, I can use all kinds of files (open() files, StringIO
objects etc.), and can re-use them if necessary, in order to
prepend/append data.
Closing can happen additionally, if the user wants.
Thomas
--
http://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
回复: Re: Need your help "1011_wxy"<1011_wxy@163.com> - 2011-04-29 09:31 +0800
csiph-web