0
所以我認爲使用python點擊庫來構建一個簡單的命令行工具將非常簡單。看起來我卡在一些只是沒有點擊我的東西。我有以下代碼:如何在使用python的點擊庫時擺脫這種TypeError?
import click
import json
import os.path
import sys
@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name',
help='The person to greet.')
@click.argument('title')
@click.argument('category')
@click.argument('tech')
@click.argument('problemNotes')
@click.argument('solutionNotes')
def hello(count, name, title, category, tech, problemNotes, solutionNotes):
print(tech + problemNotes + solutionNotes)
if __name__ == '__main__':
hello()
這看起來很簡單。 CL工具應該有一些選項和參數,然後打印出來。然後我在終端上鍵入以下調用工具:
python bugbook.py --name="steve" "Annoying stack bug" "compile bug" "xcode" "annoying" "get meowed"
,但我得到了以下錯誤:
Traceback (most recent call last):
File "bugbook.py", line 22, in <module>
hello()
File "/Library/Python/2.7/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/Library/Python/2.7/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/Library/Python/2.7/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Library/Python/2.7/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
TypeError: hello() got an unexpected keyword argument 'solutionnotes'
奇怪,我想。看來這錯誤是由casued:
if __name__ == '__main__':
hello()
這實際上調用的主要功能未能在正確的參數什麼的通過,但我試圖修修補補,只是無法得到它的工作。我錯過了什麼明顯的東西?
需要注意的是Python的抱怨'「solutionnotes'',而在你的文件中的參數被命名爲'」 solutionNotes'' 。再次檢查您是否粘貼/使用了正確的代碼。 – DyZ
是的 - 這是奇怪的,因爲沒有在我的代碼中的位置我使用'solutionnotes'我只使用'solutionNotes',所以事實上cl給出了這個錯誤與不同的外殼是奇怪的,也許是線索 – frankunderwoodisreal
嗯,我只是試圖改變所有我的代碼大小寫全部小寫,並擺脫了錯誤 - 嗯 – frankunderwoodisreal