1. An ASCII error occurs in Python

This type of problem mainly involves Chinese input in Python code. This solution is to add: #coding: UTF-8 at the beginning of the code. Otherwise, an error will be reported if any characters under the Chinese input method are entered.

2.NameError: global name ‘listdir’ is not defined

import os

Listdir (); from OS import *; listdir(); but there will be naming conflicts between modules. The stability of the code can be affected, so LZ recommends using the first method if you are not familiar with module functions.

3.NameError: global name ‘time’ is not defined

Time.time () is used to calculate the time loss. The solution is as simple as adding “import time” at the beginning of the code and adding the time library file.

4.NameError: global name ‘datetime’ is not defined

From datetime import datetime

5.NameError: global name ‘math’ is not defined

The solution is as above, import Math

6.TypeError: ‘dict_keys’ object does not support indexing

The problem is with the Python version

# if python2 is used

firstStr = myTree.keys()[0]

#LZ uses python3

firstSides = list(myTree.keys())

firstStr = firstSides[0]

That’s the problem with looking at the decision tree code, if python3 is running

firstStr = myTree.keys()[0]

This error will be reported, the solution is to first convert the list, and then extract the required index.

7.SyntaxError: invalid character in indentifier

I’ll post here how the line of code with the error appears:

b = 6\xao

LZ said before that the problem of ASCII is mixed Chinese input method. It is really embarrassing to have this problem. Why? The only way to see which lines reported errors was to replace Chinese Spaces with English ones. The rest was best accomplished by sparingly switching input forms when typing codes.

8.NameError: name ‘xrange’ is not defined

Python version issue, incompatible, Python 3 version of the range() function should be used.

AttributeError: ‘list’ object has no attribute ‘testVec’

List does not have this attribute. LZ hand remnants of the ‘, ‘into the’. ‘, know python should know ‘. ‘this is the nature of need in the class definition to some, it was useless to oneself write out of thin air.

10.NameError: name ‘reload’ is not defined

This is a problem that may occur when reloading a module if you modify the module you wrote. The solution is very simple

import importlib

importlib.reload(your module)

11.SyntaxError: Missing paraentheses in call to ‘print’

Python3. X adds ().

print (‘hello world! ‘)

12. SystemError: always compile a ‘Python. H’

The problem is the inability to parse Python headers, and the solution is simple.

# Update the source first

sudo apt-get update

# python installed – dev

sudo apt-get install python-dev

13.no module named wx

Lack of module solution or very good solution, lack of what to install what on the line

sudo apt-get install python-wxtools

Recently, many friends have sent messages to ask about learning Python. For easy communication, click on blue to join yourselfDiscussion solution resource base