无法调用类函数 [英] Not able to call class function

查看:87
本文介绍了无法调用类函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#!"C:\\Users\\M1032959\\AppData\\Local\\Programs\\Python\\Python36\\python.exe"

import cgi, cgitb
import _mysql
import sys
import logging

print ("Content-Type: text/html")
print ("""
  <TITLE>Bank login</TITLE>
""")

log_fname = "login_Details.log"

logging.basicConfig(filename=log_fname,
                    filemode='a',
                    level=logging.DEBUG,
                    format='%(asctime)s : %(levelname)s => %(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S'
                   )

frmEmp = cgi.FieldStorage()

try:
    conn = _mysql.connect("localhost", "root", "", "bank_details")
    logging.info('connection details:%s',conn)
except Exception as e:
    print ("<br>Connection Error-> e</br>")
    logging.error('connection error: %s',e)
sys.exit()

class UserBankData:
    username = []
    upassword = []    
    def __init__(self):
        username = self.username
        upassword = self.upassword            
    def validateData(self):
        username = frmEmp.getvalue("uname")
        upassword = frmEmp.getvalue("upassword")
        # serch username and password in database
        sql = "SELECT uname,pass FROM login_check"
        conn.query(sql)
        login = 0
        # Store the result set
        all_recs = conn.store_result()
        rec = all_recs.fetch_row()
        while (rec):
          for ename, epass in rec:
            ename = str(ename, 'utf-8')
            epass = str(epass, 'utf-8')
            if(username == ename and upassword == epass):
                login =1
                logging.info("User name and Password is correct")
                break
            rec = all_recs.fetch_row()
        if(login == 0):
            logging.error("User name and Password is not correct.. Please enter proper details")
            print("User name and Password is not correct.. Please enter proper details")
            
obj = UserBankData()
obj.validateData()
conn.close()





我的尝试:



我是python中的新手,我在python中写了代码。当我运行代码时,它没有给出任何错误,但它没有调用类函数validateData()。



What I have tried:

I am new in python and i wrote giving code in python. When i run code it is not giving any error but it not calling class function validateData().

推荐答案

可能是因为你对 sys的调用。 exit()没有缩进,因此不是异常处理程序的一部分,而是在try / except块之后立即执行。
Probably because your call to sys.exit() is not indented, so is not part of the exception handler, but executed immediately after the try/except block.


这篇关于无法调用类函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