0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

はじめに

移植やってます

basestring (Python)

try:
    basestring
    PY2 = True
except NameError:
    basestring = (str, bytes)
    PY2 = False

basestringって型というかオブジェクトで、ver2.7くらいまで使用されていた様子。
basestringという抽象クラスが削除 - Qiita

bytes型も曲者です。

data = 'こんにちは'
>>> encoded = data.encode('sjis')
>>> print(encoded)
b'\x82\xb1\x82\xf1\x82\xc9\x82\xbf\x82\xcd'

プログラム上、読み込んだデータが文字列かどうかを判定するのに使用されています。

if isinstance(args[0], basestring):

String (Ruby)

if args[0].instance_of?(String)

比較する対象次第ですが、Stringで代用しようかなと考えております。

メモ

  • Python の basestring を学習した
  • 道のりは遠そう
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?