7.3ファイルシステムの操作7.3.1フォルダー配下のファイル情報を取得する(1)構文listdir関数listdir(path='.')path:列挙対称のフォルダーimport osimport datetimePATH = 'C:\\data\\selfpy\\chap07\\'for f in os.listdir(PATH): p = os.path.join(PATH, f) p ...
もっと読む
2023年06月
Python勉強中 7.2.5オブジェクトのシリアライズ 20230622
7.2.5オブジェクトのシリアライズclass Book: def __init__(self, isbn, title, price): self.isbn = isbn self.title = title self.price = priceb = Book('978-4-7981-5382-7', '独習C#新版', 3600)import picklewith open('C:\\dat ...
もっと読む
Python勉強中 7.2.4タブ区切り形式のテキストを読み書きする 20230622
7.2.4タブ区切り形式のテキストを読み書きする>>> import csv >>> >>> with open('C:\\data\\selfpy\\chap07\\data.tsv', encoding='UTF-8') as file: ... for row in csv.reader(file, delimiter='\t'): ... for cell in row: ... print(cell) ... ...
もっと読む
Python勉強中 7.2.3バイナリファイルの読み書き 20230621
7.2.3バイナリファイルの読み書きimport datetimefile_path = 'C:\\data\\selfpy\\chap07\\access.log'with open('C:\\data\\selfpy\\chap07\\input.png', 'rb') as reader, \ open('C:\\data\\selfpy\\chap07\\output.png', 'wb') as writer: while True: ...
もっと読む
Python勉強中 7.2.2テキストファイルを読み込む 20230621
7.2.2テキストファイルを読み込む>>> import datetime>>>>>> file_path = 'C:\\data\\selfpy\\chap07\\access.log'>>>>>> with open('C:\\data\\selfpy\\chap07\\sample.txt', 'r', encoding='UTF-8') as file:... data = file.read()... print(data)...独習Py ...
もっと読む