wcm2020 12

  • Home
    • Site Map
    • reveal
    • blog
  • HOME
  • 每周上課內容
  • 上課內容整理
    • W10
      • Python程式
      • CSV
    • W12
      • 建立虛擬主機
    • W14
      • MBR與GPT
      • BIOS與UEFI
    • W15
      • 利用Pypdf2來切割PDF檔
    • W16
      • 何謂wsgi
    • W17
      • PDF網際分割與合併程式
      • 何謂 API
      • 何謂 URI
      • 何謂 URL 、 URN
  • 錯誤修正
    • 命令列無法使用pip下載程式
  • 操作步驟教學
    • 如何建網頁
    • 如何使用SSH維護倉儲
    • 如何安裝虛擬主機
    • 如何使用leo編輯Palican
    • 如何在虛擬主機上clone倉儲
W10 << Previous Next >> CSV

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()

W10 << Previous Next >> CSV

Copyright © All rights reserved | This template is made with by Colorlib