Weird behaviour with optparse and bash tab completion

Posted by PulpFiction on Stack Overflow See other posts from Stack Overflow or by PulpFiction
Published on 2010-06-02T07:29:45Z Indexed on 2010/06/02 7:33 UTC
Read the original article Hit count: 171

Filed under:

Hi

I am building a script for users new to Linux, so please understand why I am asking this :)

My script runs like this:

python script.py -f filename.txt

I am using the optparse module for this. However, I noticed the following when doing tab completion.

The tab completion works when I do:

python script.py <tab completion> # Tab completion works normally as expected

But it does not work when I do it like this:

python script.py -f <tab completion> # No type of tab completion works here.

I really don't want my users typing the name of the input file. Tab completion is a must. How can I get it working or what am I doing wrong here?

© Stack Overflow or respective owner

Related posts about python