<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>python応用学習 &#8211; スグブログ</title>
	<atom:link href="https://sugublog.org/tag/python%E5%BF%9C%E7%94%A8%E5%AD%A6%E7%BF%92/feed/" rel="self" type="application/rss+xml" />
	<link>https://sugublog.org</link>
	<description>ブログ運営について発信中</description>
	<lastBuildDate>Tue, 15 Mar 2022 14:48:43 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://sugublog.org/wp-content/uploads/2021/07/icon_20210703-min-150x150.png</url>
	<title>python応用学習 &#8211; スグブログ</title>
	<link>https://sugublog.org</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【python応用】エクセルファイルから辞書dictを作成する</title>
		<link>https://sugublog.org/python-base-dict/</link>
					<comments>https://sugublog.org/python-base-dict/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[suguru]]></dc:creator>
		<pubDate>Mon, 08 Feb 2021 15:00:57 +0000</pubDate>
				<category><![CDATA[python]]></category>
		<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[python応用学習]]></category>
		<guid isPermaLink="false">https://sugublog.org/?p=1049</guid>

					<description><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/07/python007-1024x769.jpg" class="webfeedsFeaturedVisual" /></p>エクセルで対応表を読み取ってpythonの辞書（dict）にしたかったのですが、いい方法がググっても載っていなかったので無理やり作成して見ました。python難しいですけどやりがいありますね。 エクセル表 良かったら使用 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/07/python007-1024x769.jpg" class="webfeedsFeaturedVisual" /></p>
<p>エクセルで対応表を読み取ってpythonの辞書（dict）にしたかったのですが、いい方法がググっても載っていなかったので無理やり作成して見ました。<a href="https://ja.wikipedia.org/wiki/Python">python</a>難しいですけどやりがいありますね。</p>



<pre class="wp-block-code"><code>import openpyxl as px
import csv
path = 'D:\python\excel-dict.xlsx'

wb = px.load_workbook(path)
ws = wb.active
row_max_number = ws.max_row +1
row = 1
column = 1
dic = {}
print(row_max_number)
while row &lt; row_max_number:
  key = ws.cell(row,column).value
  value = ws.cell(row,2).value
  dic&#91;key] = value
  row +=1

print(dic)
print(dic&#91;2])</code></pre>



<p>エクセル表</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="186" height="187" src="https://sugublog.org/wp-content/uploads/2021/02/image-19.png" alt="" class="wp-image-1052" srcset="https://sugublog.org/wp-content/uploads/2021/02/image-19.png 186w, https://sugublog.org/wp-content/uploads/2021/02/image-19-150x150.png 150w" sizes="(max-width: 186px) 100vw, 186px" /></figure></div>



<p></p>



<p>良かったら使用して見て下さい。もっといい方法があれば教えて下さい。宜しくお願い致します。</p>



<div class="wp-block-columns">
<div class="wp-block-column">
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-9330904718533231" data-ad-slot="6086594686"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>



<div class="wp-block-column"></div>
</div>



<h2 class="wp-block-heading">関連記事</h2>



<ul class="wp-block-list"><li><a href="https://sugublog.org/python-base-switch/">【python】switch構文をpythonで使用する方法【簡単です】</a></li><li><a href="https://sugublog.org/%e3%80%90python%e3%80%91while%e3%82%92%e4%bd%bf%e7%94%a8%e3%81%97%e3%81%a6%e7%b9%b0%e3%82%8a%e8%bf%94%e3%81%97%e5%87%a6%e7%90%86%e3%82%92%e3%81%97%e3%82%88%e3%81%86%ef%bc%81/07/">【python基礎】whileを使用して繰り返し処理をしよう！</a></li></ul>
]]></content:encoded>
					
					<wfw:commentRss>https://sugublog.org/python-base-dict/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【python応用】テキストの行を読み込み、特定の文字列を抽出する方法</title>
		<link>https://sugublog.org/python-app-text-extract/</link>
					<comments>https://sugublog.org/python-app-text-extract/?noamp=mobile#comments</comments>
		
		<dc:creator><![CDATA[suguru]]></dc:creator>
		<pubDate>Thu, 04 Feb 2021 13:33:35 +0000</pubDate>
				<category><![CDATA[python]]></category>
		<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[便利コマンド]]></category>
		<category><![CDATA[python応用学習]]></category>
		<guid isPermaLink="false">https://sugublog.org/?p=944</guid>

					<description><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/07/programing007-02-1024x819.jpg" class="webfeedsFeaturedVisual" /></p>仕事をしていて、あるファイルから特定の箇所を抽出したい。それが出来れば業務が早く終わるのに。でもやり方がわからないから手作業で行ってしまって、遅くなる、更に間違える。などよくあります。 また1からプラグラム組んでいたらプ [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/07/programing007-02-1024x819.jpg" class="webfeedsFeaturedVisual" /></p>
