import re with open('e:/Base/sj/sj.sql', 'r', encoding='utf-8') as f: content = f.read() tables = [ 'main_post_candidate_review', 'main_student_education', 'main_student_experience', 'main_back_interview', ] with open('_schema_out.txt', 'w', encoding='utf-8') as fout: for table in tables: match = re.search(r'CREATE TABLE `' + table + r'`\s*\((.*?)\)\s*ENGINE', content, re.DOTALL | re.IGNORECASE) if match: fout.write(f"=== {table} ===\n") lines = match.group(1).strip().split('\n') for line in lines: line = line.strip() if line and not line.startswith('PRIMARY KEY') and not line.startswith('KEY') and not line.startswith('UNIQUE KEY'): fout.write(line + "\n") else: fout.write(f"=== {table} NOT FOUND ===\n")