简体   繁体   English

无法读取标题中有空格的 Sharepoint 列表项

[英]Not able to read Sharepoint list items which has blanks in its headers

I am using Sharepoint online to fetch the data from the list.我正在使用 Sharepoint 在线从列表中获取数据。 For that I have written below code:为此,我编写了以下代码:

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.runtime.auth.user_credential import UserCredential


baseurl = 'https://my.org.com'
basesite = '/teams/ia/Powerappsdatabase/' # every share point has a home.
siteurl = baseurl + basesite
sp_list = "HCFM_Projects"
ctx = ClientContext(siteurl).with_credentials(UserCredential("id@org.com", "password"))
sp_lists = ctx.web.lists
s_list = sp_lists.get_by_title(sp_list)
l_items = s_list.get_items()
ctx.load(l_items)
ctx.execute_query()

for item in l_items:
    print(item.properties['Title'], item.properties['Owner'], item.properties["Status"])

For the headers in the sharepoint list which contains like single word in header it is populating values but which headers have space in it like "Project ID", "Process Owner".对于共享点列表中的标题,它在标题中包含类似的单个单词,它正在填充值,但哪些标题中有空格,如“项目 ID”、“流程所有者”。 It is giving error KeyError: 'Project ID' .它给出了错误KeyError: 'Project ID'

Can somebody help me to know how we can get values for those headers which have space in their names or underscore(i tried to replace space with underscore still not working) or can we print l_items to know how it is saving column headers with space or underscore.有人可以帮助我了解如何获取名称或下划线中有空格的标题的值(我尝试用下划线替换空格仍然无效),或者我们可以打印l_items以了解它如何使用空格保存列标题或下划线。

Hi i got the answer for it.嗨,我得到了答案。 If you have space or underscore in headers just write without space in header for example:-如果标题中有空格或下划线,则只需在标题中没有空格的情况下写入,例如:-

for item in l_items:
    print(item.properties['ProjectID'], item.properties['ProcessOwner'])

This worked for me.这对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python:有空格的列之间的时间差,导致错误 - Python: time difference between columns which has blanks, causes error 包含多个项目的一个元组的列表 - List of one tuple which has multiple items inside 列表项的共享点筛选器(GetListItems) - Sharepoint Filter for List Items(GetListItems) Python Sharepoint读取列表VIEW - Python Sharepoint Read List VIEW 无法读取图像路径。 AttributeError:“列表”对象没有属性“读取” - Not able to read the image path. AttributeError: 'list' object has no attribute 'read' 匹配具有基于特定列表的字典项的列表以返回修改后的列表 - Matching a List which has dictionary items based on a specific list to return a modified list Python 中哪种类型的可迭代/列表能够在结构上共享以前可迭代/列表中的相同项目? - Which type of iterable/list in Python is able to structurally share the same items from previous iterables/lists? 删除列表中没有出现在另一个列表中的子串的项目的优雅方法 - Elegant way to delete items in a list which do not has substrings that appear in another list 从列表中创建一个子列表,该列表的最小和最大元素之间的正差最小 - make a sub-list from a list which has minimum positive difference between its minimum and maximum elements 对于 header in headers.items(): AttributeError: 'set' object has no attribute 'items' - for header in headers.items(): AttributeError: 'set' object has no attribute 'items'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM