[Python] How to deal with the is instance error "is instance () arg 2 must be a type or tuple of types"

[Python] How to deal with the is instance error "is instance () arg 2 must be a type or tuple of types"

Causes and remedies when the following error occurs in is instance.

TypeError: isinstance() arg 2 must be a type or tuple of types

Occurrence Status

Error that the second argument is not of type. Occurs even though the type (list) is set correctly.

python


arr = [1,2,3]

#"List" is specified in the second argument
if isinstance(arr, list):
    print ("YES")

#TypeError: isinstance() arg 2 must be a type or tuple of types

Cause

Because I set a variable called list before this code. It was a list = variable instead of a list = type.

Coping

There are two ways to deal with it. ① Do not use a variable with the same name as the type. (2) Specify the argument as type (type name).

The basics are ①.

▼ ② When the argument is specified as type (type name)

python


arr = [1,2,3]

if isinstance(arr, type(list)):
    print ("YES")

#YES

Processing completed normally.

Recommended Posts

[Python] How to deal with the is instance error "is instance () arg 2 must be a type or tuple of types"
[Python] How to deal with the is instance error "is instance () arg 2 must be a type or tuple of types"
[python] [meta] Is the type of python a type?
How to deal with SSL error when connecting to S3 with boto of Python
[Python] How to use two types of type ()
[AWS] Wordpress How to deal with "The response is not a correct JSON response"
How to get a list of files in the same directory with python
[Introduction to Python] How to get the index of data with a for statement
How to write a list / dictionary type of Python3
[Python] How to deal with pandas read_html read error
How to identify the element with the smallest number of characters in a Python list?
How to check in Python if one of the elements of a list is in another list
[Python] What is a tuple? Explains how to use without tuples and how to use it with examples.
How to deal with python installation error in pyenv (BUILD FAILED)
How to determine the existence of a selenium element in Python
[Introduction to Python] How to split a character string with the split function
How to check the memory size of a variable in Python
How to send a request to the DMM (FANZA) API with python
[Python] What is a slice? An easy-to-understand explanation of how to use it with a concrete example.
How to get rid of the "Tags must be an array of hashes." Error in the qiita api
How to deal with the problem that the current directory moves when Python is executed from Atom
How to intercept or tamper with the SSL communication of the actual iOS device by a proxy
[Python] How to use the for statement. A method of extracting by specifying a range or conditions.
[Python] What is a formal argument? How to set the initial value
[Introduction to Python] What is the difference between a list and a tuple?
[Python] Explains how to use the range function with a concrete example
[Python] A program that calculates the number of socks to be paired
How to deal with OAuth2 error when using Google APIs from Python
How to deal with the problem that build fails when CI / CD of Python Function with AWS Amplify
Hit a method of a class instance with the Python Bottle Web API
[Introduction to Python] How to write a character string with the format function
How to format a list of dictionaries (or instances) well in Python
[Python] How to deal with module errors
[Introduction to Python] What is the method of repeating with the continue statement?
How to input a character string in Python and output it as it is or in the opposite direction.
Python> set> Convert with set ()> dictionary is only key> I was taught how to convert the values of dictionary to set / dir ({}) / help ({}) / help ({} .values)
How to deal with "^ [[A ^ [[B ^ [[C ^ [[D"] when you press the arrow keys when executing python on mac
How to pass the execution result of a shell command in a list in Python
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
[python] How to sort by the Nth Mth element of a multidimensional array
How to calculate the volatility of a brand
How to read a CSV file with Python 2/3
How to specify attributes with Mock of python
How to get dictionary type elements of Python 2.7
[Python] Determine the type of iris with SVM
[Introduction to statistics] What kind of distribution is the t distribution, chi-square distribution, and F distribution? A little summary of how to use [python]
Run the output code with tkinter, saying "A, pretending to be B" in python
Get the value of a specific key in a list from the dictionary type in the list with Python
How to deal with "Type Error: No matching signature found" error when using pandas fillna
A memo on how to overcome the difficult problem of capturing FX with AI
A memo of misunderstanding when trying to load the entire self-made module with Python3
How to count the number of occurrences of each element in the list in Python with weight
I thought about why Python self is necessary with the feeling of a Python interpreter
Don't take an instance of a Python exception class directly as an argument to the exception class!
The 15th offline real-time I tried to solve the problem of how to write with python
How to convert / restore a string with [] in python
A memo connected to HiveServer2 of EMR with python
How to get the number of digits in Python
[Python] How to draw a line graph with Matplotlib
[Introduction to Python] How to iterate with the range function?
How to create a submenu with the [Blender] plugin