|这个作业属于哪个课程|https://edu.cnblogs.com/campus/besti/2021-2022-1fois
|这个作业要求在哪里|https://www.cnblogs.com/rocedu/p/9577842.html#WEEK09
|这个作业的目标|<操作系统责任
内存与进程管理
分时系统
CPU调度
文件、文件系统
文件保护
磁盘调度>
|作业正文|
《计算机科学概论》
《看漫画学python》
f = open('test.txt', 'w+') f.write('World') print('1.创建test.txt文件,World写入文件') f = open('test.txt', 'r+') f.write('Hello') print('2.打开test.txt文件,Hello覆盖文件内容') f = open('tset.txt','a') f.write(' ') print(r'3.打开test.txt文件,在文件尾部追加空格" "') fname = 'C:/Users/Lenovo/Desktop/py/test.txt' f = open(fname, 'a+') f.write('World') print('4.打开test.txt文件,在文件尾部追加World') f_name ='test.txt' f = None try: f = open(f_name) print('打开文件成功') content = f.read() print(content) except FileNotFoundError as e: print('文件不存在,请先使用ch12_1.py程序创建文件') except OSError as e: print('处理OSError异常') finally: if f is not None: f.close() print('关闭文件成功') f_name = 'test.txt' with open(f_name) as f: content = f.read() print(content) f_name = 'src_file.txt' with open(f_name, 'r', encoding='gbk') as f: lines = f.readlines() copy_f_name = 'dest_file.txt' with open(copy_f_name, 'w', encoding='utf-8') as copy_f: copy_f.writelines(lines) print('文件复制成功') f_name = 'logo.png' with open(f_name, 'rb') as f: b = f.read() copy_f_name = 'logo2.png' with open(copy_f_name, 'wb') as copy_f: copy_f.write(b) print('文件复制成功') import threading t = threading.current_thread print(t.name) print(threading.active_count()) t = threading.main_thread() print(t.name) import time def thread_body(): t = threading.current_thread() for n in range(5): print('第{0}次执行线程{1}'.format(n,t.name)) time.sleep(2) print('线程{0}执行完成!'.format(t.name)) class SmallThread(threading.Thread): def __int__(self, name=None): super().__init__(name=name) def run(self): t = threading.current_thread() for n in range(5): print('第{0}次执行线程{1}'.format(n, t.name)) time.sleep(2) print('线程{0}执行完成!'.format(t.name)) t1 = SmallThread() t2 = SmallThread(name='Mythread') t1.start() t2.start() value = [] def thread_body(): print('t1子线程开始...') for n in range(2): print('t1子线程执行...') value.append(n) time.sleeap(2) print('t1子线程结束。') print('主线程开始执行...') t1 = threading.Thread(target=thread_body) t1.start() t1.join() print('value = {0}'.format(value)) print('主线程继续执行...') import threading import time isrunning = True def workthread_body(): while isrunning: print('工作线程执行中...') time.sleep(5) print('工作线程结束。') def controlthread_body(): global isrunning while isrunning: command = input('请输入停止指令:') if command == 'exit': isrunning = False print('控制线程结束。') workthread = threading.Thread(target=workthread_body) workthread.start() controlthread = threading.Thread(target=controlthread_body) controlthread.start() import threading import time import urllib.request isrunning = True def workthread_body(): while isrunning: print('工作线程执行下载任务...') download() time.sleep(5) print('工作线程结束。') def controlthread_body(): global isrunning while isrunning: command = input('请输入停止指令:') if command == 'exit': isrunning= False print('控制线程结束。') def download(): url = 'http://localhost:8080/NoteWebService/logo.png' reg = urllib.request.Request(url) with urllib.request.urlopen(url) as response: data = response.read() f_name = 'download.png' with open(f_name, 'wb') as f: f.write(data) print('下载文件成功') workthread = threading.Thread(target=workthread_body) workthread.start() controlthread = threading.Thread(target=controlthread_body) controlthread.start()
代码行数(新增/累积) | 博客量(新增/累积) | 学习时间(新增/累积) | 重要成长 | |
---|---|---|---|---|
目标 | 5000行 | 30篇 | 400小时 | |
第一周 | 150/150 | 2/2 | 20/20 | |
第二周 | 150/300 | 2/4 | 18/38 | |
...... | ...... | ...... | ...... | |
第九周 | 600/2000 | 3/19 | 20/160 |