Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105895 > unrolled thread
| Started by | Hongyi Zhao <hongyi.zhao@gmail.com> |
|---|---|
| First post | 2016-03-28 08:07 +0000 |
| Last post | 2016-03-29 05:59 +1100 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.python
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
| From | Hongyi Zhao <hongyi.zhao@gmail.com> |
|---|---|
| Date | 2016-03-28 08:07 +0000 |
| Subject | Using python heredoc to substitute the external file read by python script. |
| Message-ID | <ndaool$m2u$1@aspen.stu.neva.ru> |
Hi all,
See the following python codes:
import os
from subprocess import check_output
# POSIX: name shall not contain '=', value doesn't contain '\0'
output = check_output("source /home/werner/env-intel-toolchains.sh;
env -0", shell=True, executable="/bin/bash")
In the above codes, I use the file /home/werner/env-intel-toolchains.sh
for subprocess.check_output to use for its operation.
If I want to use python heredoc to substitute this external file for the
above codes. Is this possible?
Regards
--
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
[toc] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2016-03-28 21:29 +1100 |
| Message-ID | <mailman.104.1459160997.28225.python-list@python.org> |
| In reply to | #105895 |
Hongyi Zhao <hongyi.zhao@gmail.com> writes: > 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? -- \ “Anyone who puts a small gloss on [a] fundamental technology, | `\ calls it proprietary, and then tries to keep others from | _o__) building on it, is a thief.” —Tim O'Reilly, 2000-01-25 | Ben Finney
[toc] | [prev] | [next] | [standalone]
| From | Hongyi Zhao <hongyi.zhao@gmail.com> |
|---|---|
| Date | 2016-03-28 12:01 +0000 |
| Message-ID | <ndb6fj$t85$1@aspen.stu.neva.ru> |
| In reply to | #105898 |
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 :.
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2016-03-29 05:59 +1100 |
| Message-ID | <mailman.109.1459191589.28225.python-list@python.org> |
| In reply to | #105900 |
I don't understand what you're trying to do. But I think you have fixed your problem: Hongyi Zhao <hongyi.zhao@gmail.com> writes: > It seems the above code will do the job for me. If I understand correctly this sentence, you now have a satisfactory solution. Good! -- \ “A man must consider what a rich realm he abdicates when he | `\ becomes a conformist.” —Ralph Waldo Emerson | _o__) | Ben Finney
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web