Python Common 16 error sets, you know those?

Source: Internet
Author: User
Tags net time

There are a variety of errors that can occur with Python, and the following are common Python errors and workarounds.

1.ValueError: ' conv2d_1a_3x3 ' is not a valid scope name

This is just the problem, in the LZ own hand hit inception net time, want to assign a name error, in fact, this is the problem of naming errors, if you look carefully "X" is I play in Chinese symbols, Python is not recognized, the solution is to use the English letter "x" instead, Errors can be resolved, and you can see the size of the convolution cores used.

2.indentationerror:excepted an indented block

It's just a matter of crying because it's not a grammatical error, it's a question of your code writing specification. Because Python is a language that is very sensitive to code indentation, your loop structure may be expressed in indented form. The most common problem is the tab and Space key mix, this is very easy to error, and the naked eye is difficult to distinguish, and some code Editor can choose to display spaces, even so, it is difficult to find exactly where there is a problem.

In fact, the above error is often encountered, that is, there is no first line indentation, such as the write if statement is, after the colon if the direct line, the good code Editor will automatically indent the first line, but some code editor may not have this function, it is necessary for you to manually indent, this is the best habit, do not knock several times the space , it is important to keep the code style consistent in Python's use, just by pressing Tab.

3.typeerror:max_pool2d () got an unexpected keyword argument ' atride '

This error is purely a problem of the hand, you define the function does not have this keyword, it is necessary to view the definition of the function name, I should be "stride", in convolutional neural network is defined step.

4.nameerror:global name ' time ' is not defined

The problem is that when I call the function time.time () to calculate the time loss, the function of the Times is wrong, the specific solution is very simple, as long as the code at the beginning with import time of the sentence to add the Times library file in the good.

5.nameerror:global name ' datetime ' is not defined

Solution Ibid. from datetime import datetime

6.nameerror:global name ' math ' is not defined

Solution Ibid., Import Math

Error such as ASCII appears in 7.Python

This type of problem is mainly in the Python code has the Chinese input, this solution is added at the beginning of the code: #coding: Utf-8. Otherwise, the input method of Chinese characters will be an error.

8.nameerror:global name ' Listdir ' is not defined
import os

There are a few issues to note here, if you use the import OS directly, then the call is required to write Os.listdir (), if the use from OS Import *, then you can use the Listdir (), but there will be a naming conflict between the module problem, The stability of the code will have a certain impact, so LZ recommends that if the module function is not very familiar with the case of Harbin using the first method.

9.TypeError: ' Dict_keys ' object does not support indexing

This issue is a Python version of the problem

#如果使用的是python2firstStr = myTree.keys()[0]#LZ使用的是python3firstSides = list(myTree.keys())firstStr = firstSides[0]

This is a matter of looking at the decision tree code, Python3 if running

firstStr = myTree.keys()[0]

Will report this error, the solution is to first convert to a list, and then the need to extract the index.

10.nameerror:name ' reload ' is not defined

This is a problem that may arise when the small partners modify their own module, which can occur when the module is overloaded, and the workaround is simple.

import importlibimportlib.reload(your module)
11.syntaxerror:invalid character in Indentifier

I'm going to post it here first. How the line of code that said it was displayed:

b = 6\xao

This LZ before the general appearance of ASCII and other problems is mixed Chinese input method, the problem is really embarrassing, why? The naked eye can see that is the Chinese input method under the space and the English input methods under the space/(ㄒoㄒ)/~~, this can only see the bottom of the line error bar, the Chinese space to replace the space in English, the other has no way, it is best to enter the code when switching the input method less switch form.

12.nameerror:name ' xrange ' is not defined

Python version problem, incompatible, python3 version of the switch to the range () function is OK.

13.AttributeError: ' List ' object has no attribute ' Testvec '

This is to say that the list does not have this property, what is the problem? The LZ hand mutilated ', ' hit '. ', knowing that Python should know '. ' This is the nature of what is to be defined in class, and it is useless to write it out of thin air.

14.syntaxerror:missing paraentheses in call to ' print '

It's a cliché, Python version problem, Python3. X to add ().

print (‘hello world!‘)
15.systemerror:cannot compile ' Python.h '

The problem is that you can't parse the Python header file, and the workaround is simple.

No module named WX

Lack of the solution of the module is a good solution, the lack of anything to do it

sudo apt-get install python-wxtools

Python contact time is not very long, temporarily encountered a lot of errors, so first write so much!

Python Common 16 error sets, you know those?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.