I have a method GetEmpID
that takes up to two optional arguments: lastname
, and firstname
. It handles cases where either lastname
or firstname
are None
, or when neither are None
.
When sending the contents of a WxPython TextCtrl to the method, even if one of the fields are empty, TextCtrl.GetValue()
does not return None
, but instead the blank unicode string u''
I can change the logic in my simple method to check for empty unicode strings, but I feel that the change would be best handled in the method that calls GetEmpID
from the GUI interface.
I've made it work using this code, but it seems clunky and repetitive. Can it be improved?
def GetByName(self):
lname = None
fname = None
if not self.txtlname.IsEmpty():
lname = self.txtlname.GetValue()
if not self.txtfname.IsEmpty():
fname = self.txtfname.GetValue()
result = self.emplu.GetEmpID(lname, fname)