>>> 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. python-网络编程-socket编程

    一.TCP\IP(网络通信协议)简介       TCP:(Transmission Control Protocol)传输控制协议,面向有连接的通信协议  UDP:数据报文协议,面向无连接的通信协议 ...

  2. 鼠标/手指相对于元素的坐标(px转百分比)

    鼠标/手指相对于元素的坐标:鼠标或手指当前的位置 - 元素距离文档的位置 px转百分比:px / 文档尺寸 * 100 获取手指触摸在屏幕中相对于元素的坐标(px转百分比): $('#div').on ...

  3. Writing Clean Code 读后感

    最近花了一些时间看了这本书,书名是 <Writing Clean Code ── Microsoft Techniques for Developing Bug-free C Programs& ...

  4. 订餐系统之微信支付,踩了官方demo的坑

        最近一个项目要增加微信支付的功能,想来这个东西出来这么久了,按微信提供的应该可以很快搞定的,结果提供的demo( JS API网页支付)中各种坑,咨询他们的客服,态度倒是非常好,就是解决不了问 ...

  5. C# 如何生成一个时间戳

    在程序中,常常会用到时间戳,如何生成一个时间戳呢? /// <summary> /// 获取时间戳 /// </summary> /// <returns>< ...

  6. dubbo zk 分布式服务项目搭建与配置

    1. 项目 jar  -----提供接口 2. 项目 jar  -----接口实现   provider启动zk main方法启动 start applicationContext.xml <b ...

  7. linux免交互登陆远程主机并执行命令(密钥对和Expect)

    原文章摘自:http://lizhenliang.blog.51cto.com/7876557/1607723/ Linux下实现免交互登陆一般有两种: 1. SSH无密码认证方式 客户端使用ssh- ...

  8. C#稳固基础:传统遍历与迭代器

    Hello,Coders.我们除了天天的码 if…else…之外,还会不断的码出foreach.我今天要说的是:传统遍历需实现的接口及我们还有一种更简洁优雅的方式实现多种迭代器. 传统遍历 传统的遍历 ...

  9. jeecg表单页面控件权限设置(请先看官方教程,如果能看懂就不用看这里了)

    只是把看了官方教程后,觉得不清楚地方补充说明一下: 1. 2. 3. 4.用"jeecgDemoController.do?addorupdate"这个路径测试,不出意外现在应该可 ...

  10. Ubuntu16.04/LinuxMint18安装openjdk-7-jdk

    LinuxMint18的安装源已经默认没有openjdk7了,所以要自己手动添加仓库,如下: sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-ge ...