从另一个python文件为Google表格建立索引会返回“无”,但是单元格中有数据

时间:2019-03-30 20:47:11

标签: python python-2.7 gspread

我在Leaderboard.py中定义了两个函数,insertData(xpos,ypos,data)和indexThing(row,column)。尽管我可以使用插入数据功能插入数据,但无法在server.py中为值建立索引。我尝试使用设置值直接在server.py中建立索引,但仍然收到“无”。我该如何解决此问题?

server.py:

from flask import Flask, request, render_template
import leaderboard
app = Flask(__name__)

@app.route("/script", methods=['POST'])
def script():
    input_string = request.form['data']
    chose = input_string[:-4]
    chose = chose.replace('http://10.0.1.36:5000/static/images/Girls/', 'G')
    chose = chose.replace('http://10.0.1.36:5000/static/images/Boys/', 'B')

    print (leaderboard.indexThing(22,3)) ##THIS RETURNS NONE  

    if 'G' in chose:
        chose = int(chose[1:len(chose)])
        print chose
        total = leaderboard.indexThing(chose, 3)
        wins = leaderboard.indexThing(chose, 4)
        print wins ##THIS RETURNS NONE 
        print total ##THIS RETURNS NONE 
    elif 'B' in chose:
        chose = int(chose[1:len(chose)])
        print chose
        total = leaderboard.indexThing(chose, 12)
        wins = leaderboard.indexThing(chose, 13)
        print wins ##THIS RETURNS NONE 
        print total ##THIS RETURNS NONE 
    return "backend response"

@app.route('/')
def static_page():
    return render_template('index.html')

@app.route('/boys.html')
def static_page2():
    return render_template('boys.html')

@app.route('/girls.html')
def static_page3():
    return render_template('girls.html')

if __name__ == "__main__":
    app.run(host='10.0.1.36', port=5000, debug=True)

leaderboard.py

#coding=utf-8
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('static/client_secret.json', scope)
client = gspread.authorize(creds)
sheet = client.open('Rate data').sheet1

def insertData(xpos, ypos, data):
    sheet.update_cell(xpos, ypos, data)

def indexThing(row, column):
    sheet.cell(row, column).value

1 个答案:

答案 0 :(得分:0)

确保所有不同的python函数中的所有类型都是一致的。 Google表格也是如此。

例如,对于这一行,我会尝试;

sheet.cell(int(row), (int)column).value

还要确保您实际上从sheet.cell调用中获得了返回值。例如,什么是

sheet.cell(int(row), (int)column)

您期望的是什么吗?