Attention to Japanese Beginners
ðSummaryð
ðŠã³ã¡ã³ãã¢ãŠããæšæºåºåã®å©çšã§ãã£ãŠããããã°ã©ã å ã§ã¯ã§ããã ãè±æ°å以å€ã®æåã䜿ããªãããã«ããŸãããðŠ
ð«¶Noticeð«¶
ãœãŒã¹ã³ãŒãã¯GitHubããååŸã§ããŸã(åäž.pyãã¡ã€ã«)
ðŸâã®READMEã«ãã®èšäºãšå šãåãããšãæžãããŠããŸãðŸ
https://github.com/myon-bioinformatics/AttentionToJapaneseBeginners
python main.py
ðŽââïž(JSP)
- ã¢ã«ãã¡ããããããªãæåã䜿ããšãããåå ã§åé¡ãèµ·ããããšããããŸãã
- ä»åã¯ãShift_JISããšã³ã³ãŒããããã¯ãã³ãŒããããæãäŸã«ããŸãã
- ã¡ãªã¿ã«ãã®ããã°ã©ã (main.py)ã¯æåäŸã®ãããåé¡ã¯åºæ¬çã«èµ·ãããŸããã
ðCause & ðCountermeasures
ðCause
ðŽââïž(JSP)
ð€ä»¥äžããã®åå ã§ãð€â
-
èŠããäžã¯1ã€ã®æåã§ãã£ãŠããå®éã«ã¯2ãã€ã以äžã§ããããšãåå ã§åé¡ãèµ·ããããšããããŸãã
-
Shift_JISïŒSJISãcp932ïŒã®æåã³ãŒãã§ã¯ã2ãã€ãç®ã0x5cã®ã\ãïŒããã¯ã¹ã©ãã·ã¥ïŒãå«ãæåã代衚çã§ãã
-
åºçŸ©ã®æå³ã§ã¯ã2ãã€ãç®ã0x7cã®ã|ãïŒãã€ãæåïŒãã2ãã€ãç®ãæ£èŠè¡šçŸãªã©ã®ã¡ã¿æåãšéãªãæåãå«ã¿ãŸãã
ð®at lengthð®
ðŽââïž(JSP)
-
äŸãã°ããèœããšããæåã®2ãã€ãç®ã¯ã\ãã§ãã
-
ããã¯è¡æ«ã«ã\ããšæžãããŠããããšãšå矩ã«ãªããŸãã
-
Cèšèªã§ã¯ãããã«ãã£ãŠæ¬¡ã®è¡ãŸã§ãã³ã¡ã³ãã¢ãŠããããŠããŸããŸãã
Example include those with a second byte of "\"(0x5c)
è¡š: b'\x95\\'
èœ: b'\x94\\'
å: b'\x8f\\'
ðCountermeasures
ðŽââïž(JSP)
ð¥·è§£æ±ºçã¯æå€ãšåçŽð¥·
- ã³ã¡ã³ãã¢ãŠãã®ææ«ã«"."(ããªãªã)ãªã©ãã€ãã: ãç°¡åã
- ãšã³ã³ãŒã/ãã³ãŒãæã®æåã³ãŒãããUTF-8ããªã©ã«ãã: ãéåžžã
- ããããè±æ°å以å€ã¯ã§ããã ã䜿ããªã: ãéèŠã
ðThe Result of Standard Outputð
ðŽââïž(JSP) âïžä»¥äžã®äŸã¯main.pyãå®è¡ããæã®æåäŸã®çµæã§ãâïž
----------------
Called function: standard_output_harmless_shift_jis
ã: b'\x82\xe9'
ã: b'\x82\xbd'
èš: b'\x8bL'
ã: b'\x81Y'
èœ.: b'\x94\\.'
a: b'a'
1: b'1'
----------------
Called function: standard_output_harmful_shift_jis
è¡š: b'\x95\\'
èœ: b'\x94\\'
å: b'\x8f\\'
æ³: b'\x96@'
å
: b'\x8f['
å: b'\x8c^'
æœ: b'\x8e{'
å: b'\x94{'
æ¬: b'\x96{'
å³: b'\x90}'
----------------
Called function: print_harmless_shift_jis
No problem!!
----------------
Called function: print_harmful_shift_jis
No problem!!
Warning If a problem were occured,
"print("No problem!!") at Called function: print_harmful_shift_jis"
wouldn't function.
Addendum
ðŽââïž(JSP)
â ïžãmain_to_shift_jis.pyãã¯ããmain.pyããUTF-8ã§ã¯ãªãShift_JISã§ãšã³ã³ãŒããããã¡ã€ã«ã§ãã
ð§Mojibake in detailð§
- ð€¥main.pyð€¥
easy_separator = easy_separator_closure()() #ããã¯ã¯ããŒãžã£ãšããæ©èœ
- ðµâð«main_to_mojibake.py(Even the Japanese speaker can't read)ðµâð«
easy_separator = easy_separator_closure()() #繧ç¹ïœç¹ïœŒç¹§ïœžç¹ïœ£ç¹§åé瞺å±â
ðŽââïžæ¥æ¬èªè©±è ã«åããŠ
ã¯ããã«
æ¥æ¬èªãã³ã¡ã³ããæšæºåºåçã§å©çšããŠãæ¹åããžã®èª¬æãªã®ã§ãã©ã¡ãããšããã°ã³ãŒãããããã¡ãã®èª¬æãæ¬é¡ãããããŸãããã
ä»åã¯ã³ã¡ã³ãã¢ãŠãã®çš®é¡(#
or """ """
)ãšã¯é¢ä¿ãªãPythonã§å®è£
ããã®ã§ãèŠããäžã¯åé¡ãªãããã«èŠããŸãã
æã«æ¯ã¹ããšèŠãããæ©äŒãæžããŸããããã繧ç¹ïœç¹ïœŒç¹§ïœžç¹ïœ£ç¹§åé瞺å±âãã®ãããªæååããç®ã«ããããšã¯ããããŸããïŒ
ããããç解ã§ããªãå€æã®åå ã®äžã€ã«ã¯ãäžã«æããæåã³ãŒãã®éã(Shift_JISãªã©)ã«å€æããããšãã«çããããšããããŸãã
äžçªäŒãããããš
ãã¡ãããæ£ããæåãåæ ãããŠãªãåé¡ãæ°ã«ãã¹ãããšãªã®ã§ãããæåãå€ããã®ã¯èŠèŠçã®åœ±é¿ã®ã¿ãšã¯éããŸããã
ä»åã®ã¬ããžããªã§æã匷ãäŒãããããšã¯ã³ã¡ã³ãã¢ãŠãã®è±æ°å以å€ã®æåã圱é¿ããŠæåãå€æŽããããšããããšããããšã§ãã
以äžã®ãããªäºäŸããããŸãã
- ãã±ããã¢ã³ã¹ã¿ãŒãèµ€ããç·ãã«ãããè£æ(ãã°)
- ããã®è¡ã®ã³ã¡ã³ããæ¶ããšãªããããããªããã©åããªããªãããšããçŸè±¡
- ãšã¹ã±ãŒãåŠçãããã¯ãã®ã³ãŒãã«çºèŠãããè匱æ§(äžéšã®äºäŸ)
ããããäºäŸã®åå ã®äžã€ã«ã³ã¡ã³ãã¢ãŠããè±æ°å以å€ã ã£ããšããã±ãŒã¹ããããŸãã
ãŸããããã³ããšã³ããããã¯ãšã³ããªã©é¢ä¿ãªã以äžã®ã³ã¡ã³ãã¢ãŠããæ®ããŠãæ¹ãããŸãã
- #ããã¯ãããšããæ©èœ
- #æè¡çã«å®è£ å¯èœ
- #ããã®é¢æ°ã¯åºåãããäŸïŒãåŸæ¥è ãªã¹ãã売äžè¡š
æ¬é³ã¯ã...
ã»ãã¥ãªãã£ãšã³ãžãã¢ãšããŠãããã°æ©èœãæ®ã£ãŠããã³ãŒãããã§ãã¯ããéã«ããç®ã«ããä»ã
ãã®åŸã®å®è£ ãããªãã£ã/å»æ¢ããã¡ãœãããã³ã¡ã³ãã¢ãŠããæ®ããŠãã±ãŒã¹ã決ããŠçãããããŸãããã
ãã ã幞éã«ãã»ãšãã©ã®ã±ãŒã¹ã§ã¯æ¡ä»¶ãé£ããããŠçŸå®çã§ãªãã®ã§ãè匱æ§èšºææã«ã¯ãæ å ±ãã§æžãã§ããŸãã
ïŒãã ããã¡ããšããŠãä»äºéã¯ãªãã«è¶ããããšã¯ãªãã®ã§ããïŒ
ããããŠâ."(ããªãªã)ã§ãã€ããŠãããããªãã ãšæããããšãããããŸããð¶âð«ïž
ä»åã¯ç®ãåŒãããã«BeginnersãšããããæžããŸããããå®éã¯äžäžçŽè ã§ããããããŸããã
ããããäžå匷ãªäžäžçŽè ã»ã©ä»ãŸã§ã®ããæ¹ã«åºå·ããŠåä»ããšãå¢ãããŠãã±ãŒã¹ãããã®ã§ã
ãããŠè³¢ãäžäžçŽè ãšããããã®ååŠè ã®æ¹ã ã«ã¯æ°ãä»ããŠããã ãããã§ãããð®âðš
æåŸã«
ãããããŸããŸãã»ãã¥ãªãã£ã幟床ãšãªãå«ã°ããããšã«ãªããšæããŸããã
è匱æ§ãšåå ã®å€§åã¯ã(å€ãæ¹ããæ°ããã»ããæ©ã)èšèšã»å®è£ æã®ãã¥ãŒãã³ãšã©ãŒã§ãã
äžå¹žãªããšã«ã¬ã¬ã·ãŒãªèšèªã»ã©ãããã©ããããããªãã¬ãã«ãŸã§ããããã
éè¡ãå®å ¬åºãªã©ã®ã¬ã¬ã·ãŒã·ã¹ãã ã®ã³ãŒãã®æ¹ä¿®ããªããŒã¹ãšã³ãžãã¢ãªã³ã°ãªã©ã¯ç¹ã«èŠåŽã匷ããããã ãããªããð€
ã§ããã°è±èªã§ãããšèšããããšããã§ãããã
â."(ããªãªã)ã²ãšã€ã§åé¡ã®è§£æ±ºã»è»œåŸ®ãªè匱æ§ã®å¯ŸåŠãå¯èœãªããšãããã®ã§ã
ãããã«åããŠé ã®çé ã«å ¥ããŠãããšåœ¹ç«ã€ããšããããããããŸãããð