Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105900
| From | Hongyi Zhao <hongyi.zhao@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Using python heredoc to substitute the external file read by python script. |
| Date | 2016-03-28 12:01 +0000 |
| Organization | NPO RUSnet InterNetNews site |
| Message-ID | <ndb6fj$t85$1@aspen.stu.neva.ru> (permalink) |
| References | <ndaool$m2u$1@aspen.stu.neva.ru> <mailman.104.1459160997.28225.python-list@python.org> |
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 :.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Using python heredoc to substitute the external file read by python script. Hongyi Zhao <hongyi.zhao@gmail.com> - 2016-03-28 08:07 +0000
Re: Using python heredoc to substitute the external file read by python script. Ben Finney <ben+python@benfinney.id.au> - 2016-03-28 21:29 +1100
Re: Using python heredoc to substitute the external file read by python script. Hongyi Zhao <hongyi.zhao@gmail.com> - 2016-03-28 12:01 +0000
Re: Using python heredoc to substitute the external file read by python script. Ben Finney <ben+python@benfinney.id.au> - 2016-03-29 05:59 +1100
csiph-web