Pedro Mendes
Pedro Mendes

Reputation: 25

docopt in python3 argumentes definitions

I'm trying to use docopt.

i want to call my program like this:

python3 my_script -p argum1 -d argum2 -u faculm

The -u is not mandatory, but "-p" and "-d" are mandatory.

i have allready made this:

""" 
Usage:
    passwdcrack.py -p=<password>, 
    passwdcrack.py -d=<dicionario>       
    passwdcrack.py [-u=<user>]        

Options:
    -h --help       mostra este ecrã
    --version       Mostra a versão
    -p=<password>   indicar o caminho para o ficheiro tipo */etc/shadow
    -d=<dicionario> indicar o caminho para o ficheiro com lista de Passw
    -u=<user>       indica o utilizador para ser analisado
"""
import docopt

if __name__ == '__main__':
    arguments = docopt.docopt(__doc__, version='0.0001')
    print (arguments)

but when i call it it gives me this:

$ python3 passwdcrack.py -d papa -d pfpf -u madona Traceback (most recent call last): File "passwdcrack.py", line 17, in arguments = docopt.docopt(doc, version='0.0001') AttributeError: 'module' object has no attribute 'docopt'

Can some one help me? thanks

Upvotes: 1

Views: 597

Answers (2)

Pedro Mendes
Pedro Mendes

Reputation: 25

I have found out. Docopt is very picky concerning the space and tabs.

so here is how it's going to be.

"""
Usage:
  passcrack_end.py -p <passw> -d <dic> [-u <user>]

Arguments:
  <passw>   ficheiro onde se encontram as passwords encriptadas - shadow
  <dic>     ficheiros com o dicionario das possiveis palavras passe 
  <user>    Utilizador para o qual quer encontrar a password

Option:
  -p pp     opção obrigatória
  -d dd     opção obrigatória
  -u uu     campo facultativo
"""

Watch out for the spaces. in the options the indentations is 2 spaces -d

if you call the program with this arguments:

-d derivation -p panto -u ume

the output will be:

{
  "-d": "derivation", 
  "-p": "panto", 
  "-u": "ume"
}

if you call the program with this arguments:

-p panto -u ume -d derivation

the output will be the same:

{
  "-d": "derivation", 
  "-p": "panto", 
  "-u": "ume"
}

Upvotes: 0

Padraic Cunningham
Padraic Cunningham

Reputation: 180401

You have a file called docopt.py somewhere in your path that is getting imported instead of the actual docopt module. You need to find it and rename or remove it.

Upvotes: 1

Related Questions