NFU-MDE-40823108-KAO,YU-CHE-cd2021

  • Home
    • Site Map
    • reveal
    • blog
  • Introduction
  • KMOLab basis
    • Cmsimde create
    • Python program
    • SSH key produce
    • SSH putty settings
    • Leo Edit Blog
    • Leo Edit Reveal
    • Synergy
  • Coppeliasim basic
    • Import objects
    • Divide object
    • Appearance setting
    • Joint settings
    • Orchestration objects
    • Proximity sensor
  • Midterm
    • W1
    • W2
    • W3
      • work
    • W4
    • W5
    • W6
    • W7
    • W8
    • W9
  • Final
    • W10-task1
    • W11-task2
    • W12-task3
    • W13
    • W14
    • W15
    • W16
    • W17
    • W18
  • Stage1-ag1
  • Stage2-ag1
  • Stage3-ag1
  • phone webcam
    • ios for Webcam
    • Android for Webcam
  • Github sever issue
Final << Previous Next >> W11-task2

W10-task1

利用國立虎尾科技科技大學機械設計工程系cd2021下的task1進行作業。

讀取 stage3_2a.txt, 建立 Stage3 的分組倉儲, 分組網頁, 以及各組員倉儲及網頁連結.

已知 stage3_2a.txt內容, 以及初步資料讀取程式:

程式碼(version1): 

# open file, default is read mode, since txt content no chinese char4
# no encoding = "UTF- 08" is needed
with open("stage3_2a.txt") as fh:
    # readlines will read into the whole line and put into list format 23
    # has \n at the end of each line 13
    data = fh.readlines()
#print(len(data))1
for i in range(len(data)):
    group = data[i].rstrip("\n").split("\t")
    print('<p>'+group[0]+'|<a href="https://'+group[1]+'.github.io/stage3-ag'+group[0][9]+'">網站</a>|<a href="https://github.com/'+group[2]+'/stage3-ag'+group[0][9]+'">倉儲</a></p>')
    for j in range(2,18,2):
        print('<p>'+group[j]+'|Website:'+'<a href="https://'+group[j]+'.github.io/cd2021'+'">'+group[j]+'</a>'+'|Repository:'+'<a href="https://github.com/'+group[j]+'/cd2021'+'">'+group[j]+'</a></p>')

version1程式中檔案資料夾 stage3_2a.txt 其中學號有誤,會導致排序有誤。

程式碼(version2):

# open file, default is read mode, since txt content no chinese char4
# no encoding = "UTF-08" is needed
with open("stage3_2a.txt") as fh:
    # readlines will read into the whole line and put into list format 23
    # has \n at the end of each line 13
    data = fh.readlines()
    data = [a.replace('4823122','40823122') for a in data]
    data = [c.replace('\t\t\t\t','') for c in data]
    print(data)
#print(len(data))1
for i in range(len(data)):
    group = data[i].rstrip("\n").split("\t")
    print('<p>'+group[0]+'|<a href="https://'+group[1]+'.github.io/stage3-ag'+group[0][9]+'">網站</a>|<a href="https://github.com/'+group[2]+'/stage3-ag'+group[0][9]+'">倉儲</a></p>')
# the following will use group data to generate needed html
  
    for j in range(2,18,2):
        try:
            print('<p>'+group[j]+'|Website:'+'<a href="https://'+group[j]+'.github.io/cd2021'+'">'+group[j]+'</a>'+'|Repository:'+'<a href="https://github.com/'+group[j]+'/cd2021'+'">'+group[j]+'</a></p>')
        except:
            continue

version2程式中字串 

with open("stage3_2a.txt") as fh:

字串為:

開啟檔案 stage3_2a

data = fh.readlines()

字串為:

用於讀取所有行(直到結束)並返回列表,該列表可以由Python的for... in ...結構進行處理。

如果碰到結束,則返回空字符串。

data = [a.replace('4823122','40823122') for a in data]

字串為:

把字符串中的old(舊字符串) 替換成new(新字符串),如果指定第三個參數max,則替換不超過max 次,等於把 "4823112" 換成 "40823112"

data = [c.replace('\t\t\t\t','') for c in data]

字串為:

('\t\t\t\t','')將排序出來的結果作空格

for i in range(len(data)):
    group = data[i].rstrip("\n").split("\t")

字串為:

分析檔案範圍有六組,進行迴圈,變數為i

將data列表中第i項,去除元素\n(換行)利用\t(空格)分割變成元素(逗號自動補上)

 print('<p>'+group[0]+'|<a href="https://'+group[1]+'.github.io/stage3-ag'+group[0][9]+'">網站</a>|<a href="https://github.com/'+group[2]+'/stage3-ag'+group[0][9]+'">倉儲</a></p>')

