我正在爲Git編寫一個預先提交的鉤子,它運行pyflakes並檢查修改文件中的製表符和尾隨空格(code on Github)。我想通過要求用戶確認,使其可以覆蓋鉤如下:如何在Python Git鉤子中使用raw_input()?
answer = raw_input('Commit anyway? [N/y] ')
if answer.strip()[0].lower() == 'y':
print >> sys.stderr, 'Committing anyway.'
sys.exit(0)
else:
print >> sys.stderr, 'Commit aborted.'
sys.exit(1)
此代碼產生一個錯誤:
Commit anyway? [N/y] Traceback (most recent call last):
File ".git/hooks/pre-commit", line 59, in ?
main()
File ".git/hooks/pre-commit", line 20, in main
answer = raw_input('Commit anyway? [N/y] ')
EOFError: EOF when reading a line
它甚至有可能使用的raw_input()或在Git鉤子中有類似的功能,如果是的話,我做錯了什麼?
這完美的作品。謝謝。 – badzil