-
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ファイルに新しいファイルを追加したりできます。 注意点として、デフォルトの設定では「圧縮」は行われず、単にファイルをまとめ... -
C#樹林
[C#] Splitting Strings by a Specified Regex Pattern (Regex.Split)
The standard String.Split method can only split text by fixed characters like commas or spaces. However, using Regex.Split allows you to convert strings into arrays using flexible rules, such as "splitting where a number appears" or "spl... -
C#樹林
【C#】文字列を指定した正規表現パターンで分割する (Regex.Split)
String.Split メソッドは「カンマ」や「空白」といった固定の文字でしか分割できませんが、Regex.Split を使用すると、「数字が現れた場所で区切る」「カンマまたはセミコロンまたは空白で区切る」といった柔軟なルールで文字列を分割配列に変換できます。... -
C#樹林
[C#] Advanced Replacement with Regex (Substitution Patterns and MatchEvaluator)
While the String.Replace method can only perform simple string substitutions, Regex.Replace enables advanced processing, such as "rewriting parts that match a pattern" or "replacing text with the result of a programmatic calculation." In... -
C#樹林
【C#】正規表現を使った高度な置換処理 (置換パターンとMatchEvaluator)
String.Replace メソッドは単純な文字列の置き換えしかできませんが、Regex.Replace を使用すると、「パターンに一致した部分の書き換え」や「プログラムによる計算結果への置き換え」といった高度な処理が可能になります。 ここでは、「置換パターン($1,... -
C#樹林
[C#] Retrieving “All” Occurrences Matching a Pattern in a String (Regex.Matches)
While Regex.Match retrieves only the "first" match, the Regex.Matches method allows you to retrieve all matching occurrences within a string as a collection (list). This method is essential when you want to extract multiple pieces of dat... -
C#樹林
【C#】文字列の中からパターンに一致する箇所を「すべて」取得する (Regex.Matches)
Regex.Match が「最初の1つ」だけを取得するのに対し、Regex.Matches メソッドを使用すると、文字列内に含まれるすべての一致箇所をコレクション(リスト)として取得できます。 ログファイルからのデータ抽出や、文章内のタグ解析など、複数のデータを取... -
C#樹林
[C#] Extracting a Single Match from a String Using Regex Pattern (Regex.Match)
To find a specific pattern (such as an order number, ID, or amount) within a string and retrieve only the first occurrence, use the Regex.Match method. Also, by using the "Grouping ()" feature of regular expressions, you can extract just... -
C#樹林
【C#】文字列の中から正規表現パターンに一致する箇所をひとつだけ取り出す (Regex.Match)
文字列の中から、特定のパターン(注文番号、ID、金額など)に合致する部分を探し出し、最初に見つかった1つだけを取得するには Regex.Match メソッドを使用します。 また、正規表現の「グループ化 ()」という機能を使うと、「注文ID全体」ではなく「IDの... -
C#樹林
[C#] Checking if a String Matches a Regular Expression Pattern (Regex.IsMatch)
When checking if data entered by a user is in the correct format (e.g., zip codes, phone numbers, or email addresses), Regular Expressions are a very powerful tool. In C#, you can use the Regex.IsMatch method from the System.Text.Regular... -
C#樹林
【C#】文字列が正規表現パターンに一致するか判定する (Regex.IsMatch)
ユーザーが入力したデータが正しい形式になっているか(例:郵便番号、電話番号、メールアドレスなど)をチェックする際、正規表現(Regular Expressions) は非常に強力なツールです。 C#では System.Text.RegularExpressions 名前空間の Regex.IsMatch ... -
C#樹林
[C#] Defining Custom Attributes and Controlling Behavior with Reflection
In C#, in addition to standard attributes (like [Obsolete] or [Serializable]), developers can define their own attributes (custom attributes). By using this, you can attach unique metadata (marks such as "this item is required" or "autom... -
C#樹林
【C#】独自の属性(Attribute)を定義してリフレクションで動作を制御する方法
C#では、標準で用意されている属性([Obsolete] や [Serializable] など)以外に、開発者が独自の属性(カスタム属性)を定義することができます。 これを利用すると、クラスやプロパティに対して独自のメタデータ(「この項目は必須」「この項目は自動変... -
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文字しか扱えない古いシステムへのデータ送信や、設定ファイルでの文字化け防止などに利...