![프랑스에 대한 문자열을 Microsoft Excel 파일로 내보내는 방법은 무엇입니까?](https://linux55.com/image/36356/%ED%94%84%EB%9E%91%EC%8A%A4%EC%97%90%20%EB%8C%80%ED%95%9C%20%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%84%20Microsoft%20Excel%20%ED%8C%8C%EC%9D%BC%EB%A1%9C%20%EB%82%B4%EB%B3%B4%EB%82%B4%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
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"
...
Str.xls
이제 다음과 같이 Microsoft로 내보낼 수 있습니다 .
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])"