[英]How to use the bash command 'read -e variable' and pass the variable to a python variable
I'd like to pass shell input to a variable in python. 我想将shell输入传递给python中的变量。 Normally I would use the
raw_input()
method for this, but I'd like to use something which allows me to "browse" through my folders. 通常我会使用
raw_input()
方法,但我想使用允许我“浏览”我的文件夹的东西。
In a bash script I'd use something like this: (The -e allows me use the "autocomplete" function of the shell via Tab.) 在bash脚本中我会使用这样的东西:( -e允许我通过Tab使用shell的“自动完成”功能。)
#!/bin/bash
echo Please input the path to the file:
read -e var
echo $var
Does anyone know how to solve this in Python? 有谁知道如何在Python中解决这个问题? I looked at
os.popen()
and os.system()
but cannot figure out how to use them. 我查看了
os.popen()
和os.system()
但无法弄清楚如何使用它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.