[英]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.