W8 <<
Previous Next >> W11-W13
W10
Python and Flask
測試使用Python程式取出表單中學號以及對應成績
import csv
# read student list
filename = 'D:/1a/1alist.txt'
with open(filename, encoding="utf-8") as f:
content = f.readlines()
student = [x.strip() for x in content]
#print(content)
#print(student)
# Timestamp, email, ????, url, score, desp, memo
# 0, 1, 2, 3, 4, 5, 6
#total = 0
all = {}
with open('D:/1a/1a.csv', encoding="utf-8") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
if line_count == 0:
#print(f'Column names are {", ".join(row)}')
line_count += 1
else:
student_num = row[1].split("@")[0]
#print(student_num)
student_score = row[4]
#print(student_score)
try:
all.update({student_num: student_score})
except:
all.update({student_num: "error"})
#print(f'\t{row[0]} works in the {row[1]} department, and was born in {row[2]}.')
#print(f'\t{row[4]}')
#total += int(row[4])
line_count += 1
#print(all)
#print(student)
for i in student:
#if i in all:
#pass
#else:
#print(str(i))
try:
print(i + "\t" + all[i])
except:
print(i + "\t60")
#print(f'Processed {line_count} lines.')
#print("??=" + str(total/line_count))
基本Flask
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, From Flask!'
if __name__== '__main__':
app.run()
以此為基本再進行延伸。
W8 <<
Previous Next >> W11-W13
Copyright © All rights reserved | This template is made with by Colorlib