<p>仕事をしていて、<strong>あるファイルから特定の箇所を抽出したい</strong>。それが出来れば業務が早く終わるのに。でもやり方がわからないから手作業で行ってしまって、遅くなる、更に間違える。などよくあります。</p>



<p>また1からプラグラム組んでいたらプログラミングで時間を取られてしまった。などの経験があると思いますので、自分の好きな箇所の文字列を抽出していくpythonファイルの雛形を作成しておきます。</p>



<h2 class="wp-block-heading">構成</h2>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="646" height="156" src="https://sugublog.org/wp-content/uploads/2021/02/image-7.png" alt="" class="wp-image-947" srcset="https://sugublog.org/wp-content/uploads/2021/02/image-7.png 646w, https://sugublog.org/wp-content/uploads/2021/02/image-7-300x72.png 300w" sizes="(max-width: 646px) 100vw, 646px" /><figcaption>デフォルトフォルダ</figcaption></figure></div>



<p>まずはデフォルトのフォルダを決めて、そこにpythonファイルを作成します。同じフォルダに「text」フォルダ作成し、読み込むファイルと書き込むファイルを入れるフォルダにしましょう。</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="664" height="160" src="https://sugublog.org/wp-content/uploads/2021/02/image-8.png" alt="" class="wp-image-948" srcset="https://sugublog.org/wp-content/uploads/2021/02/image-8.png 664w, https://sugublog.org/wp-content/uploads/2021/02/image-8-300x72.png 300w" sizes="(max-width: 664px) 100vw, 664px" /><figcaption>「text」フォルダの中身</figcaption></figure></div>



<p>「text」フォルダには読み込むファイルを作成しておきましょう。ここでは「text_input.txt」としておきましょう。</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="560" height="190" src="https://sugublog.org/wp-content/uploads/2021/02/image-9.png" alt="" class="wp-image-949" srcset="https://sugublog.org/wp-content/uploads/2021/02/image-9.png 560w, https://sugublog.org/wp-content/uploads/2021/02/image-9-300x102.png 300w" sizes="(max-width: 560px) 100vw, 560px" /><figcaption>ファイルの中身</figcaption></figure></div>



<p>ファイルの中身は上記のようなコピーをしたようなログのファイルを準備して見ます。今回はここから「コピー先のパス」と「コピーしたファイル」を抽出してみましょう。</p>



<p>まずは何か共通点や一意のもの、特徴的なものなどを探します。今回はコピー先は「¥¥」で始まっています。ファイルは右から数えて最初の「.」が使用できそうですね。今回はこれにしましょう。</p>



<h2 class="wp-block-heading">作成</h2>



<p>ではひな形を作成しましょう！カタカタ肩</p>



<div class="ad">
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-9330904718533231" data-ad-slot="6086594686"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>



<p>どどーーーん！</p>



<p>作成しました！！</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>path_input = &quot;D:\\python\\text\\text_input.txt&quot;
path_output_path = &quot;D:\\python\\text\\text_output_path.txt&quot;
path_output_file = &quot;D:\\python\\text\\text_output_file.txt&quot;
with open(path_output_file,&quot;w&quot;) as f_o_f:
 with open(path_output_path,&quot;w&quot;) as f_o_p:
  with open(path_input,&quot;r&quot;) as f_i:
   lines = f_i.readlines()
   for line in lines:
    start = line.index(&quot;\\\\&quot;)
    end = line.rindex(&quot;\\&quot;)
    url = line[start:end+1] + &quot;\n&quot;
    f_o_p.write(url)

    start_file = line.rindex(&quot;\\&quot;)
    end_file = line.rindex(&quot;.&quot;)
    url_file = line[start_file+1:end_file] + &quot;\n&quot;
    f_o_f.write(url_file)</code></pre></div>



<h2 class="wp-block-heading">結果：最終的にこうなれば成功です！</h2>



<p>これを実行するとこうなります。</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img decoding="async" width="650" height="183" src="https://sugublog.org/wp-content/uploads/2021/02/image-10.png" alt="" class="wp-image-954" srcset="https://sugublog.org/wp-content/uploads/2021/02/image-10.png 650w, https://sugublog.org/wp-content/uploads/2021/02/image-10-300x84.png 300w" sizes="(max-width: 650px) 100vw, 650px" /><figcaption>python実行後フォルダ</figcaption></figure></div>



