拆分名字和姓氏

时间:2013-09-06 13:26:17

标签: python split

所以,我发现了这个主题:Separate first, middle and last names (Python),我试图根据我对OpenERP的需求调整代码。

我现在这个:

class get_the_name(object):
            def __init__(self, fullname):
                self.full = fullname
                s = self.full.split()

                try:
                    self.first = " ".join(s[:2]) if len(s[0]) == 1 else s[0]
                    s = s[len(self.first.split()):]

                    self.middle = " ".join(s[:2]) if len(s[0]) == 1 else s[0]
                    s = s[len(self.middle.split()):]

                    self.last = " ".join(s[:2]) if len(s[0]) == 1 else s[0]
                finally:
                    pass
class class_A(osv.osv):

    _name = 'classA.classA'
    _rec_name = 'name_of'
    _columns = {
        'name_of':fields.char('Name:', size = 10),
            'description_':fields.char('Description:', size = 10),
            'first_last':fields.function(get_the_name("Just testing this").first, method = True, string = "Split Name", type = "char", size = 50),
    }
class_A()

虽然这给了我错误信息:

  

AttributeError:'str'对象没有属性'func_name'

即使这有话,我也不想这样。而不是功能:

'first_last':fields.function(get_the_name("Just testing this").first, method = True, string = "Split Name", type = "char", size = 50),

我希望它是:

'first_last':fields.function(get_the_name(name_of).first, method = True, string = "Split Name", type = "char", size = 50),

我怎样才能做到这一点?

0 个答案:

没有答案