NeptuneGamer
NeptuneGamer

Reputation: 123

Arg parse not returning float

I am trying to create a function to control the volume of a file. I dont understand why this error is occurring as I should simply be returning a float

parser.add_argument('--volume','-v', default=None, type=float,help='Number  between 0.0 and 1.0 indicating volume level')
    print args.volume

python audio.py -v 0.333338 (terminal input)

    usage: audio.py [-h] [--volume VOLUME] phrase [phrase ...]
            audio.py: error: too few arguments

Below is the initialisation of the parser

 parser = argparse.ArgumentParser()
    parser.add_argument('--volume','-v', default=None, type=float,help='Number  between 0.0 and 1.0 indicating volume level')
    parser.add_argument('phrase', nargs='+', help="Audio phrase for interpretation")
    args = parser.parse_args()

Upvotes: 0

Views: 1645

Answers (2)

Tautvydas
Tautvydas

Reputation: 2067

Using python 2.7.10 and this code snippet work fine:

import argparse

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--volume','-v', default=None, type=float,help='Number between 0.0 and 1.0 indicating volume level')
args = parser.parse_args()
print args.volume

Try copy pasting same snippet and let me know if it works. My output looks like this:

:-/temp$ python audio.py -v 0.333338
0.333338

Upvotes: 0

alecxe
alecxe

Reputation: 473873

usage: audio.py [-h] [--volume VOLUME] phrase [phrase ...]

You are missing the phrase argument:

python audio.py -v 0.333338 some_phrase_here

Upvotes: 2

Related Questions