Python argument after * must be an iterablereport an error
An error "argument after * must be an iterable" was reported when using create thread.
th = (target=executeThread, args=(name)) ()
This is the wrong way to write it, there is a comma missing from the args
The correct way to write:
th = (target=executeThread, args=(name,)) ()
Python common errors and solutions, Bug Rescue Guide
If writing code is the most afraid of what, it is undoubtedly the bugs. and for newcomers, just touch programming, in the enjoyment of writing code sense of accomplishment, often will also be a variety of bugs to get confused.
1. IndentationError
In Python, all code is organized by correct spaces. So, whether it's an extra space or a missing space, the whole code won't run and only returns an error function.
The Python code follows the PEP8 whitespace specification, indenting each level using the4 spaces.
error message
a=1 b=2 if a<b: print a
amendment
a=1 b=2 if a<b: print a
Mixing with spaces (TabError)
This type of error is caused by coding with both tabs and spaces; the tab key is essentially a tab, not an indent.
Since tabs represent spaces of varying widths in different text editors, the use of spaces is recommended.
3. SyntaxError
The causes of grammatical errors include the following three:
1. invalid syntax
Missing punctuation, mixing Chinese and English symbols, misspellings, use of keywords in variable or function names.
2. invalid character in identifier (invalid character in identifier)
There are unrecognizable characters in the code, check to see if there are extra characters or Chinese characters.
3. Check for incomplete strings (EOL while scanning string litera)
In many cases it is due to inconsistent quotes on both sides of the string.
error message
print( 'hello', 'world')
Error Cause: Comma is Chinese comma
Error message: SyntaxError: invalid character inidentifier
result = (1024+(512*2)/128
Reason for error: Parentheses do not appear in pairs
error message (computing):SyntaxError:unexpected EOF whileparsing
if name =="A" print("hello")
Reason: Forgot to add a colon at the end of if/elif/else/while/for/def/class statements
Error message: SyntaxError:invalid syntax
3. Variable Name Error (NameErro)
Variable name errors are the most common and frequently encountered type of built-in error reporting, often occurring in Python variable naming, which raises a NameError if the variable cannot be found.There are a few rules to keep in mind about variable names:
- Variable names can only contain letters, numbers, and underscores, and may not begin with a number;
- Variable names cannot contain spaces, but you can use underscores to separate words within them;
- Do not use Python keywords and function names as variable names, such as print;
- Variable names should be both short and descriptive;
- Be careful with lowercase l's and uppercase O's, as they can easily be mistaken for the numbers 1 and 0.
If there is a variable name error, you can check whether the variable is assigned a value, whether there is a case inconsistency or the variable name is written incorrectly, and fix it when you find it.
error message
message = "Hello!" print(mesage)
Reason for error: misspelled variable name, misspelled massage as masge
error message (computing):NameError: name 'mesage' is not defined
5. Index error (IndexError)
The index is the position of the item in the array or list, and this exception occurs when we try to access an element from a list or a tuple from an index that does not exist in the list.
For example, if there is a list of 10 elements with indexes between 0 and 9, an IndexError is generated if an attempt is made to access an element at index 10 or 11 or more.
error message
a = [1,2,3] print(a[3])
Reason for error: The 4th index does not exist in list a. The index of the list is numbered from 0.
error message (computing):IndexError: string index out of range
6. KeyError
A KeyError error is triggered if the key does not exist when reading the key and value in the dictionary.
error message
d = {'a':1,'b':2} print(d['f'])
Reason for error: key 'f' does not exist
Error message: KeyError: 'f'
7. TypeError
This error is raised when an incorrect or unsupported object type is used in a program.
This error is also raised if an attempt is made to call an uncallable object or to iterate through a non-iterative identifier.
error message
age=18 print("My age is"+age)
Reason: When using "+" for splicing, you must either use a string, or convert the number to a string using str().
error message (computing):TypeError:can only concatenate str(not"int")to str
8. AttributeError
Attribute errors are raised when feature references and assignments fail.
The reason for this type of error is an attempt to access an unknown object property, in other words, the property of the corresponding object cannot be found. You can check that the constructor __init__() in the class is written correctly, with two underscores on the left and right sides.
For beginners, frequent bugs in the code does not mean that you are not learning well. If you look at a bug as a small monster in the game, then the process of eliminating the bug is not the process of upgrading?
summarize
The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.