python常见问题
上一篇 /
下一篇 2016-05-19 16:51:13
/ 个人分类:python
1 常见问题
1.1 退格
进入Linux的python后,退格键无法删除,需按“ctrl+Backspace”
1.2 编码
源代码加上以下语句可解决编码错误
# !/usr/bin/python
# -*-coding:utf-8-*-
或者
#!/usr/bin/env python
# coding: UTF-8
1.3 文件名不可和模块名重复
文件名不可和模块名称一致,否则运行时会报错,报错如下
Traceback (most recent call last):
File "random.py", line 3, in <module>
import random
File "D:\random.py", line 11, in <module>
num1 = random.randrange(1,9)
AttributeError: 'module' object has no
attribute 'randrange
1.4 打印函数时未打印括号报错
如代码为:print add
正确代码应该为print add()
<function test_add at 0x000000000282E588>
1.5 语法错误
SyntaxError: invalid syntax
1) 错误的变量命名,如:1_bn
2) 未正确分隔
3) 中文注释缺乏标注
1.6 非法缩进
IndentationError
收藏
举报
TAG:
Python
python