4

I'd like to pass shell input to a variable in 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.

In a bash script I'd use something like this: (The -e allows me use the "autocomplete" function of the shell via Tab.)

#!/bin/bash

echo Please input the path to the file:

read -e var

echo $var

Does anyone know how to solve this in Python? I looked at os.popen() and os.system() but cannot figure out how to use them.

mgilson
  • 300,191
  • 65
  • 633
  • 696
Wiggles
  • 125
  • 1
  • 7

1 Answers1

4

The readline module can give you tab completion for raw_input().

You probably want to do something like this.

Community
  • 1
  • 1
Matt
  • 3,651
  • 3
  • 16
  • 35
  • Hey thx for your help. After all, I used a bash script which asks for the path and then opens my python script. This way, it was easier for me to handle and know what is going on. – Wiggles Oct 23 '12 at 15:55