gdata.data.PhoneNumber:如何获取电话号码的类型



使用gdata.data.PhoneNumber类,如何获取该电话号码的类型(家庭/企业/手机等)?

这是我参考的文件:https://gdata-python-client.googlecode.com/hg/pydocs/gdata.data.html#PhoneNumber

您应该查找"rel"属性。这是来自的示例代码https://github.com/google/gdata-python-client/blob/master/tests/gdata_tests/contacts/service_test.py:

# Create a new entry
new_entry = gdata.contacts.ContactEntry()
new_entry.title = atom.Title(text='Elizabeth Bennet')
new_entry.content = atom.Content(text='Test Notes')
new_entry.email.append(gdata.contacts.Email(
    rel='http://schemas.google.com/g/2005#work',
    primary='true',
    address='liz@gmail.com'))
new_entry.phone_number.append(gdata.contacts.PhoneNumber(
    rel='http://schemas.google.com/g/2005#work', text='(206)555-1212'))
new_entry.organization = gdata.contacts.Organization(
    org_name=gdata.contacts.OrgName(text='TestCo.'), 
    rel='http://schemas.google.com/g/2005#work')

它不访问"rel"属性,但它在那里,我发誓:)

一旦你得到一个PhoneNumber实例,你就可以用内置的dir()函数打印每个属性:

print(dir(phone_number))

以下是"rel"的列表(https://github.com/google/gdata-python-client/blob/master/src/gdata/data.py)。我不知道所有这些是否都适用于电话号码,但它可能对检查类型有用:

FAX_REL = 'http://schemas.google.com/g/2005#fax'
HOME_REL = 'http://schemas.google.com/g/2005#home'
HOME_FAX_REL = 'http://schemas.google.com/g/2005#home_fax'
ISDN_REL = 'http://schemas.google.com/g/2005#isdn'
MAIN_REL = 'http://schemas.google.com/g/2005#main'
MOBILE_REL = 'http://schemas.google.com/g/2005#mobile'
OTHER_REL = 'http://schemas.google.com/g/2005#other'
OTHER_FAX_REL = 'http://schemas.google.com/g/2005#other_fax'
PAGER_REL = 'http://schemas.google.com/g/2005#pager'
RADIO_REL = 'http://schemas.google.com/g/2005#radio'
TELEX_REL = 'http://schemas.google.com/g/2005#telex'
TTL_TDD_REL = 'http://schemas.google.com/g/2005#tty_tdd'
WORK_REL = 'http://schemas.google.com/g/2005#work'
WORK_FAX_REL = 'http://schemas.google.com/g/2005#work_fax'
WORK_MOBILE_REL = 'http://schemas.google.com/g/2005#work_mobile'
WORK_PAGER_REL = 'http://schemas.google.com/g/2005#work_pager'
NETMEETING_REL = 'http://schemas.google.com/g/2005#netmeeting'

那些OTHER的"rel"可以(或者可能应该?)与对象的"label"属性连接。

相关内容

  • 没有找到相关文章

最新更新