我有一大堆文件名,我想将其转换为特定格式。
e.g。
"D:\emote\aaatoot.gif"
"D:\emote\aatrek.001.gif"
"D:\emote\agesilaus.001.png"
"D:\emote\agreed.001.png"
"D:\emote\anarchists.001.gif"
etc...
到
emojis:
- name: aaatoot
src: D:\emote\aaatoot.gif
- name: aatrek.001.gif
src: D:\emote\aatrek.001.gif.gif
etc...
我试图将图像文件夹转换为emojipack,如果相关,则将其导入到松弛状态。 任何帮助都会很棒。
答案 0 :(得分:1)
你可以像这样阅读文件和格式:
import os
with open("your_file") as f, open("new_file", "w") as f1:
f1.write("Emojis:\n")
for line in f:
line = line.strip()
name = os.path.basename(line)
f1.write("\t- name: {}\n\t src:{}\n".format(name, line))