Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.041 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'automate': 0.07; 'literal': 0.09; 'template': 0.14; 'cui': 0.16; 'guys,': 0.16; 'url:pocoo': 0.16; 'hey': 0.18; 'variable': 0.18; 'trying': 0.19; 'value.': 0.19; 'to:name:python-list@python.org': 0.22; 'creating': 0.23; 'header:User-Agent:1': 0.23; 'replace': 0.24; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'document.': 0.30; "i'm": 0.30; 'libraries': 0.31; 'values.': 0.31; 'text': 0.33; 'url:python': 0.33; 'received:fr': 0.33; 'maybe': 0.34; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'url:org': 0.36; 'example,': 0.37; 'initially': 0.38; 'url:library': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'kind': 0.63; 'such': 0.63; 'more': 0.64; 'frank': 0.68; 'lightweight': 0.84; 'power,': 0.91 X-IronPort-AV: E=Sophos;i="4.95,613,1384297200"; d="scan'208";a="51925087" Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: David Froger User-Agent: alot/0.3.5 X-Sender-Computer: INRIA-ROCQ-UBUNTU-fl-58186.rocq.inria.fr To: "python-list@python.org" References: In-Reply-To: Subject: Re: word replacing in a paragraph Date: Mon, 06 Jan 2014 15:39:50 +0100 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389019260 news.xs4all.nl 2883 [2001:888:2000:d::a6]:44545 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63283 Quoting Frank Cui (2014-01-06 15:01:25) > Hey guys, > = > I'm trying to automate a process by initially creating a standard templat= e and > then replace some text fields with variable values. > = > [for example, "DATE" in the paragraph will be replaced by the current date > value. it doesn't have to be a literal word of "DATE", "DATE" in "TESTDAT= E" can > also be replaced.] > = > Is there some lightweight built-in or 3rd party libraries which are good= for > such kind of work ? Hi Franck, There is the standard module: http://docs.python.org/2/library/string.html#template-strings Or maybe if you need more power, something like jinja2. It's for Web (HTML documents), but it can also be used for any kind of document. http://jinja.pocoo.org/docs/ David