【问题标题】:Syntax error while executing a python script to make a web application执行 python 脚本以创建 Web 应用程序时出现语法错误
【发布时间】:2019-10-16 00:56:44
【问题描述】:

这是我第一次使用 pycharm 和烧瓶库。我对高级编程相当陌生,我试图为我的程序创建一个可执行链接,但我遇到了语法错误。当我在空闲时运行相同的脚本而没有烧瓶功能并且没有 python IDLE 中的if __name__=="__main__": 行时,它会按预期工作。

from flask import Flask
import os
import csv
import sqlite3
import tkinter.filedialog
import pandas as pd
from tkinter import filedialog
from tkinter import *

app=Flask(__name__)
@app.route('/')

k=Tk()
k.filename =  filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("csv files","*.csv"),("all files","*.*")))
database=sqlite3.connect("C:\SQLiteStudio\data.db")
d=database.cursor()
task1="""CREATE TABLE z (
        date DATE ,
        time TIME ,
        value_1 DOUBLE PRECISION ,
        value_2 DOUBLE PRECISION ,
        final_value DOUBLE
    );"""
task2="""INSERT INTO z (date, time, value_1, value_2, final_value) VALUES (?,?,?,?,?)"""
#d.execute(task1)
out=pd.read_csv(k.filename, header=None)
print(len(out))
print(out.iloc[0])
row=1
if str(out.iloc[0,0])=='Date' and str(out.iloc[0,1])=='Time' and str(out.iloc[0,2])=='Lat' and str(out.iloc[0,3])=='Long' and str(out.iloc[0,4])=='Temp':
    while row< len(out):
        print(row)  
        d.execute(task2,out.iloc[row])
        database.commit()
        row+=1
else:
    print("The data is not in expected format.")
database.close()

if __name__=="__main__":
    app.run()
"C:\Users\Jay Paliwal\Desktop\Internship\venv\Scripts\python.exe" 
"C:/Users/Jay Paliwal/Desktop/Internship/task 1.py"
File "C:/Users/Jay Paliwal/Desktop/Internship/task 1.py", line 13
        k=Tk()
        ^
    SyntaxError: invalid syntax

    Process finished with exit code 1

这是我得到的输出。我期待一个链接出现,当有人访问该链接时,会打开一个用于使用 tkinter 函数的对话框

【问题讨论】:

    标签: python flask web-applications pycharm


    【解决方案1】:

    你不能只拥有一个装饰器。装饰器需要声明一个函数。

    无论如何,您的代码都应该在函数中。

    (请注意,尝试在 Flask 应用程序中使用 tkinter 是没有意义的。你为什么在这里使用 Flask?)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 2021-05-08
      • 2022-01-26
      相关资源
      最近更新 更多