首页 > 解决方案 > 创建并选择同一个工作表

问题描述

在我的代码中 gspread 创建了一个新的统计工作表,名称为“Year__Month_Day_HourMinute_'XTeam'_vs'Yteam'”,我这样做是为了更容易找到合适的工作表。如何选择此表以供进一步使用。由于这个小程序将同时用于2-3场比赛(yay small time Ultimate frisbee)。任何想法?

我不能做一个简单的“worksheet = sh.sheet1”,因为我不知道# 会是什么。我的解决方案是省略名称的分钟,这样会更容易,只需将名称创建者代码部分复制粘贴到选择代码部分,但我希望会有更好的解决方案。

on_press: root.worksheet = root.np.add_worksheet(title=str(root.localtime.year) + "_" + str(root.localtime.month) + "_" + str(root.localtime.day) + "_" + str(root.localtime.hour) + str(root.localtime.minute) + spinner1_id.text + "_vs_" + spinner2_id.text, rows ="100", cols= "20")

标签: pythongspread

解决方案


I would not recommend using a title that varies like that, as you have to dig all that data back up just to form a search for it. I would use only 3 Varying points in your title at most, such as 'DATE_xTEAM_yTEAM'. DATE would be a STRING value such as "042318" where you can split each element from the string (MONTHDAYYEAR).

This is a method I would personally do for accessing the data easier: Manifest a JSON file which includes a DICTIONARY of all the spreadsheets (titles) ever created. The KEY would be a NUMBER (1) and the value would be the title. So if you wanted to find the second game in the season, create a small python script that (using 'import json') would find the value for that key. Basically a dictionary is the best way to organize the titles.

-Ryan


推荐阅读