报错一:python文件无法处理中文字符
SyntaxError: Non-ASCII character '\xe8' in file /home/windy/mininet/custom/get_packets.py on line 8, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
这个错误提示是因为Python默认的编码方式(ASCII编码)无法处理文件中出现的非ASCII字符。要解决这个问题,需要在Python文件的开头添加注释来指定文件的编码方式。
可以在文件开头添加如下注释:
# -*- coding: utf-8 -*-
报错二:
NameError: global name ‘
’ is not defined
这个错误提示是因为我在函数内部使用了变量udp_filter(这个变量在外部已经赋值)
Python中定义函数时,若想在函数内部对函数外的变量进行操作,就需要在函数内部声明其为global
所以要在函数内部在声明一次变量
global udp_filter
报错三:没有引入time模块
time.sleep(10)
NameError: name 'time' is not defined
import time