Using python heredoc to substitute the external file read by python script.
Hongyi Zhao
hongyi.zhao at gmail.com
Mon Mar 28 08:01:56 EDT 2016
On Mon, 28 Mar 2016 21:29:48 +1100, Ben Finney wrote:
>> If I want to use python heredoc to substitute this external file for
>> the above codes. Is this possible?
>
> What do you mean by “Python heredoc”? What Python feature are you
> referring to?
I find the following methods currently:
import subprocess
subprocess.Popen(
"""
cat <<EOF > new.txt
Hello World!
EOF""", shell=True)
subprocess.Popen(
"""
cat <<EOF | sh
source /opt/intel/composer_xe_2011_sp1.11.339/bin/ifortvars.sh intel64
source /opt/intel/composer_xe_2011_sp1.11.339/bin/iccvars.sh intel64
source /opt/intel/composer_xe_2011_sp1.11.339/mkl/bin/mklvars.sh intel64
lp64 mod
source /opt/intel/impi/4.1.0.024/intel64/bin/mpivars.sh
env -0
EOF
""", shell=True,
executable = "/bin/bash",)
or
import subprocess
subprocess.check_output(
"""
cat <<EOF | sh
source /opt/intel/composer_xe_2011_sp1.11.339/bin/ifortvars.sh intel64
source /opt/intel/composer_xe_2011_sp1.11.339/bin/iccvars.sh intel64
source /opt/intel/composer_xe_2011_sp1.11.339/mkl/bin/mklvars.sh intel64
lp64 mod
source /opt/intel/impi/4.1.0.024/intel64/bin/mpivars.sh
env -0
EOF
""", shell=True,
executable = "/bin/bash",)
It seems the above code will do the job for me.
Regards
--
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
More information about the Python-list
mailing list