>>> ls1=["nihia"]
>>> ls1
['nihia']
>>> ls1.pop()
'nihia'
>>> ls1.append("sssss")
>>> ls1
['sssss']
>>> assert len(ls1)>0
>>> ls1.pop()
'sssss'
>>> assert len(ls1)>0 Traceback (most recent call last):
File "<pyshell#38>", line 1, in <module>
assert len(ls1)>0
AssertionError
>>>
>>> ls1.fishc Traceback (most recent call last):
File "<pyshell#40>", line 1, in <module>
ls1.fishc
AttributeError: 'list' object has no attribute 'fishc'
>>>
>>> ms1[3] Traceback (most recent call last):
File "<pyshell#42>", line 1, in <module>
ms1[3]
NameError: name 'ms1' is not defined
>>> ls1[3] Traceback (most recent call last):
File "<pyshell#43>", line 1, in <module>
ls1[3]
IndexError: list index out of range
>>>
>>> dict1={'one':1 ,'two':2}
>>> dict1['one']
1
>>> dict1['four'] Traceback (most recent call last):
File "<pyshell#47>", line 1, in <module>
dict1['four']
KeyError: 'four'
>>> dixt1.get('four') Traceback (most recent call last):
File "<pyshell#48>", line 1, in <module>
dixt1.get('four')
NameError: name 'dixt1' is not defined
>>> dict1.get('four')
>>> dict1.get('two')
2
>>> 1+'' Traceback (most recent call last):
File "<pyshell#51>", line 1, in <module>
1+''
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>> 5/0 Traceback (most recent call last):
File "<pyshell#52>", line 1, in <module>
5/0
ZeroDivisionError: integer division or modulo by zero
>>>
>>>
>>>
>>>
>>> ================================ RESTART ================================
>>> Traceback (most recent call last):
File "/tmp/guest-WX48w4/文档/py1.py", line 2, in <module>
file_name=open('myname')
IOError: [Errno 2] No such file or directory: 'myname'
>>> ================================ RESTART ================================
>>> Traceback (most recent call last):
File "/tmp/guest-WX48w4/文档/py1.py", line 2, in <module>
file_name=open('myname.txt')
IOError: [Errno 2] No such file or directory: 'myname.txt'
>>> ================================ RESTART ================================
>>>
wrong
[Errno 2] No such file or directory: 'myname.txt'
>>> ================================ RESTART ================================
>>>
wrong
[Errno 2] No such file or directory: 'myname.txt'
>>> ================================ RESTART ================================
>>> Traceback (most recent call last):
File "/tmp/guest-WX48w4/文档/py1.py", line 2, in <module>
name=a+''
NameError: name 'a' is not defined
>>> ================================ RESTART ================================
>>>
wrong
unsupported operand type(s) for +: 'int' and 'str'
>>> ================================ RESTART ================================
>>> Traceback (most recent call last):
File "/tmp/guest-WX48w4/文档/py1.py", line 2, in <module>
int ('abc')
ValueError: invalid literal for int() with base 10: 'abc'
>>> ================================ RESTART ================================
>>> Traceback (most recent call last):
File "/tmp/guest-WX48w4/文档/py1.py", line 5, in <module>
print (file_name.read())
NameError: name 'file_name' is not defined
>>> 1/0 Traceback (most recent call last):
File "<pyshell#57>", line 1, in <module>
1/0
ZeroDivisionError: integer division or modulo by zero
>>> raise 1/0 Traceback (most recent call last):
File "<pyshell#58>", line 1, in <module>
raise 1/0
ZeroDivisionError: integer division or modulo by zero
>>>
 try:
int ('')
#name=1+'1'
#file_name=open('myname.txt')
print (file_name.read())
file_name.close()
except IOError as reason: #eg1
print ('wrong\n'+str(reason))
except TypeError as reason:
print ('wrong\n'+str(reason))
except: #eg2
print ('wrong\n'+str(reason))
except (TypeError,IOError): #eg3
print ('wrong\n'+str(reason))
finally: #keep away from not closing the file
file_name.close()

