pythonã§ããããã¡ã¤ã«ã®ä¸èº«ãæ¸ãæãããã¨ããããããã£ã¦ãã
ã°ã°ãã¨with openã¨ãã§ä¸åº¦ãã¡ã¤ã«ãéãã¦
ãã¡ã¤ã«ã®ä¸èº«ãæ¸ãæãã¦ãããä¸åº¦æ¸ãåºãã¿ãããªãã¨ããã¦ããè¨äºãã¨ã¦ãå¤ã
ãããçä¼¼ãã¦ãã£ã¦ã¿ãã¨ããªããä¿®æ£å¾ã®ãã¡ã¤ã«ã¨å
ã®ãã¡ã¤ã«ãåæã«ä¿®æ£ããã
(pythonã®ã³ãã¼ãæªããã¦ãï¼)
ããªãæéãããããã©ãåå ãããããªãã£ãã®ã§å¥ã®æ¹æ³ã§ã»ã»ã»
ããã¯å¤ã®sedãsubprocessããå¼ã³åºãã¦ä½¿ã
åèã«ãããã¼ã¸
import subprocess subprocess.run('sed -i -e s/div>/p>/g sample_fixed.html', shell=True)
èªåã¯ãã®æå¾ã®shell=Trueãã¤ãã¦ããªãã¦ã30åã»ã©è©°ã¾ã£ã¦ãã¾ã£ãã»ã»ã»(æ¥ãããã)
ãã®æã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ã¯
OSError: [Errno 2] No such file or directory
ã¿ãããªæãã ã£ãã¨æã(ã¡ã¢ã£ã¦ãªããã©)
sedã«ã¤ãã¦
ä»åã¯ãã¡ã¤ã«ã®ãã¹ãç½®æããå¿
è¦ããã£ãã®ã§ / ãåå²æåã ã¨è¦éããæªã
ããã¯å¥ã®è¨å·ã§ç½®ãæãã¦ãããã£ã½ã(tex ã®verbã¿ãããªãã®ã)
以ä¸ã®ãããªæãã§ããããã¨æã(æªç¢ºèªã§ã)
import subprocess subprocess.run('sed -i -e s@div>@p>@g sample_fixed.html', shell=True)