Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

option does not take a value error

Tags:

python

django

I have this Command(BaseCommand) class with this defined:

make_option('--username', action='store_true', dest='username', default=None),

Then I try to run it like this:

python manage.py thescript --username=something

The output is:

manage.py: error: --username option does not take a value

Why?


EDIT

I am always getting None:

class Command(BaseCommand):
    args = '--username=username ...'
    help = '...'

    option_list = BaseCommand.option_list + (
        make_option('--username', action='store', default=None, help='...'),
    )

    def handle(self, *args, **options):
        print options['username']
like image 533
azio Avatar asked Dec 03 '25 03:12

azio


1 Answers

The line store_true will cause the command to store the boolean value True if the argument --username is given, rather then storing the next value.

I suspect that doing something along the lines of action='store' would do what you expect.

I think you're currently using optparse, correct? If so, you can find a full listing of the different kinds of actions available in the optparse documentation.

like image 200
Michael0x2a Avatar answered Dec 04 '25 15:12

Michael0x2a



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!