<p>２つのファイルが出来ます。中身を見てみましょう！</p>



<div class="wp-block-columns">
<div class="wp-block-column">
<div class="wp-block-image"><figure class="alignright size-large"><img decoding="async" width="290" height="202" src="https://sugublog.org/wp-content/uploads/2021/02/image-11.png" alt="出来たファイル　パス編" class="wp-image-955"/><figcaption>ファイル１</figcaption></figure></div>
</div>



<div class="wp-block-column">
<p>「text_output_path」ファイルを開いてみると、最初においていたファイルの中身から<strong>コピー後のファイルパスだけ</strong>を抽出したファイルが出来ています。</p>
</div>
</div>



<div class="wp-block-columns">
<div class="wp-block-column">
<div class="wp-block-image"><figure class="alignright size-large"><img decoding="async" width="280" height="205" src="https://sugublog.org/wp-content/uploads/2021/02/image-12.png" alt="出来たファイル　ファイル名編" class="wp-image-956"/><figcaption>ファイル２</figcaption></figure></div>



<p></p>
</div>



<div class="wp-block-column">
<p>「text_output_file」ファイルを開いてみると、最初においていたファイルの中身から<strong>コピー後のファイル名だけ</strong>を抽出したファイルが出来ています。</p>
</div>
</div>



<h2 class="wp-block-heading">解説します。</h2>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>path_input = &quot;D:\\python\\text\\text_input.txt&quot;</code></pre></div>



<p>#インプットするファイルパスを変数に入れましょう。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>path_output_path = &quot;D:\\python\\text\\text_output_path.txt&quot;</code></pre></div>



<p>#アウトプットするパスのファイルパスを変数に入れましょう。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>path_output_file = &quot;D:\\python\\text\\text_output_file.txt&quot;
﻿</code></pre></div>



<p>#アウトプットするファイルのファイルパスを変数に入れましょう。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>with open(path_output_file,&quot;w&quot;) as f_o_f:
 with open(path_output_path,&quot;w&quot;) as f_o_p:
  with open(path_input,&quot;r&quot;) as f_i:</code></pre></div>



<p>ファイルを実際に読み込んでいきましょう。ファイルを書き込みで開いて変数「f_o_f」「f_o_p」に入れています。読み込むファイルは読み取り専用で開きましょう。<strong>「with」を使用し「:」で終わりインデントすると、インデント終わったところで自動で閉じてくれます</strong>ので便利です。</p>



<p>withの注意</p>



<ul class="wp-block-list"><li>スペースかタブでインデントしましょう。</li><li>行の最後に「:」を忘れずに入れましょう。</li></ul>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>lines = f_i.readlines()</code></pre></div>



<p>「readlines」で読み取ったファイルを１行１行読み取っていき、リスト「lines」に入れます。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>for line in lines:</code></pre></div>



<p>「for」で繰り返します。先程作成したリスト「lines」から一行ずつ取り出し変数「line」に入れます。</p>



<p>「for」注意点</p>



<ul class="wp-block-list" id="block-734652d0-1b71-4e22-ab15-31900a9bc64e"><li>スペースかタブでインデントしましょう。</li><li>行の最後に「:」を忘れずに入れましょう。</li></ul>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>start = line.index(&quot;\\\\&quot;)</code></pre></div>



<p>抽出する初めの位置を決め変数<strong>「start」</strong>に入れます。「<strong>index</strong>」メソッドで「￥￥￥￥」の位置を数えます。文字列の場合「￥」などは<a href="https://ja.wikipedia.org/wiki/%E3%82%A8%E3%82%B9%E3%82%B1%E3%83%BC%E3%83%97%E3%82%B7%E3%83%BC%E3%82%B1%E3%83%B3%E3%82%B9" title="https://ja.wikipedia.org/wiki/%E3%82%A8%E3%82%B9%E3%82%B1%E3%83%BC%E3%83%97%E3%82%B7%E3%83%BC%E3%82%B1%E3%83%B3%E3%82%B9">エスケープシークエンス</a>なので「￥￥」と<strong>２回繰り返します</strong>。ここでは「￥￥」の位置が欲しいので「￥￥￥￥」と記入します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>end = line.rindex(&quot;\\&quot;)</code></pre></div>



<p>終わる位置は右から数えて最初の「￥」になるので「￥￥」とします。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>url = line[start:end+1] + &quot;\n&quot;</code></pre></div>



<p><strong>[]で囲う事で文字列から抽出してくれます</strong>。構文はこうです。</p>



<p>line[文字列の初めの位置:文字列の終わりの位置]</p>



