简体   繁体   English

如何使用bash命令'read -e variable'并将变量传递给python变量

[英]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()但无法弄清楚如何使用它们。

The readline module can give you tab completion for raw_input(). readline模块可以为raw_input()提供标签完成。

You probably want to do something like this . 你可能想要做像这样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM