Python-string-decode

提供:Dev Guides
移動先:案内検索

Python String decode()メソッド

説明

Python文字列メソッド* decode()*は、_encoding_に登録されたコーデックを使用して文字列をデコードします。 デフォルトはデフォルトの文字列エンコーディングです。

構文

Str.decode(encoding='UTF-8',errors='strict')

パラメーター

  • encoding -これは使用されるエンコーディングです。 すべてのエンコーディングスキームのリストについては、http://docs.python.org/library/codecsl#standard-encodings [Standard Encodings。]をご覧ください。
  • エラー-これは、異なるエラー処理スキームを設定するために指定できます。 エラーのデフォルトは「strict」です。つまり、エンコードエラーはUnicodeErrorを発生させます。 他の可能な値は、「ignore」、「replace」、「xmlcharrefreplace」、「backslashreplace」、およびcodecs.register_error()を介して登録されたその他の名前です。

戻り値

デコードされた文字列。

#!/usr/bin/python

Str = "this is string example....wow!!!";
Str = Str.encode('base64','strict');

print "Encoded String: " + Str
print "Decoded String: " + Str.decode('base64','strict')

結果

Encoded String: dGhpcyBpcyBzdHJpbmcgZXhhbXBsZS4uLi53b3chISE=
Decoded String: this is string example....wow!!!