<p>始めの位置は先程の<strong>「start」</strong>　終わりの位置は先程の「<strong>end</strong>」に<strong>１を足したものになります（初めが１ではなく０の為）最後に改行を表す「¥n」を「+」で足して変数「url」に入れましょう。</strong></p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>f_o_p.write(url)</code></pre></div>



<p>先程の変数「url」をwriteメソッドでファイルに書き込めば完了です。後はfor構文で最後の行まで繰り返してくれるのでOKです。</p>



<p>では同じ様にファイルも抽出して見て下さい。コードの残りの部分になります。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-python" data-lang="Python"><code>    start_file = line.rindex(&quot;\\&quot;)
    end_file = line.rindex(&quot;.&quot;)
    url_file = line[start_file+1:end_file] + &quot;\n&quot;
    f_o_f.write(url_file)</code></pre></div>



<p>読み込むファイルの<strong>共通点や特徴や独特な部分を見つける事が出来れば</strong>これだけ覚えるだけでも<strong>かなり業務効率化が測れる</strong>のではないでしょうか。是非編集して作成して見て下さい。</p>



<div class="ad">
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-9330904718533231" data-ad-slot="6086594686"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>



<div class="wp-block-columns">
<div class="wp-block-column" style="flex-basis:66.66%">
<h2 class="wp-block-heading">関連記事　</h2>



<ul class="wp-block-list"><li><a href="https://sugublog.org/python-base-switch/">【python】switch構文をpythonで使用する方法</a></li><li><a href="https://sugublog.org/python%e3%81%a7excel%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95%e3%80%90%e5%9f%ba%e7%a4%8e%ef%bc%9a%e6%9c%80%e5%88%9d%e3%81%ab%e8%a6%9a%e3%81%88%e3%82%8b%e4%ba%8b%e3%80%91/24/" title="https://sugublog.org/python%e3%81%a7excel%e3%82%92%e6%93%8d%e4%bd%9c%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95%e3%80%90%e5%9f%ba%e7%a4%8e%ef%bc%9a%e6%9c%80%e5%88%9d%e3%81%ab%e8%a6%9a%e3%81%88%e3%82%8b%e4%ba%8b%e3%80%91/24/">pythonでエクセルを操作する為の基礎</a></li></ul>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://sugublog.org/python-app-text-extract/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>pythonでエクセル、テキストを読み込みhtmlに書き出すスクリプト</title>
		<link>https://sugublog.org/python-excel-text-read-01/</link>
					<comments>https://sugublog.org/python-excel-text-read-01/?noamp=mobile#comments</comments>
		
		<dc:creator><![CDATA[suguru]]></dc:creator>
		<pubDate>Sun, 06 Dec 2020 12:10:53 +0000</pubDate>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[python応用学習]]></category>
		<guid isPermaLink="false">https://sugublog.org/?p=228</guid>

					<description><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/07/html-007-1-1024x655.jpg" class="webfeedsFeaturedVisual" /></p>pythonでエクセル、テキストを読み込みhtmlに書きだしたい時があると思います。 その時の方法を、自分用に作成しました。 pythonでエクセル、テキストを読み込みhtmlに書き出すスクリプト 同じフォルダに入れるフ [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/07/html-007-1-1024x655.jpg" class="webfeedsFeaturedVisual" /></p>
<p>pythonでエクセル、テキストを読み込みhtmlに書きだしたい時があると思います。</p>



<p>その時の方法を、自分用に作成しました。</p>



<h2 class="wp-block-heading">pythonでエクセル、テキストを読み込みhtmlに書き出すスクリプト</h2>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle ads" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-9330904718533231" data-ad-slot="6086594686"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<pre class="wp-block-code"><code>import openpyxl as px
import os
###################読み込むエクセルファイルパス
wb = px.load_workbook(r'D:\DATA\pythonG\1_host_ip_syutoku\host_ip.xlsx')
###################読み込むテキストファイルパス
contents_file = r'D:\DATA\pythonG\1_host_ip_syutoku\contests.txt'
###################書き込むテキストファイルパス
contents_file_w = r'D:\DATA\pythonG\1_host_ip_syutoku\contests_w.txt'
#waku_file = r'D:\DATA\pythonG\1_host_ip_syutoku\waku.html'
###################読み込むヘッダーテキストファイルパス
waku_headfile = r'D:\DATA\pythonG\1_host_ip_syutoku\waku_head.txt'
###################読み込むフッターテキストファイルパス
waku_footfile = r'D:\DATA\pythonG\1_host_ip_syutoku\waku_foot.txt'
###################シートの初期値
page_number = 0
###################シートを読み込みリストへ変換する
sheets = wb.sheetnames
###################シートの総数を求め、繰り返し回数を決定する
sheets_suu = len(sheets)-1
###################現ページNOとシートの総数を比較する-シートの数だけ繰り返す
while page_number &lt;= sheets_suu:
    #現ページNOから現ページの名前を調べる
    page = sheets&#091;page_number]
    #書き込むファイルの指定、シートにより分ける場合
    waku_file_w = r'D:\DATA\pythonG\1_host_ip_syutoku\comp\waku_w-'+page+'.html'
    #現ページの名前から現ページをアクティブにする
    wb.active = wb.sheetnames.index(page)
    ws = wb.active
    ############初期にセルを指定する2##番号で############
    row = 4
    column = 2
