简体   繁体   English

Python,gspread。 我如何剪切或解析我的列表

[英]Python, gspread. How i can cut or parse my list

when I use the worksheets() function from gspread package I obtain the list, but this list contains not only string type.当我使用 gspread package 中的worksheets() gspread时,我获得了该列表,但该列表不仅包含字符串类型。 how can I obtain only string?我怎样才能只获得字符串? Here is my code:这是我的代码:

import gspread


cred = gspread.service_account(filename="creds.json")
sheet = cred.open("nameoftable")
sheet_list = sheet.worksheets()
print(sheet_list)

Out data> [<Worksheet 'Name 0' id:0>, <Worksheet 'Name 1' id:298444145>, <Worksheet 'Name 2' id:1037339372>, <Worksheet 'Name 3' id:1556601152>, <Worksheet 'Name 4' id:2041525675>, <Worksheet 'Name 5' id:1830132413>]

I need a list with only names, but I don't understand how I can do that.我需要一个只有名字的列表,但我不明白我该怎么做。

Use list comprehension to get the title for each worksheet object in the list使用列表理解获取列表中每个工作表 object 的title

[x.title for x in sheet_list]

or map with a lambda function或 map 与 lambda function

list(map(lambda x: x.title, sheet_list))

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

相关问题 pyinstaller 无法使用 gspread 制作正确的 exe 文件。 ModuleNotFoundError:没有名为“gspread”的模块 - pyinstaller can't make correct exe file with gspread. ModuleNotFoundError: No module named 'gspread' Python:我如何解析这个列表? - Python: How can I parse this list? 我无法在Python 3上使用gspread授权 - I can`t authorize with gspread on Python 3 (gspread) 如何使用 gspread 将自定义公式放入单元格中? - (gspread) How can I put a custom formula into a cell using gspread? Gspread - 如何在不超过配额限制的情况下一次格式化多个单元格? - Gspread - How can I format many cells at once without exceeding my quota limit? Python/gspread - 如何一次更新具有不同值的多个单元格? - Python/gspread - how can I update multiple cells with DIFFERENT VALUES at once? Python/Gspread 如何在创建工作表时添加列名? - Python/Gspread How can I add column names while creating a worksheet? python df2gspread.d2g.upload:如何上传数据类型为 integer 的 datefram 列 - python df2gspread.d2g.upload: How can I upload datefram column with data type integer Python:如何在列表中使用过滤器进行双重解析? - Python: How I can do a double parse in a list with a filter in the middle? 如何将托管在 GitHub 上的 JavaScript 数组解析为 Python 列表? - How can I parse a JavaScript array hosted on GitHub into a Python list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM