Initial commit: skills library
- 70 skills with code and documentation - Add .gitignore (ignore __pycache__, output/, temp/, venv/) - Clean up test intermediates and caches
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
"""删除 MusicXML 中所有 <print> 元素。"""
|
||||
import sys
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print('Usage: python remove_print.py input.musicxml [output.musicxml]')
|
||||
sys.exit(1)
|
||||
|
||||
input_file = sys.argv[1]
|
||||
output_file = sys.argv[2] if len(sys.argv) > 2 else input_file.replace('.musicxml', '_no_print.musicxml')
|
||||
|
||||
ET.register_namespace('m', 'http://www.musescore.org/ns/mscore')
|
||||
ET.register_namespace('xlink', 'http://www.w3.org/1999/xlink')
|
||||
|
||||
tree = ET.parse(input_file)
|
||||
root = tree.getroot()
|
||||
removed_count = 0
|
||||
for elem in root.iter():
|
||||
to_remove = [c for c in list(elem) if c.tag == 'print']
|
||||
for c in to_remove:
|
||||
elem.remove(c)
|
||||
removed_count += 1
|
||||
|
||||
try:
|
||||
ET.indent(root)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
tree.write(output_file, encoding='UTF-8', xml_declaration=True)
|
||||
print(f'Removed {removed_count} <print> element(s)')
|
||||
print(f'Output: {output_file}')
|
||||
Reference in New Issue
Block a user