从另一个python文件索引google工作表会返回'none',但是单元格中包含数据

问题描述 投票:0回答:1

我在leaderboard.py,insertData(xpos,ypos,data)和indexThing(row,column)中定义了两个函数。虽然我能够使用插入数据函数插入数据,但我无法索引server.py中的值。我已经尝试使用设置值直接在server.py中进行索引,但仍然收到“无”。我该如何解决此问题?

server.朋友:

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.朋友

#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
python python-2.7 gspread
1个回答
0
投票

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

例如,对于这条线,我会尝试;

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

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

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

这是你期待的吗?

© www.soinside.com 2019 - 2024. All rights reserved.