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: 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: References: Date: Mon, 25 Jun 2012 14:41:52 -0700 Subject: Re: Perl __DATA__ construct. From: Benjamin Kaplan 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Mon, Jun 25, 2012 at 2:20 PM, Mladen Gogala wr= ote: > 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 () { > =C2=A0 =C2=A0s/%OB/$base/; > =C2=A0 =C2=A0if ( length($home) > 0 ) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0s/%OH/$home/; > =C2=A0 =C2=A0} > =C2=A0 =C2=A0else { > =C2=A0 =C2=A0 =C2=A0 =C2=A0s/\/%OH$//; > =C2=A0 =C2=A0} > =C2=A0 =C2=A0if ( length($sid) > 0 && /%OS/ ) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0s/%OS/$sid/; > =C2=A0 =C2=A0} > =C2=A0 =C2=A0elsif (/%OS/) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0next; > =C2=A0 =C2=A0} > =C2=A0 =C2=A0s/%VR/$ver/; > =C2=A0 =C2=A0print; > } > __DATA__ > # .bashrc > # Source global definitions > if [ -f /etc/bashrc ]; then > =C2=A0 =C2=A0 =C2=A0 =C2=A0. /etc/bashrc > fi > set -a > > # User specific aliases and functions > export PATH=3D/sbin:/bin:/usr/sbin:$PATH > export EDITOR=3Dvi > export ORACLE_BASE=3D%OB > export ORACLE_HOME=3D$ORACLE_BASE/product/%VR/%OH > export LD_LIBRARY_PATH=3D$ORACLE_HOME/lib:/opt/odbc/lib:$ORACLE_HOME/lib3= 2 > export CLASSPATH=3D/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=3D< 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