diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..9bd1038ee62cb0cb284945a5b7a1bd7dc09cb5cd --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/python-demo.iml b/.idea/python-demo.iml index ec63674cd7f4d511fb06cd63eaeba166d6bc0dd8..8b8c395472a5a6b3598af42086e590417ace9933 100644 --- a/.idea/python-demo.iml +++ b/.idea/python-demo.iml @@ -1,5 +1,10 @@ - + + + + + + - + + + + + + + + + + + + - - - + + + + + + + + + + + + - @@ -104,8 +138,8 @@ - - + + - + - + - + - + + + + - - - - - + + + + + - @@ -258,7 +315,11 @@ - + + + + + - @@ -372,36 +441,56 @@ - + + + + + file://$PROJECT_DIR$/07_文件操作/02_文件读取的课后练习.py + 7 + + + - + + + + - + + + - + + + + - + diff --git "a/07_\346\226\207\344\273\266\346\223\215\344\275\234/01_\346\226\207\344\273\266\347\232\204\350\257\273\345\217\226.py" "b/07_\346\226\207\344\273\266\346\223\215\344\275\234/01_\346\226\207\344\273\266\347\232\204\350\257\273\345\217\226.py" index b2055b6fbb750a6acb411c196837f0dc36467e22..76fd33b15a89a39b9f70b9dfd93d4b23a9b8f3fe 100644 --- "a/07_\346\226\207\344\273\266\346\223\215\344\275\234/01_\346\226\207\344\273\266\347\232\204\350\257\273\345\217\226.py" +++ "b/07_\346\226\207\344\273\266\346\223\215\344\275\234/01_\346\226\207\344\273\266\347\232\204\350\257\273\345\217\226.py" @@ -5,24 +5,25 @@ # 打开文件 import time -f = open("/Users/qinyingjie/Downloads/改签合同系统操作指引.pdf", "r", encoding="UTF-8") +f = open("/Users/qinyingjie/Documents/python-workspace/python-demo/07_文件操作/05_文件操作的综合案例.py", "r", encoding="UTF-8") print(type(f)) # 读取文件 - read() -# print(f"读取10个字节的结果:{f.read(10)}") -# print(f"read方法读取全部内容的结果是:{f.read()}") +print(f"读取10个字节的结果:{f.read(10)}") +print("-"*100) +print(f"read方法读取全部内容的结果是:{f.read()}") print("-----------------------------------------------") # 读取文件 - readLines() -# lines = f.readlines() # 读取文件的全部行,封装到列表中 +lines = f.readlines() # 读取文件的全部行,封装到列表中 # print(f"lines对象的类型:{type(lines)}") # print(f"lines对象的内容是:{lines}") # 读取文件 - readline() -# line1 = f.readline() -# line2 = f.readline() -# line3 = f.readline() -# print(f"第一行数据是:{line1}") -# print(f"第二行数据是:{line2}") -# print(f"第三行数据是:{line3}") +line1 = f.readline() +line2 = f.readline() +line3 = f.readline() +print(f"第一行数据是:{line1}") +print(f"第二行数据是:{line2}") +print(f"第三行数据是:{line3}") # for循环读取文件行 # for line in f: @@ -32,7 +33,7 @@ print("-----------------------------------------------") # time.sleep(500000) # with open 语法操作文件 row = 0 -with open("/Users/qinyingjie/Downloads/资料/第1-12章资料/资料/地图数据/疫情.txt", "r", encoding="UTF-8") as f: +with open("/Users/qinyingjie/Documents/python-workspace/python-demo/07_文件操作/05_文件操作的综合案例.py", "r", encoding="UTF-8") as f: for line in f: row += 1 print(f"第{row}行数据是:{line}") diff --git "a/07_\346\226\207\344\273\266\346\223\215\344\275\234/02_\346\226\207\344\273\266\350\257\273\345\217\226\347\232\204\350\257\276\345\220\216\347\273\203\344\271\240.py" "b/07_\346\226\207\344\273\266\346\223\215\344\275\234/02_\346\226\207\344\273\266\350\257\273\345\217\226\347\232\204\350\257\276\345\220\216\347\273\203\344\271\240.py" index ad7c49971fff683269b0b03d1a50de68081f8f17..cc50c292ec4593868451263bbf1ea786fae130c9 100644 --- "a/07_\346\226\207\344\273\266\346\223\215\344\275\234/02_\346\226\207\344\273\266\350\257\273\345\217\226\347\232\204\350\257\276\345\220\216\347\273\203\344\271\240.py" +++ "b/07_\346\226\207\344\273\266\346\223\215\344\275\234/02_\346\226\207\344\273\266\350\257\273\345\217\226\347\232\204\350\257\276\345\220\216\347\273\203\344\271\240.py" @@ -3,19 +3,19 @@ """ # 打开文件,以读取模式打开 -f = open("D:/word.txt", "r", encoding="UTF-8") +f = open("/Users/qinyingjie/Downloads/Snipaste_2024-08-11_22-14-26.png", "r", encoding="UTF-8") # 方式1:读取全部内容,通过字符串count方法统计itheima单词数量 -# content = f.read() -# count = content.count("itheima") +content = f.read() +count = content.count("itheima") # print(f"itheima在文件中出现了:{count}次") # 方式2:读取内容,一行一行读取 -count = 0 # 使用count变量来累计itheima出现的次数 +count = 0 # 使用count变量来累计itheima出现的次数 for line in f: - line = line.strip() # 去除开头和结尾的空格以及换行符 + line = line.strip() # 去除开头和结尾的空格以及换行符 words = line.split(" ") for word in words: if word == "itheima": - count += 1 # 如果单词是itheima,进行数量的累加加1 + count += 1 # 如果单词是itheima,进行数量的累加加1 # 判断单词出现次数并累计 print(f"itheima出现的次数是:{count}") # 关闭文件 diff --git "a/07_\346\226\207\344\273\266\346\223\215\344\275\234/03_\346\226\207\344\273\266\347\232\204\345\206\231\345\205\245.py" "b/07_\346\226\207\344\273\266\346\223\215\344\275\234/03_\346\226\207\344\273\266\347\232\204\345\206\231\345\205\245.py" index 508531edd370842f960d9aaaf78091e144bacfd4..be4390d5e007914c856b29dfa16aed4ab681d53f 100644 --- "a/07_\346\226\207\344\273\266\346\223\215\344\275\234/03_\346\226\207\344\273\266\347\232\204\345\206\231\345\205\245.py" +++ "b/07_\346\226\207\344\273\266\346\223\215\344\275\234/03_\346\226\207\344\273\266\347\232\204\345\206\231\345\205\245.py" @@ -5,17 +5,18 @@ # 打开文件,不存在的文件, r, w, a import time -# f = open("D:/test.txt", "w", encoding="UTF-8") +f = open("/Users/qinyingjie/Downloads/未命名.txt", "w", encoding="UTF-8") # # write写入 -# f.write("Hello World!!!") # 内容写入到内存中 +f.write("Hello World!!!") # 内容写入到内存中 # # flush刷新 -# # f.flush() # 将内存中积攒的内容,写入到硬盘的文件中 -# # close关闭 +f.flush() # 将内存中积攒的内容,写入到硬盘的文件中 +# close关闭 # f.close() # close方法,内置了flush的功能的 +print(1111) # 打开一个存在的文件 -f = open("D:/test.txt", "w", encoding="UTF-8") +# f = open("D:/test.txt", "w", encoding="UTF-8") # write写入、flush刷新 -f.write("黑马程序员") +# f.write("黑马程序员") # close关闭 -f.close() +# f.close() diff --git "a/07_\346\226\207\344\273\266\346\223\215\344\275\234/04_\346\226\207\344\273\266\347\232\204\350\277\275\345\212\240\345\206\231\345\205\245.py" "b/07_\346\226\207\344\273\266\346\223\215\344\275\234/04_\346\226\207\344\273\266\347\232\204\350\277\275\345\212\240\345\206\231\345\205\245.py" index 4d2e9e5d8cff0a29d490b5474691f86a30de21d4..f9a2b46121ace3c7657730b1714d8f08b8d9af07 100644 --- "a/07_\346\226\207\344\273\266\346\223\215\344\275\234/04_\346\226\207\344\273\266\347\232\204\350\277\275\345\212\240\345\206\231\345\205\245.py" +++ "b/07_\346\226\207\344\273\266\346\223\215\344\275\234/04_\346\226\207\344\273\266\347\232\204\350\277\275\345\212\240\345\206\231\345\205\245.py" @@ -11,7 +11,7 @@ # # close关闭 # f.close() # 打开一个存在的文件 -f = open("D:/test.txt", "a", encoding="UTF-8") +f = open("/Users/qinyingjie/Downloads/未命名.txt", "a", encoding="UTF-8") # write写入、flush刷新 f.write("\n月薪过万") # close关闭 diff --git "a/07_\346\226\207\344\273\266\346\223\215\344\275\234/05_\346\226\207\344\273\266\346\223\215\344\275\234\347\232\204\347\273\274\345\220\210\346\241\210\344\276\213.py" "b/07_\346\226\207\344\273\266\346\223\215\344\275\234/05_\346\226\207\344\273\266\346\223\215\344\275\234\347\232\204\347\273\274\345\220\210\346\241\210\344\276\213.py" index e58e9b82c4cb6de6ce78c054976d8e26a8617fa7..166d4e1d8ed95cc1b1f4c607780620c40fb5fa46 100644 --- "a/07_\346\226\207\344\273\266\346\223\215\344\275\234/05_\346\226\207\344\273\266\346\223\215\344\275\234\347\232\204\347\273\274\345\220\210\346\241\210\344\276\213.py" +++ "b/07_\346\226\207\344\273\266\346\223\215\344\275\234/05_\346\226\207\344\273\266\346\223\215\344\275\234\347\232\204\347\273\274\345\220\210\346\241\210\344\276\213.py" @@ -11,12 +11,14 @@ for line in fr: line = line.strip() # 判断内容,将满足的内容写出 if line.split(",")[4] == "测试": - continue # continue进入下一次循环,这一次后面的内容就跳过了 - # 将内容写出去 + # continue进入下一次循环,这一次后面的内容就跳过了 + continue + # 将内容写出去 fw.write(line) # 由于前面对内容进行了strip()的操作,所以要手动的写出换行符 fw.write("\n") # close2个文件对象 fr.close() -fw.close() # 写出文件调用close()会自动flush() +# 写出文件调用close()会自动flush() +fw.close() diff --git "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/03_\345\274\202\345\270\270\347\232\204\344\274\240\351\200\222.py" "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/03_\345\274\202\345\270\270\347\232\204\344\274\240\351\200\222.py" index 1915b838263274e8cf74d045b51ee61968cc0d36..c65ae58fabd3df0bac7c5d03a7f81d8321d4eb62 100644 --- "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/03_\345\274\202\345\270\270\347\232\204\344\274\240\351\200\222.py" +++ "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/03_\345\274\202\345\270\270\347\232\204\344\274\240\351\200\222.py" @@ -2,17 +2,22 @@ 演示异常的传递性 """ + # 定义一个出现异常的方法 def func1(): print("func1 开始执行") - num = 1 / 0 # 肯定有异常,除以0的异常 + num = 1 / 0 # 肯定有异常,除以0的异常 print("func1 结束执行") + + # 定义一个无异常的方法,调用上面的方法 def func2(): print("func2 开始执行") func1() print("func2 结束执行") + + # 定义一个方法,调用上面的方法 def main(): @@ -21,4 +26,5 @@ def main(): except Exception as e: print(f"出现异常了,异常的信息是:{e}") + main() diff --git "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/06_\345\214\205.py" "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/06_\345\214\205.py" index e82360adfc4acb3de54e318614e63eb4bc216425..fd13e159e491d3536fd4dbdf42d5d9bff1f4c224 100644 --- "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/06_\345\214\205.py" +++ "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/06_\345\214\205.py" @@ -22,5 +22,6 @@ # 通过__all__变量,控制import * from my_package import * + my_module1.info_print1() my_module2.info_print2() diff --git "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/07_\347\273\274\345\220\210\346\241\210\344\276\213\347\273\203\344\271\240.py" "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/07_\347\273\274\345\220\210\346\241\210\344\276\213\347\273\203\344\271\240.py" index 0e83d0cecbdfe5783fae6fe2a1a82a50f3b95bc7..8f7138b458c8cf92a0100527162948d6ffa059d8 100644 --- "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/07_\347\273\274\345\220\210\346\241\210\344\276\213\347\273\203\344\271\240.py" +++ "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/07_\347\273\274\345\220\210\346\241\210\344\276\213\347\273\203\344\271\240.py" @@ -9,6 +9,5 @@ from my_utils import file_util print(my_utils.str_util.str_reverse("黑马程序员")) print(my_utils.str_util.substr("itheima", 0, 4)) - file_util.append_to_file("D:/test_append.txt", "itheima") file_util.print_file_info("D:/test_append.txt") diff --git "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/08_\346\211\251\345\261\225_Python\345\270\270\347\224\250\346\250\241\345\235\227\345\212\237\350\203\275.py" "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/08_\346\211\251\345\261\225_time.py" similarity index 72% rename from "08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/08_\346\211\251\345\261\225_Python\345\270\270\347\224\250\346\250\241\345\235\227\345\212\237\350\203\275.py" rename to "08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/08_\346\211\251\345\261\225_time.py" index 20f0054722c1348b1d26f6194d42c51af0310c64..6ec77bf4778a6d60dd0aa2a460c6654112aca559 100644 --- "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/08_\346\211\251\345\261\225_Python\345\270\270\347\224\250\346\250\241\345\235\227\345\212\237\350\203\275.py" +++ "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/08_\346\211\251\345\261\225_time.py" @@ -1,9 +1,10 @@ """ -演示常用的模块功能 +演示常用的模块功能-time模块 """ import time + # time模块 -ts = time.time() # 当前时间戳 +ts = time.time() # 当前时间戳 print(f"当前时间戳是:{ts}") # 获取当前时间以指定的格式显示,2000-01-01 10:00:00 @@ -11,8 +12,3 @@ print(time.strftime("%Y-%m-%d %H:%M:%S")) # 将指定的时间戳转换为格式化的日期字符串 print(time.strftime("%Y-%m-%d %H:%M:%S")) -# random模块 - -# os模块 - -# sys模块 diff --git "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_01.py" "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_01.py" new file mode 100644 index 0000000000000000000000000000000000000000..9fe53a3227724ca2a643496b392b796753cd264b --- /dev/null +++ "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_01.py" @@ -0,0 +1,5 @@ +import random + +# 生成一个0到1之间的随机浮点数 +random_float = random.random() +print(random_float) diff --git "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_02.py" "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_02.py" new file mode 100644 index 0000000000000000000000000000000000000000..05f89e0ea3faddd63134b3f8aca5350bfe52c730 --- /dev/null +++ "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_02.py" @@ -0,0 +1,18 @@ +import random + +# 方式一 +# 生成一个随机浮点数,并格式化为两位小数 +random_float = random.random() +formatted_float = f"{random_float:.2f}" +print(formatted_float) + +# 方式二 +# 生成一个随机浮点数,并四舍五入到两位小数 +random_float = round(random.random(), 2) +print(random_float) + +# 方式三 +# 使用format()函数格式化为两位小数 +random_float = random.random() +formatted_float = format(random_float, '.2f') +print(formatted_float) diff --git "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_03.py" "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_03.py" new file mode 100644 index 0000000000000000000000000000000000000000..8392dd39f9dda0b14d99f54d0fa4a52c3e227084 --- /dev/null +++ "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_03.py" @@ -0,0 +1,9 @@ +import random + +# 从序列中随机选择一个元素 +item1 = random.choice(['apple', 'banana', 'cherry']) +print(item1) + +# 从序列中随机选择一个元素 +item2 = random.sample(['apple', 'banana', 'cherry'], 3) +print(item2) diff --git "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_04.py" "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_04.py" new file mode 100644 index 0000000000000000000000000000000000000000..6e340ed7f634f7d0196e589642ed9a0848bc3905 --- /dev/null +++ "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_04.py" @@ -0,0 +1,25 @@ +import random + +# 从序列中随机选择多个元素,不重复 +items = random.sample(range(1, 11), 5) +print(items) + +# 定义一个列表 +items = ['apple', 'banana', 'cherry'] + +# 相同的概率 +# 使用random.choices()随机选择3个元素,允许重复 +# 第三个参数是每个元素被选择的概率,如果为None,则每个元素被选择的概率相同 +# weights=None 表示每个元素被选择的概率相同。 +item2 = random.choices(items, weights=None, cum_weights=None, k=3) + +print(item2) + +# 不同的概率 +# 使用 cum_weights 进行选择时,每个元素的选择概率取决于其累积权重与总累积权重的比例。 +# 例如,如果总累积权重是 10,而某个元素的累积权重是 5,那么这个元素被选中的概率是 50%。 +# 这种方法可以用于实现更复杂的选择逻辑,例如基于概率分布的选择。 +weights = [1, 2, 3] +item3 = random.choices(items, weights=weights, cum_weights=None, k=3) + +print(item3) diff --git "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_05.py" "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_05.py" new file mode 100644 index 0000000000000000000000000000000000000000..8a16c88b3ea8246e4341718b521779bc1147b118 --- /dev/null +++ "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_05.py" @@ -0,0 +1,11 @@ +import random + +# 定义一个列表 +items = ['apple', 'banana', 'cherry'] + +# 同时指定2个策略会报错 +cum_weights = [2, 2, 2] +weights = [1, 2, 3] +item3 = random.choices(items, weights=weights, cum_weights=cum_weights, k=3) + +print(item3) diff --git "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_06.py" "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_06.py" new file mode 100644 index 0000000000000000000000000000000000000000..afbf7102ce0f5296feaa83bef54e0e4862e7823e --- /dev/null +++ "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_06.py" @@ -0,0 +1,15 @@ +import random + +# 定义一个列表 + +# 不同的累计权重 +# 'A' 的累计权重为 1, +# 'B' 的累计权重为 2(1 + 2), +# 'C' 的累计权重为 3(1 + 2 + 3), +# 'D' 的累计权重为 4(1 + 2 + 3 + 4)。 +items = ['A', 'B', 'C', 'D'] +cum_weights = [1, 3, 6, 10] + +item3 = random.choices(items, weights=None, cum_weights=cum_weights, k=3) + +print(item3) diff --git "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_07.py" "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_07.py" new file mode 100644 index 0000000000000000000000000000000000000000..329d46736a9c8e0c5c9d50a51a0cf066069c42d1 --- /dev/null +++ "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/09_\346\211\251\345\261\225_random_07.py" @@ -0,0 +1,6 @@ +import random + +# 设置随机数生成器的种子,每次的结果一致,一般用于测试 +random.seed(1) + +print(random.random()) diff --git "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/10_\346\211\251\345\261\225_os.py" "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/10_\346\211\251\345\261\225_os.py" new file mode 100644 index 0000000000000000000000000000000000000000..8431f3036345cc475a6db5af28bf0110fb0443cd --- /dev/null +++ "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/10_\346\211\251\345\261\225_os.py" @@ -0,0 +1,16 @@ +import os + +# 获取当前工作目录 +current_directory = os.getcwd() +print(current_directory) + +# 列出指定目录下的所有文件和目录名 +entries = os.listdir('.') +print(entries) + +# 改变当前工作目录 +os.chdir('/Users/qinyingjie/Downloads') + +# 获取环境变量 +path = os.getenv('PATH') +print(path) diff --git "a/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/11_\346\211\251\345\261\225_sys.py" "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/11_\346\211\251\345\261\225_sys.py" new file mode 100644 index 0000000000000000000000000000000000000000..b2ca8ffc274cb6a9b27788e51685f039c7a0fe28 --- /dev/null +++ "b/08_\345\274\202\345\270\270_\346\250\241\345\235\227_\345\214\205/11_\346\211\251\345\261\225_sys.py" @@ -0,0 +1,14 @@ +import sys + +# 打印Python解释器的版本信息 +print(sys.version) + +# 打印Python解释器的路径 +print(sys.executable) + +# 获取命令行参数列表 +arguments = sys.argv +print(arguments) + +# 退出程序 +sys.exit(0) diff --git a/my_package/my_module1.py b/my_package/my_module1.py index 1b6b48482f0fa08e8054f10caa9e57f4d55e1e58..4edf23dceaf46f7dd65430d68749bfc7b7e184bd 100644 --- a/my_package/my_module1.py +++ b/my_package/my_module1.py @@ -2,7 +2,9 @@ 演示自定义模块1 """ + def info_print1(): print("我是模块1的功能函数代码") -info_print1() \ No newline at end of file + +info_print1() diff --git a/my_utils/file_util.py b/my_utils/file_util.py index 947690d64c970d872f09e4c8c6cc33ea69bc316c..7bbceee147607499218953fdd63f49bdb2e87f48 100644 --- a/my_utils/file_util.py +++ b/my_utils/file_util.py @@ -18,7 +18,7 @@ def print_file_info(file_name): except Exception as e: print(f"程序出现异常了,原因是:{e}") finally: - if f: # 如果变量是None,表示False,如果有任何内容,就是True + if f: # 如果变量是None,表示False,如果有任何内容,就是True f.close()