Str.rc
一个关于法语的字符串文件在这里:
ID_STR_BRIGHTNESS;,"Luminosité"
ID_STR_CHILE_EASTER_ISLAND;,"Île de Pâques"
ID_STR_CURRENT_CH;,"Saisie chaîne"
ID_STR_DETAILS;,"Détails"
......
现在我可以将其导出到 Microsoft Str.xls
,如下所示:
cat ./Str.rc | sed 's/.*,//g' > ./Str.xls
但它会以这种方式从“详细信息”中获取“详细信息”。
顺便说一句,我尝试通过命令获取文件 Str.rc 编码格式:enca Str.rc
,它返回如下:
enca: Cannot determine (or understand) your language preferences.
Please use `-L language', or `-L none' if your language is not supported
(only a few multibyte encodings can be recognized then).
Run `enca --list languages' to get a list of supported languages.
那么,我能为此做些什么呢?
答案1
您或许可以调整您的 Unix 工具来正确处理编码。但是,如果您只想使用 Python 删除“,”之前的数据:
with open('Str.xls', 'w') as ofp:
with open('Str.rc') as fp:
for line in fp:
ofp.write(line.split(',',1)[1])
如果您想从命令行运行它而不先将其保存为文件,您可以剪切并粘贴:
python -c "with open('Str.xls', 'w') as ofp:
with open('Str.rc') as fp:
for line in fp:
ofp.write(line.split(',',1)[1])"