如何修复TypeError:'str'对象不可调用

时间:2019-04-03 16:07:25

标签: python

我正在调用Flask另一个Python文件中定义的Python函数,该函数会发送一个字符串,并将其分配给全局变量。然后tabPage.Controls.Add(geckoWebBrowser1); 将全局变量发送到HTML文件。

但是它给出了render_template。我如何解决它?

TypeError: 'str' object is not callable

@app.route('/agricul', methods=["post"]) def agricul(): global summarry summarry = check.summary() print(summarry) return render_template('summary.html', sum=summarry) `

check.py

2 个答案:

答案 0 :(得分:2)

此函数本身会“破坏”:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication41
{
    public partial class Form1 : Form
    {
        DataTable dt = null;
        public Form1()
        {
            InitializeComponent();

            dt = new DataTable();
            dt.Columns.Add("ID", typeof(int));
            dt.Columns.Add("Parent_ID", typeof(int));
            dt.Columns.Add("Name", typeof(string));

            dt.Rows.Add(new object[] {1, 0, "Apple"});
            dt.Rows.Add(new object[] {2, 0, "Pear"});
            dt.Rows.Add(new object[] {3, 2, "Grapes"});
            dt.Rows.Add(new object[] {4, 3, "Banana"});

            TreeNode node = new TreeNode("Root");
            treeView1.Nodes.Add(node);
            int parentID = 0;
            MakeTree(parentID, node);

            treeView1.ExpandAll();
        }

        public void MakeTree(int parentID, TreeNode parentNode)
        {
            foreach(DataRow row in dt.AsEnumerable().Where(x => x.Field<int>("Parent_ID") == parentID))
            {
                string name = row.Field<string>("Name");
                int id = row.Field<int>("ID");
                TreeNode node = new TreeNode(name);
                parentNode.Nodes.Add(node);
                MakeTree(id, node);

            }
        }
    }
}

调用def summary(): global summary summary='hello world' return summary 时,赋值summary()将函数替换为字符串summary='hello world'

换句话说,您只能调用一次该函数,然后不再调用该函数。

目前尚不清楚为什么要使用全局变量,但是如果您急需一个全局变量,还需要重命名变量或函数。

一个更常见的实现看起来像

'hello world'

答案 1 :(得分:0)

NSDecimalNumber与check.py中的函数同名。我认为python与check.summary混淆,后者是一个字符串?

相关问题