Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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)
share
add comment (requires an account with 50 reputation)

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.