Home > other >  Python, gspread. How i can cut or parse my list
Python, gspread. How i can cut or parse my list

Time:10-05

when i use "worksheets" function from gspread package i obtain the list, but this list containt not only string type. how i can obtaint only string? There 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 list with only names, but i dont understand how i can do that.

CodePudding user response:

Use list comprehension to get the title for each worksheet object in the list

[x.title for x in sheet_list]

or map with a lambda function

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