Python 2 to 3 = TypeError: descriptor 'find' for 'str' objects doesn't apply to a 'bytes' object
Python 2 to 3 = TypeError: descriptor 'find' for 'str' objects doesn't apply to a 'bytes' object
您好,我们尝试将 python 2 转换为 3,但遇到错误。
也许有人有想法。
谢谢
if episode_num is not None:
episode_num = str.encode(str(episode_num), 'ascii','ignore')
if str.find(episode_num, ".") != -1:
splitted = str.split(episode_num, ".")
if splitted[0] != "":
#TODO fix dk format
try:
season = int(splitted[0]) + 1
is_movie = None # fix for misclassification
if str.find(splitted[1], "/") != -1:
episode = int(splitted[1].split("/")[0]) + 1
elif splitted[1] != "":
episode = int(splitted[1]) + 1
except:
episode = ""
season = ""
if str.find(episode_num, ".") != -1:
类型错误:'str' 对象的描述符 'find' 不适用于 'bytes' 对象
Python 3 对于混合 str
和 bytes
字符串要严格得多。只要保持一致。当您使用 encode
时,您会创建一个 bytes
字符串。
if bytes.find(episode_num, b".") != -1:
更好,学会使用in
:
if b"." in episode_num:
您好,我们尝试将 python 2 转换为 3,但遇到错误。 也许有人有想法。
谢谢
if episode_num is not None:
episode_num = str.encode(str(episode_num), 'ascii','ignore')
if str.find(episode_num, ".") != -1:
splitted = str.split(episode_num, ".")
if splitted[0] != "":
#TODO fix dk format
try:
season = int(splitted[0]) + 1
is_movie = None # fix for misclassification
if str.find(splitted[1], "/") != -1:
episode = int(splitted[1].split("/")[0]) + 1
elif splitted[1] != "":
episode = int(splitted[1]) + 1
except:
episode = ""
season = ""
if str.find(episode_num, ".") != -1:
类型错误:'str' 对象的描述符 'find' 不适用于 'bytes' 对象
Python 3 对于混合 str
和 bytes
字符串要严格得多。只要保持一致。当您使用 encode
时,您会创建一个 bytes
字符串。
if bytes.find(episode_num, b".") != -1:
更好,学会使用in
:
if b"." in episode_num: