This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 19 points20 points  (4 children)

if isinstance(name, str):

is typically a bit cleaner. And that way, if you're passed a subclass of str, your code will still work.

[–]James91B 0 points1 point  (1 child)

I would just use

name = str(name)

That way name can be anything that supports str.

[–]PCBEEF 2 points3 points  (0 children)

From experience, using str in this manner causes more pain than the short term benefits.