[英]Is there a way to hold a big list of strings in memory created from a Python script, and made available to the current bash shell?
想象一下,我在Python程序中列出了很多文件路徑,然后想在終端中使用它。
我可以將其存儲到文件中。
我可以將其通過管道傳遞到Python程序之外,以便bash可以讀取它。
但是是否可以只是設置某種變量,以使當前shell(運行腳本的那個shell)作為普通bash變量訪問輸出?
請注意,使用“ $ var”訪問bash變量的區別在於保留換行符,而使用普通的$ var則將換行符更改為空格。
paddy$ echo $SHELL
/bin/bash
paddy$ unset frompython
paddy$ cat alltxt.py
from glob import glob
print("\n".join(glob("*.txt")))
paddy$ python alltxt.py
entry3.txt
entry2.txt
test_in2.txt
infile.txt
test_in.txt
entry.txt
entry1.txt
testfile.txt
paddy$ frompython=`python alltxt.py`
paddy$ echo $frompython
entry3.txt entry2.txt test_in2.txt infile.txt test_in.txt entry.txt entry1.txt testfile.txt
paddy$ echo "$frompython"
entry3.txt
entry2.txt
test_in2.txt
infile.txt
test_in.txt
entry.txt
entry1.txt
testfile.txt
paddy$
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.