Python樹林– category –
-
Python樹林
[Python] Accessing SQLite3 Data by Column Name Using sqlite3.Row
By default, Python's sqlite3 module returns data as tuples. However, by changing a specific setting, you can access values by specifying their "column names," just like a dictionary. This eliminates the need to worry about the order of c... -
Python樹林
【Python】SQLite3でカラム名を指定して値を取得する方法
Pythonの sqlite3 モジュールでは、デフォルトのデータ取得形式はタプル(tuple)ですが、設定を変更することで辞書のように「カラム名」を指定して値にアクセスすることが可能になります。これにより、SQLのSELECT文で取得したカラムの順序を気にする必要... -
Python樹林
[Python] Basics of Retrieving Data with SQLite3: Cursor Loop vs. fetchall vs. fetchone
When retrieving data from a database using Python's standard sqlite3 module, there are several methods available. This article explains how to directly iterate over the cursor object, how to retrieve everything at once using fetchall(), ... -
Python樹林
【Python】SQLite3でデータを取得する基本:cursorループ・fetchall・fetchoneの使い分け
Python標準ライブラリの sqlite3 モジュールを使用してデータベースからデータを取得する際、いくつかの方法が存在します。ここでは、cursor オブジェクトを直接反復処理する方法、fetchall() でリストとして一括取得する方法、そして fetchone() で1行ず... -
Python樹林
[Python] Executing SQL with SQLite3: Creating a Member Table and Inserting Data
This article demonstrates how to use the sqlite3 module to perform "Table Creation (CREATE)" and "Data Registration (INSERT)" operations. We will simulate a database that manages member information for a web service, implementing securit... -
Python樹林
【Python】SQLite3でSQL文を実行する:会員テーブルの作成と登録
sqlite3 モジュールを使用し、データベースへの「テーブル作成(CREATE)」と「データ登録(INSERT)」を行う実装です。 ここでは、Webサービスの会員情報を管理するデータベースを想定し、セキュリティを考慮したプレースホルダを使用した実装を行います... -
Python樹林
[Python] Connecting to and Disconnecting from SQLite3 Databases: File vs. In-Memory
Using the Python standard library sqlite3, you can create and manage lightweight relational databases that run on local files or in memory, without needing to set up a separate server. This article explains how to connect to a database f... -
Python樹林
【Python】SQLite3データベースへの接続と切断:ファイルDBとオンメモリDB
Python標準ライブラリの sqlite3 を使用すると、別途サーバーを立てることなく、ローカルファイルやメモリ上で動作する軽量なリレーショナルデータベースを作成・操作できます。 ここでは、データベースファイル(永続化)への接続方法と、データ保存しな... -
Python樹林
[Python] Saving and Restoring Running Objects to a File: How to Use pickle
If you want to save (serialize) complex data generated by a Python program, such as class instances, lists, or dictionaries, exactly as they are to a file and restore (deserialize) them later, use the standard library pickle module. Unli... -
Python樹林
【Python】実行中のオブジェクトをファイルに保存・復元する:pickleの使い方
Pythonプログラムで生成したクラスのインスタンスやリスト、辞書などの複雑なデータを、そのままの形でファイルに保存(シリアライズ)し、後から復元(デシリアライズ)したい場合は、標準ライブラリの pickle モジュールを使用します。 JSON形式とは異な... -
Python樹林
[Python] Compress/Archive an Entire Directory at Once: shutil.make_archive
When you want to compress an entire directory (folder) in Python, using the make_archive() function from the standard library shutil module is overwhelmingly easier than writing loop processes with the zipfile or tarfile modules. This fu... -
Python樹林
【Python】ディレクトリごと一括で圧縮・アーカイブする:shutil.make_archive
Pythonでディレクトリ(フォルダ)の中身をまるごと圧縮したい場合、zipfile や tarfile モジュールでループ処理を書くよりも、標準ライブラリ shutil モジュールの make_archive() 関数を使うのが圧倒的に簡単です。 この関数は、1行のコードでディレクト... -
Python樹林
[Python] Compressing and Archiving Files in Tar Format: Writing with tarfile
This article explains how to use Python's tarfile module to group multiple files and directories into a tar archive. In addition to creating simple archives (uncompressed), you can also reduce file size by using compression algorithms li... -
Python樹林
【Python】tar形式でファイルを圧縮・アーカイブする:tarfileの書き込み
Pythonの tarfile モジュールを使用して、複数のファイルやディレクトリをまとめてtarアーカイブを作成する方法を解説します。 単なるアーカイブ(無圧縮)だけでなく、gzipなどの圧縮アルゴリズムを併用してファイルサイズを小さくすることも可能です。 o... -
Python樹林
[Python] How to Extract and Unpack Tar Files: Using the tarfile Module
To handle archive files such as .tar, .tar.gz, and .tgz in Python, use the standard library tarfile module. This format is frequently used for server management and data exchange in Linux environments. What is a Tar File? "Tar (Tape Arch... -
Python樹林
【Python】tarファイルを展開・解凍する方法:tarfileモジュールの使い方
Pythonで .tar, .tar.gz, .tgz などのアーカイブファイルを操作するには、標準ライブラリの tarfile モジュールを使用します。 サーバー管理やLinux環境でのデータ交換などで頻繁に利用される形式です。 Tarファイルとは? 「Tar(Tape Archive)」は、複... -
Python樹林
[Python] Compressing and Creating ZIP Files: Writing and Appending with zipfile
The Python standard library zipfile module allows you to group existing files to create a ZIP archive or add new files to an existing ZIP file. A key point to note is that by default, "compression" is not performed; files are simply bund... -
Python樹林
【Python】ファイルをZIP形式で圧縮・作成する:zipfileの書き込みと追記
Python標準ライブラリの zipfile モジュールを使用すると、既存のファイルをまとめてZIPアーカイブを作成したり、既存のZIPファイルに新しいファイルを追加したりできます。 注意点として、デフォルトの設定では「圧縮」は行われず、単にファイルをまとめ... -
Python樹林
[Python] Handling ZIP Files: How to Extract and Manipulate Using the zipfile Module
Python's standard library zipfile module allows you to extract (unzip) ZIP archives or check the list of filenames inside without extracting. This article explains operations ranging from basic handling to processing password-protected Z... -
Python樹林
【Python】ZIPファイルの展開と操作:zipfileモジュールの使い方
Python標準ライブラリの zipfile モジュールを使用すると、ZIP形式の圧縮ファイルを解凍(展開)したり、解凍せずに中身のファイル名一覧を確認したりできます。 ここでは、業務データのバックアップファイル(ZIP)を操作するシナリオを例に、基本操作か... -
Python樹林
[Python] Generating Hash Values: Usage of hashlib (SHA256, MD5, etc.)
Python's standard library hashlib module allows you to easily generate hash values (message digests) from strings or files. Hash values are widely used for security and data integrity checks, such as password storage and file tampering d... -
Python樹林
【Python】ハッシュ値を生成する:hashlibの使い方(SHA256, MD5等)
Pythonの標準ライブラリ hashlib モジュールを使用すると、文字列やファイルから**ハッシュ値(メッセージダイジェスト)**を簡単に生成できます。 ハッシュ値は、パスワードの保存やファイルの改ざん検知など、セキュリティやデータ整合性の確認に広く利... -
Python樹林
[Python] Restoring Unicode Escape Strings: Using the codecs Module
In API responses or server logs, text is sometimes recorded in the \uXXXX format (Unicode Escape). This article explains how to decode such data back into its original string format using Python's codecs module. We will implement a syste... -
Python樹林
【Python】ユニコードエスケープ文字列を復元する:codecsモジュールの活用
APIのレスポンスやサーバーの生ログなど、日本語が \uXXXX 形式(ユニコードエスケープ)で記録されているデータを、Pythonの codecs モジュールを使用して本来の文字列に復元(デコード)する方法を解説します。 ここでは、サーバーから受信した「ステー... -
Python樹林
[Python] How to Convert Strings to Unicode Escape Format
There are cases where you need to convert multi-byte characters (such as Japanese or emojis) into an ASCII-only string composed of "Unicode escape sequences" in the format \uXXXX. This is often used for data transmission to legacy system... -
Python樹林
【Python】文字列をユニコードエスケープ形式に変換する方法
日本語などのマルチバイト文字を、\uXXXX という形式の「ユニコードエスケープシーケンス」のみで構成されたASCII文字列に変換したい場合があります。 これは、ASCII文字しか扱えない古いシステムへのデータ送信や、設定ファイルでの文字化け防止などに利... -
Python樹林
[Python] How to Parse URL Query Parameters into a Dictionary
In web application development or scraping, you often need to analyze query parameters at the end of a URL (in the format ?key=value&...) and handle them as a Python dictionary. You can easily perform this conversion using the parse_... -
Python樹林
【Python】URLのクエリパラメータをパースして辞書(dict)に変換する方法
Webアプリケーション開発やスクレイピングにおいて、URLの末尾にある ?key=value&... という形式のクエリパラメータを解析し、Pythonの辞書として扱いたい場合があります。 標準ライブラリ urllib.parse モジュールの parse_qs() 関数を使用すると、こ... -
Python樹林
[Python] How to Parse URLs to Extract Components (Domain, Path, Query, etc.)
In web scraping or API integration processes, you often need to extract specific parts from a long URL string, such as just the "domain name" or only the "query parameters." By using the urlparse() function from Python's standard library... -
Python樹林
【Python】URLをパースして構成要素(ドメイン・パス・クエリ等)を取得する方法
WebスクレイピングやAPI連携の処理において、1つの長いURL文字列から「ドメイン名だけ」や「クエリパラメータだけ」を抜き出したい場合があります。 Pythonの標準ライブラリ urllib.parse モジュールにある urlparse() 関数を使用すると、URLを6つの構成要...