############コンテンツ作成関数############
    def func1(host,row,column):
        ############初期のセルを読み込み############
        #host = ws.cell(row,column).value
        ############セルが空白の時は関数を抜ける###########
        if not host:
            exit
        else:
            ############セルの値がAP出なければくり返す###########   
          while False == host.startswith('AP'):
            #host = ws.cell(row,column).value
            ip = ws.cell(row,column+1).value
            ############ファイルに書き込み###########
            with open(contents_file,'r') as contents:
                filetext = contents.read()
                ############元ファイルの値を変換###########
                after_text = filetext.replace('host_input',host).replace('ip_input',ip)
                ############コンテンツの中身を追記していく###########
                with open(contents_file_w,'a') as contents_w:
                    contents_w.write(after_text)
                
                ############////ファイルに書き込み###########
            row +=1
            ############APの最初が入ってしまうのでもう一回判定###########
            host = ws.cell(row,column).value
            if 'AP' in host:
                break       
    host = ws.cell(row,column).value
    ############hostがあれば関数呼び出し###########
    while host:
        host = ws.cell(row,column).value 
        func1(host,row,column)
        column +=3
    
    with open(waku_headfile,'r') as waku_head_r:
        headtext = waku_head_r.read()
        with open(waku_footfile,'r') as waku_foot_r:
            foottext = waku_foot_r.read()
            with open(contents_file_w,'r') as contents_file_all:
                contenstext = contents_file_all.read()
                with open(waku_file_w,'w') as waku_w:
                    waku_w.write(headtext)
                    waku_w.write(contenstext)
                    waku_w.write(foottext)
    ############書き込み終わったのでコンテンツファイル削除###########                
    os.remove(contents_file_w)
    ############次のシートへ###########  
    page_number +=1</code></pre>



<h3 class="wp-block-heading">同じフォルダに入れるファイル</h3>



<ul class="wp-block-list"><li>waku.html (入れたい部分)</li><li>waku_head.txt (入れたい部分から上の部分)</li><li>waku_foot.txt (入れたい部分から下の部分)</li></ul>



<h3 class="wp-block-heading">変更する箇所</h3>



<ul class="wp-block-list"><li>ファイルのパス全般</li><li>エクセルの初めに参照するセルの位置をrowとcolumnの数字に入力する</li><li>エクセルの列の間の数字を入力する column +=3 の数字を編集する</li><li>waku.htmlとpythonファイルの入れ込みたい部分</li><li>row +=1を止めるトリガーの部分2か所（今回でいう「AP」が含まれていなければ、「AP」が含まれていればbreak）</li></ul>



<p>見にくいのでコピーして何かテキストか何かに張り付けてみてね。。。</p>



<h2 class="wp-block-heading">python使用時の注意点</h2>



<p class="is-style-balloon_box">またこれを作成している時にはまったというかpythonが動かなかったりもしたので、そのリンクも張っておきます。</p>



<p><a rel="noreferrer noopener" title="https://sugublog.org/python%e3%81%8c%e5%8b%95%e3%81%8b%e3%81%aa%e3%81%84%e7%90%86%e7%94%b1%e3%81%af%e3%83%91%e3%82%b9%e3%81%ab%e3%81%82%e3%81%a3%e3%81%9f%e8%a9%b1/" href="https://sugublog.org/python%e3%81%8c%e5%8b%95%e3%81%8b%e3%81%aa%e3%81%84%e7%90%86%e7%94%b1%e3%81%af%e3%83%91%e3%82%b9%e3%81%ab%e3%81%82%e3%81%a3%e3%81%9f%e8%a9%b1/" target="_blank">pythonが動かなかった理由はパスにあった話</a></p>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle ads" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-9330904718533231" data-ad-slot="6086594686"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
]]></content:encoded>
					
					<wfw:commentRss>https://sugublog.org/python-excel-text-read-01/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
