Catalog
One 、 Actual combat scene
Two 、 Main knowledge points
File read and write
Basic grammar
exception handling
Loop statement
string manipulation
3、 ... and 、 Rookie actual combat
1、 establish python file
2、 Running effect
Actual combat scene : How to associate multiple files with multiple columns
File read and write
Basic grammar
exception handling
Loop statement
string manipulation
Make arrangements now !
"""
Author: Rookie actual combat
Actual combat scene : How to associate multiple files with multiple columns
"""
# Import system package
import platform
print("Hello, Rookie actual combat ")
print(" Actual combat scene : How to associate multiple files with multiple columns ")
grade_dict = {}
# You need to create a file first py015_grade.txt
with open("py015_grade.txt", encoding="utf8") as f:
for line in f:
sno, grade = line.strip().split(",")
grade_dict[sno] = grade
print(grade_dict)
# You need to create a file first py015.txt
fout = open("py015.txt", "w", encoding="utf8")
with open("py015_student.txt", encoding="utf8") as f:
for line in f:
sno, sname = line.strip().split(",")
grade = grade_dict[sno]
# relation py015_student.txt、py015_grade.txt write in py015.txt
fout.write(f"{sno},{sname},{grade}\n")
# Close file stream
fout.close()
print("Python edition ", platform.python_version())
Rookie actual combat , Continuous learning !