Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #24448
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <bsk16@case.edu> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.006 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'definitions': 0.07; 'skip:l 60': 0.07; 'aliases': 0.09; 'escape': 0.09; 'rewrite': 0.09; '!defined': 0.16; 'eof': 0.16; 'script,': 0.16; '\xc2\xa0if': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'python?': 0.20; 'skip:p 30': 0.22; 'string': 0.22; 'string,': 0.22; 'this:': 0.23; 'header:In-Reply-To:1': 0.23; 'idea': 0.25; 'message- id:@mail.gmail.com': 0.27; 'source': 0.28; 'script': 0.28; 'perl': 0.29; 'skip:! 10': 0.29; 'url:python': 0.31; 'lines': 0.32; 'like:': 0.33; 'oracle': 0.33; 'file': 0.34; 'received:google.com': 0.34; 'received:209.85': 0.35; 'to:addr :python-list': 0.35; 'there': 0.35; 'url:org': 0.35; 'something': 0.36; 'character': 0.36; 'but': 0.36; 'subject:: ': 0.37; 'received:209': 0.37; 'pm,': 0.38; 'end': 0.38; 'data': 0.39; 'to:addr:python.org': 0.39; 'entire': 0.62; 'skip:\xc2 10': 0.63; 'special': 0.74; 'export': 0.76; 'skip:$ 10': 0.79; 'url:tutorial': 0.84 |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding:x-gm-message-state; bh=Waov0YvZrhD8PVuAs03DRZZKDXcYkh0W1jgKEUSEqos=; b=Zfr/Y8UoIS0gsgy6FWw2pdVb8pWcIMbqcXZjsR0L/QUVrH7CUEIs2IXNpL6N9EiA/o gQ2fbsR8+3wlKDswtuvsC/bst+KM/+P58kRo9Ez1G0sY7tnbzwxAa0eUnN4dt/ICX1fX bfKlVZzAT7wM1APZcELxRQ6oct5DDPo5WfF2yRjlmF6agfu9F2IAnObvMuqZKzej7/Pj p5x3hNnB73tQAlQ9fP1Xmn/Jxrnfpdh7yOis3TcwwM3MDyDqyVZ5AeqvM59OfIRnxzp1 RSYJ3mrPODEU7vZjKjcy2SbFFZxvHDqd47k569dWaWI8PwOU1vk20OGAb6IFjj9D9HXG bJKA== |
| MIME-Version | 1.0 |
| In-Reply-To | <jsakmp$bsp$1@solani.org> |
| References | <jsakmp$bsp$1@solani.org> |
| Date | Mon, 25 Jun 2012 14:41:52 -0700 |
| Subject | Re: Perl __DATA__ construct. |
| From | Benjamin Kaplan <benjamin.kaplan@case.edu> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-Gm-Message-State | ALoCoQkYeUoEFddt70LTLJVpqhsBOwznqNiz0eIvvrHynWnwtgFbvb4xbbizkDpkyn686zoCKlO0 |
| X-Junkmail-Whitelist | YES (by domain whitelist at mpv2.tis.cwru.edu) |
| 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.1500.1340660517.4697.python-list@python.org> (permalink) |
| Lines | 71 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1340660517 news.xs4all.nl 6885 [2001:888:2000:d::a6]:50638 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:24448 |
Show key headers only | View raw
On Mon, Jun 25, 2012 at 2:20 PM, Mladen Gogala <gogala.mladen@gmail.com> wrote:
> I have a script in Perl that I need to rewrite to Python. The script
> contains __DATA__ at the end of the script, which enables Perl to access
> all the data after that through a file descriptor, like this:
>
> usage() if ( !$stat or !defined($home) or !defined($base) or !defined
> ($sid) );
> while (<DATA>) {
> s/%OB/$base/;
> if ( length($home) > 0 ) {
> s/%OH/$home/;
> }
> else {
> s/\/%OH$//;
> }
> if ( length($sid) > 0 && /%OS/ ) {
> s/%OS/$sid/;
> }
> elsif (/%OS/) {
> next;
> }
> s/%VR/$ver/;
> print;
> }
> __DATA__
> # .bashrc
> # Source global definitions
> if [ -f /etc/bashrc ]; then
> . /etc/bashrc
> fi
> set -a
>
> # User specific aliases and functions
> export PATH=/sbin:/bin:/usr/sbin:$PATH
> export EDITOR=vi
> export ORACLE_BASE=%OB
> export ORACLE_HOME=$ORACLE_BASE/product/%VR/%OH
> export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/opt/odbc/lib:$ORACLE_HOME/lib32
> export CLASSPATH=/opt/java/lib/tools.jar:$ORACLE_HOME/jdbc/lib/
> ojdbc14.jar:.
>
> ......
>
>
>
> How do I do the same thing in Python? Alternatively, in Perl I can put an
> entire file into a string by using something like:
>
> $str=<<EOF
> This is all a single string,
> no matter how many lines do
> I put in it, but I do have to
> escape the special character
> EOF
> ;
>
> Is there a way to do the same thing in Python? The idea of the script is
> to generate $HOME/.bashrc for any automagically provisioned Oracle
> installation.
>
either escape the new-line
'hello \
world'
or use triple-quoted strings
"""hello
world"""
http://docs.python.org/tutorial/introduction.html#strings
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Perl __DATA__ construct. Mladen Gogala <gogala.mladen@gmail.com> - 2012-06-25 21:20 +0000 Re: Perl __DATA__ construct. Benjamin Kaplan <benjamin.kaplan@case.edu> - 2012-06-25 14:41 -0700 Re: Perl __DATA__ construct. Miki Tebeka <miki.tebeka@gmail.com> - 2012-06-25 14:50 -0700
csiph-web