字串為:

group[0][9]=第0個第9位

用print依序索引group list 中的元素,放入html格式,依序列出

for j in range(2,18,2):

字串為:

從2開始每次跳2格最多跳到16不可超過18

try:
            print('<p>'+group[j]+'|Website:'+'<a href="https://'+group[j]+'.github.io/cd2021'+'">'+group[j]+'</a>'+'|Repository:'+'<a href="https://github.com/'+group[j]+'/cd2021'+'">'+group[j]+'</a></p>')
        except:
            continue

用print依序索引group list 中的元素,放入html格式,依序列出來

  差別在於這行取組員的但因為有一組只有6人超出範圍所以一定會error。

列出各分組倉儲, 分組網站與學員倉儲及學員網站連結:

stage3_ag1 | 網站 | 倉儲

40823131 | Website:40823131 | Repository:40823131 | Group Website:40823131

a40823112 | Website:a40823112 | Repository:a40823112 | Group Website:a40823112

40823123 | Website:40823123 | Repository:40823123 | Group Website:40823123

40823145 | Website:40823145 | Repository:40823145 | Group Website:40823145

40823136 | Website:40823136 | Repository:40823136 | Group Website:40823136

40823109 | Website:40823109 | Repository:40823109 | Group Website:40823109

40823116 | Website:40823116 | Repository:40823116 | Group Website:40823116

40823108 | Website:40823108 | Repository:40823108 | Group Website:40823108

stage3_ag2 | 網站 | 倉儲

40823151 | Website:40823151 | Repository:40823151 | Group Website:40823151

40623121 | Website:40623121 | Repository:40623121 | Group Website:40623121

40871106 | Website:40871106 | Repository:40871106 | Group Website:40871106

40823102 | Website:40823102 | Repository:40823102 | Group Website:40823102

40823104 | Website:40823104 | Repository:40823104 | Group Website:40823104

40823106 | Website:40823106 | Repository:40823106 | Group Website:40823106

40823101 | Website:40823101 | Repository:40823101 | Group Website:40823101

40823132 | Website:40823132 | Repository:40823132 | Group Website:40823132

stage3_ag3 | 網站 | 倉儲

40823119 | Website:40823119 | Repository:40823119 | Group Website:40823119

40823150 | Website:40823150 | Repository:40823150 | Group Website:40823150

40823103 | Website:40823103 | Repository:40823103 | Group Website:40823103

40823107 | Website:40823107 | Repository:40823107 | Group Website:40823107

40523252 | Website:40523252 | Repository:40523252 | Group Website:40523252

40823154 | Website:40823154 | Repository:40823154 | Group Website:40823154

stage3_ag4 | 網站 | 倉儲

40823142 | Website:40823142 | Repository:40823142 | Group Website:40823142

40823144 | Website:40823144 | Repository:40823144 | Group Website:40823144

40823127 | Website:40823127 | Repository:40823127 | Group Website:40823127

40823148 | Website:40823148 | Repository:40823148 | Group Website:40823148

40823121 | Website:40823121 | Repository:40823121 | Group Website:40823121

40823135 | Website:40823135 | Repository:40823135 | Group Website:40823135

40823114 | Website:40823114 | Repository:40823114 | Group Website:40823114

40823146 | Website:40823146 | Repository:40823146 | Group Website:40823146

stage3_ag5 | 網站 | 倉儲

40823111 | Website:40823111 | Repository:40823111 | Group Website:40823111

40823115 | Website:40823115 | Repository:40823115 | Group Website:40823115

40823128 | Website:40823128 | Repository:40823128 | Group Website:40823128

40823120 | Website:40823120 | Repository:40823120 | Group Website:40823120

40823140 | Website:40823140 | Repository:40823140 | Group Website:40823140

40823124 | Website:40823124 | Repository:40823124 | Group Website:40823124

40823139 | Website:40823139 | Repository:40823139 | Group Website:40823139

40823126 | Website:40823126 | Repository:40823126 | Group Website:40823126

stage3_ag6 | 網站 | 倉儲

40823152 | Website:40823152 | Repository:40823152 | Group Website:40823152

40823110 | Website:40823110 | Repository:40823110 | Group Website:40823110

40823122 | Website:40823122 | Repository:40823122 | Group Website:40823122

40823125 | Website:40823125 | Repository:40823125 | Group Website:40823125

40823117 | Website:40823117 | Repository:40823117 | Group Website:40823117

40823129 | Website:40823129 | Repository:40823129 | Group Website:40823129

40823149 | Website:40823149 | Repository:40823149 | Group Website:40823149

40823153 | Website:40823153 | Repository:40823153 | Group Website:40823153


Final << Previous Next >> W11-task2

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