Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Mladen Gogala Newsgroups: comp.lang.python Subject: Perl __DATA__ construct. Date: Mon, 25 Jun 2012 21:20:25 +0000 (UTC) Organization: solani.org Lines: 61 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: solani.org 1340659225 12185 eJwFwQkBwDAIA0BLDV9AzkrBv4TduQaiaeFhvr6qSmEacVanByYheN/kotKE5XNvnXpEr7wf/jcQfQ== (25 Jun 2012 21:20:25 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 25 Jun 2012 21:20:25 +0000 (UTC) User-Agent: Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) X-User-ID: eJwFwQkBACAIA8BKoGNCHOXpH8E721TmAY2wsVntG7xLblTKaEE0JPhaTq3Wdqhntw9gr/wDE1MRAQ== Cancel-Lock: sha1:CTPEuReU/ibUTkpkviSNb+9gcL8= X-NNTP-Posting-Host: eJwFwQERACAIBMFMgPdKHGGwfwR3CZl6L6HF40W4qM6doPG4WLw83JqKqTy9xzGuzJ3mAwo8EHo= Xref: csiph.com comp.lang.python:24446 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 () { 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=<