设计一个基于Linux的教学课程,以帮助学生掌握 →
课程分为8个模块,每个模块包括实践活动和课后作业。
掌握程序:【了解】
掌握程序:【熟练】
掌握程序:【熟练】
掌握程序:【熟练】
掌握程序:【熟练】
掌握程序:【了解】
掌握程序:【熟练】
grep -i不区分大小写 -w匹配单词 -E多项匹配 -r递归匹配 -l只显示匹配的文件名 按名字匹配 find . -iname “test*” 按时间匹配 find . -type f -ctime +5 -ctime -10 按类型匹配 find . -type d|l|f 按大小匹配 find . -type f -size +100M -size -500M 按用户匹配 find . -type f -user shaohy
对结果再做处理 find . -iname “test*” | xargs -i ls -al {}
掌握程序:【熟练】
前后左右 (hjkl, w, b) 行首行尾 (0,$) 开头结尾 (gg, G) 插入编辑 (o, O, i, a, s) 搜索替换 (/, ?) 回撤重做 (u, ctrl+r) 复制粘贴删除 (y, p, d, c, x, yy, dd, cc, yw, cw, dw) 上翻下翻 (c+f, c+b, c+e, c+y) 保存退出 (esc, :wq, ZZ)
掌握程序:【了解】
#!/bin/sh while read line;do name=$(echo $line | awk -F, '{print $1}') xinbie=$(echo $line | awk -F, '{print $2}') if [ $xinbie == "男" ];then xinbie="先生" else xinbie="女士" fi sed -r -n "s@name@$name@g; s@sex@$xinbie@g; p" 邀请.txt done < 会议名单.csv
掌握程序:【熟练】
ipv4.method
Device: enps0p1 (ifname) IP address:172.25.0.11 (ip4) Netmask:255.255.255.0 (ip4) Gateway:172.25.0.254 (gw4) Name server:172.25.254.254 (ipv4.dns)
python -m SimpleHTTPServer 8000
[Unit] Description=LVS and VRRP High Availability Monitor After=neutron-l3-agent Wants=network-online.target [Service] Type=forking PIDFile=/var/run/keepalived.pid KillMode=process EnvironmentFile=-/etc/sysconfig/keepalived ExecStartPre=/bin/sleep 3 ExecStartPre=-/etc/keepalived/check_vip.sh config ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure [Install] WantedBy=multi-user.target
课程结束后,学生将掌握Linux的基本操作和概念,为进一步学习Linux相关技能打下坚实的基础。
from random import choice from datetime import datetime, timedelta debug = True class Person(): def __init__(self): nick = self.GetList("/Users/shaohy/Desktop/nick.txt", 0) name = self.GetList("/Users/shaohy/Desktop/name.txt", 0) province = self.GetList("/Users/shaohy/Desktop/sheng.txt", 4) self.fullname = f"{choice(nick)}{choice(name)}" self.sex = choice(["男", "女"]) self.prov = choice(province) def GetName(self): return f"{self.fullname}" def GetSex(self): return f"{self.sex}" def GetProv(self): return f"{self.prov}" def GetList(self, filename, length): with open(filename, "r", encoding="utf-8") as f: result = [ line.strip().split(":")[0] for line in f if len(line) > length ] return result def make_invite(name, sex): invite_txt=''' 尊敬的 name (sex): 欢迎参加我们的会议!! 敬礼 ''' # today_date = time.strftime(('%Y%m%d_%H%M%S'), time.localtime()) #time.localtime()用于生成当前时间 today_date = datetime.strftime(datetime.now() + timedelta(days=7), "%Y-%m-%d") invite_txt2 = invite_txt.replace("name", name).replace("sex", "先生" if sex == "男" else " 女士") with open(f"/Users/shaohy/Desktop/invite_{name}_{today_date}.txt", "w+") as f: f.write(invite_txt2) print(f"{name}的邀请已经完成。") try: with open("/Users/shaohy/Desktop/会议名单.csv", "w+") as f: for i in range(100): person = Person() fullname = f"{person.GetName()}, {person.GetSex()}, {person.GetProv()}" f.write(fullname + "\r\n") make_invite(person.GetName(), person.GetSex()) except Exception as e: print(e) finally: print("啥事也没有")
import xlwings as xw from docx import Document from docx.oxml.ns import qn from docx.shared import Pt,RGBColor def write_invite(name, sex): document = Document() document.styles['Normal'].font.name = u'宋体' document.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体') document.styles['Normal'].font.size = Pt(10.5) document.styles['Normal'].font.color.rgb = RGBColor(0,0,0) Head = document.add_heading('', level=0) # 插入标题 run = Head.add_run("邀请函") run.font.name=u'微软雅黑' run.font.color.rgb = RGBColor(255,0,0) run._element.rPr.rFonts.set(qn('w:eastAsia'), u'Cambria') paragraph = document.add_paragraph('尊敬的 ') # 插入段落 paragraph.add_run(name).bold = True # 正文 paragraph.add_run(f" ({sex})").italic = True document.add_heading('\t\t欢迎参加狂欢节!', level=1) # 插入标题 1 ''' document.add_paragraph('Intense quote', style='Intense Quote') # 插入段落,明显引用 document.add_paragraph('first item in unordered list', style='List Bullet') # 插入段落,无序列表 document.add_paragraph('first item in ordered list', style='List Number') # 插入段落,有序列表 records = ( (3, '101', 'Spam'), (7, '422', 'Eggs'), (4, '631', 'Spam, spam, eggs, and spam') ) table = document.add_table(rows=1, cols=3) # 插入表格 hdr_cells = table.rows[0].cells hdr_cells[0].text = 'Qty' hdr_cells[1].text = 'Id' hdr_cells[2].text = 'Desc' for qty, id, desc in records: row_cells = table.add_row().cells row_cells[0].text = str(qty) row_cells[1].text = id row_cells[2].text = desc ''' document.add_page_break() # 插入分页 document.save(f"invite_{name}.docx") # 保存 try: wb = xw.Book(r"/Users/shaohy/Desktop/会议名单.xls") sheet = wb.sheets[0] # 选择第0个表单 for i in range(1,10): name = sheet.range(i,1).value.strip() sex = sheet.range(i, 2).value.strip() sex = "先生" if sex == "男" else "女士" write_invite(name, sex) except Exception as e: raise(e)
Beautiful Soup是一个功能强大的解析库,可以用于从HTML或XML文件中提取数据。它提供了灵活的API,可以用于搜索、修改和遍历文档树结构。
import re from bs4 import BeautifulSoup import urllib.request as urllib2 url = "http://www.baidu.com" response1 = urllib2.urlopen(url) html_doc = response1.read() #创建一个BeautifulSoup解析对象 soup = BeautifulSoup(html_doc,"html.parser",from_encoding="utf-8") #获取所有的链接 links = soup.find_all('a') for link in links: if link.get('href', None) != None: print(f"{link['href']}")
lxml是基于C编写的库,速度较快。它使用了libxml2和libxslt库作为底层,支持XPath和CSS选择器,可以高效地解析和处理XML和HTML文档。
html.parser是Python标准库中内置的解析库,用于解析和处理HTML文档。它虽然功能相对较弱,但是由于是内置库,使用起来非常方便。
from machine import Pin from time import sleep, sleep_ms from umqtt.simple import MQTTClient ssid = "总有刁民想连朕的热点" passwd = "13870143008" client_id = "esp32-chenfc" mqtt_server = "devops.upyun.com" mqtt_user = "shaohy" mqtt_pass = "upyun.com" topic_sub = "online/#" topic_pub = "online/chenfc" last_message = 0 message_interval = 30 def wifi_connect(): import network wlan = network.WLAN(network.STA_IF) wlan.active(True) while not wlan.isconnected(): print("正在努力连接 wifi 热点。。。。") wlan.connect(ssid, passwd) sleep(3) print("WiFi Network Info: ", wlan.ifconfig()) do_ledon(100) def do_ledon(step=15): import neopixel np = neopixel.NeoPixel(Pin(8), 8, bpp=3) for r in range(0, 256, step): for g in range(0, 256, step): for b in range(0, 256, step): np[0] = (r, g, b) np.write() sleep_ms(10) def sub_cb(topic, msg): msgarray = msg.split() if msgarray[0] == b"online": if len(msgarray) > 1: do_ledon(int(msgarray[1])) else: do_ledon() def connect_and_subscribe(): global client_id, mqtt_server, topic_sub wifi_connect() client = MQTTClient(client_id, mqtt_server, user=mqtt_user, password=mqtt_pass) client.set_callback(sub_cb) client.connect() client.subscribe(topic_sub) print('Connected to %s MQTT broker, subscribed to %s topic' % (mqtt_server, topic_sub)) return client if __name__ == '__main__': try: client = connect_and_subscribe() while True: client.check_msg() if (time() - last_message) > message_interval: msg = b'online' client.publish(topic_pub, msg) do_ledon(50) last_message = time() except Exception as e: print(e)