python 3.2では、実行中の関数の残りの部分を停止する方法はありますか?Pythonでは、実行中の関数でコードをどのように停止しますか?
基本的には私のコースワークのコンセプトとしてログインシステムを作成していますが、私はどこにでもこの回答を見つけることができませんでした。
マイコードはここなど2つのファイル、ログファイルと入出力を処理ロガー、およびそのようなデータベース接続などのメインクラス、ログインコード自体、
に分割されるコードでありますユーザーの入力を処理する、私は3番目と4番目の行に興味がある、 'quit'を 'QUIT0x0'に変換して、事故によって呼び出される終了コードの可能性を最小限に抑える。
def getInput(input_string, type):
result = input(input_string)
if result.lower == 'quit':
result = 'QUIT0x0'
#log the input string and result
if type == 1:
with open(logFile, 'a') as log_file:
log_file.write('[Input] %s \n[Result] %s\n' %(input_string, result))
return result
#no logging
elif type == 2:
return result
#undefined type, returns 'Undefined input type' for substring searches, and makes a log entry
else:
result = '[Undefined input type] %s' %(input_string)
output(result, 4)
return result
これは、ユーザデータベースからユーザレコードを削除処理するコード、私は4番目と5番目のラインの仕事を作り、実行から機能の残りの部分を停止する方法に興味がある:
事前にdef deleteUser(self):
self.__user = getInput('Enter the username you want to delete records for: ', 1)
if self.__user == 'QUIT0x0':
#Quit code goes here
else:
self.__userList = []
self.__curs.execute('SELECT id FROM users WHERE username="%s"' %(self.__user))
おかげで、 トム
'result.lower'をすべきbe 'result.lower() ' –
なぜ' quit() 'コードが偶然に呼び出されるのですか? –