python FileError的更多相关文章

  1. python click module for command line interface

    Click Module(一)                                                  ----xiaojikuaipao The following mat ...

  2. python异常以及面向对象编程

    一.面向对象 需要注意的是,在Python中,变量名类似__xxx__的,也就是以双下划线开头,并且以双下划线结尾的,是特殊变量,特殊变量是可以直接访问的,不是private变量,所以,不能用__na ...

  3. [Head First Python]4.读取文件datafile.txt, 去除两边空格, 存储到列表,从列表格式化(nester.py)后输出到文件man.out,other.out

    datafile.txt  #文件 Man: this is the right room for an argument. Other Man: I've told you once. Man: N ...

  4. Python学习的个人笔记(基础语法)

    Python学习的个人笔记 题外话: 我是一个大二的计算机系的学生,这份python学习个人笔记是趁寒假这一周在慕课网,w3cschool,还有借鉴了一些博客,资料整理出来的,用于自己方便的时候查阅, ...

  5. python基础语法及知识点总结

    本文转载于星过无痕的博客http://www.cnblogs.com/linxiangpeng/p/6403991.html 在此表达对原创作者的感激之情,多谢星过无痕的分享!谢谢! Python学习 ...

  6. Python错误和异常 学习笔记

    错误和异常概念 错误:     1.语法错误:代码不符合解释器或者编译器语法     2.逻辑错误:不完整或者不合法输入或者计算出现问题 异常:执行过程中出现万体导致程序无法执行     1.程序遇到 ...

  7. Python中的多进程与多线程(一)

    一.背景 最近在Azkaban的测试工作中,需要在测试环境下模拟线上的调度场景进行稳定性测试.故而重操python旧业,通过python编写脚本来构造类似线上的调度场景.在脚本编写过程中,碰到这样一个 ...

  8. Python高手之路【六】python基础之字符串格式化

    Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...

  9. Python 小而美的函数

    python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况   any any(iterable) ...

随机推荐

  1. 简单的angular购物车商品小计

    <!DOCTYPE html> <html lang="en" ng-app="shopApp"> <head> <m ...

  2. Quartz Cron表达式 在线生成器

    Cron Expressions——Cron 表达式 按顺序依次为 秒(0~59) 分钟(0~59) 小时(0~23) 天(月)(0~31,但是你需要考虑你月的天数) 月(0~11) 天(星期)(1~ ...

  3. 在 JS 中使用 fetch 更加高效地进行网络请求

    在前端快速发展地过程中,为了契合更好的设计模式,产生了 fetch 框架,此文将简要介绍下 fetch 的基本使用. 我的源博客地址:http://blog.parryqiu.com/2016/03/ ...

  4. rsyslog配置报错解决

    配置过程中,查看/var/log/meassage 有报错信息: action '*' treated as ':omusrmsg:*' - please use ':omusrmsg:*' synt ...

  5. eclipse关闭编译时不必要的校验

  6. 转 PresentViewController切换界面

    视图切换,没有NavigationController的情况下,一般会使用presentViewController来切换视图并携带切换时的动画, 其中切换方法如下: – presentViewCon ...

  7. iOS获取设备唯一标识的8种方法

    8种iOS获取设备唯一标识的方法,希望对大家有用. UDID UDID(Unique Device Identifier),iOS 设备的唯一识别码,是一个40位十六进制序列(越狱的设备通过某些工具可 ...

  8. nginx虚拟主机配置小结

    nginx的安装在lnmp环境搭建中已经介绍过了,配置文件在安装目录下的conf子目录下,主要主要分成四部分:main(全局设置).server(主机设置).upstream(负载均衡服务器设置).l ...

  9. Google Map API V3开发(1)

    Google Map API V3开发(1) Google Map API V3开发(2) Google Map API V3开发(3) Google Map API V3开发(4) Google M ...

  10. Loadrunner安装

    安装参考网址:http://www.cnblogs.com/yangxia-test/archive/2012/10/30/2746621.html 本人验证过的,不自己写了 另附Loadrunner ...