python FileError
>>> 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的更多相关文章
- python click module for command line interface
Click Module(一) ----xiaojikuaipao The following mat ...
- python异常以及面向对象编程
一.面向对象 需要注意的是,在Python中,变量名类似__xxx__的,也就是以双下划线开头,并且以双下划线结尾的,是特殊变量,特殊变量是可以直接访问的,不是private变量,所以,不能用__na ...
- [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 ...
- Python学习的个人笔记(基础语法)
Python学习的个人笔记 题外话: 我是一个大二的计算机系的学生,这份python学习个人笔记是趁寒假这一周在慕课网,w3cschool,还有借鉴了一些博客,资料整理出来的,用于自己方便的时候查阅, ...
- python基础语法及知识点总结
本文转载于星过无痕的博客http://www.cnblogs.com/linxiangpeng/p/6403991.html 在此表达对原创作者的感激之情,多谢星过无痕的分享!谢谢! Python学习 ...
- Python错误和异常 学习笔记
错误和异常概念 错误: 1.语法错误:代码不符合解释器或者编译器语法 2.逻辑错误:不完整或者不合法输入或者计算出现问题 异常:执行过程中出现万体导致程序无法执行 1.程序遇到 ...
- Python中的多进程与多线程(一)
一.背景 最近在Azkaban的测试工作中,需要在测试环境下模拟线上的调度场景进行稳定性测试.故而重操python旧业,通过python编写脚本来构造类似线上的调度场景.在脚本编写过程中,碰到这样一个 ...
- Python高手之路【六】python基础之字符串格式化
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...
- Python 小而美的函数
python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况 any any(iterable) ...
随机推荐
- 初学C#和MVC的一些心得,弯路,总结,还有教训(2)--关于Entity Framework
看了一堆视频教程后,感觉基本了解的差不多了,可以动手.....因为最好的学习方法就是实践嘛.... 所以打算从网站做起,在WebForm和MVC之间选了MVC,因为感觉高大上...也比较灵活 于是买了 ...
- jQuery之DOM属性
1. .addClass()方法:为每个匹配的元素添加指定的样式类名.值得注意的是设个方法不会替换一个样式类名.他只是简单的添加一个样式类名到元素上.对所有匹配的元素可以一次添加多个用空格隔开的样式类 ...
- 红米3 Flyme5.1.9.5插桩适配长期不定时更新
ROM介绍: 2016.9.5更新日志: 1,更新源码到0905 2.修复bug若干. 2016.8.29更新日志: 1,更新源码到0829 2.修复bug若干. 2016.8.22更新日志: 1,更 ...
- C#中的try catch 和finally
错误的出现并不总是编写应用程序的人的原因,有时应用程序会因为终端用户的操作而发生错误.无论如何,我们都应预测应用程序和代码中出现的错误. 这三个关键字try是必定要用的,要不然就失去了意义.然后cat ...
- _UICreateCGImageFromIOSurface 使用API
上传的时候,苹果发送邮件 Non-public API usage: The app references non-public symbols in DUO-LINK 4: _UICreateCGI ...
- 【bzoj1923】 Sdoi2010—外星千足虫
http://www.lydsy.com/JudgeOnline/problem.php?id=1923 (题目链接) 题意 按顺序给出m个n元模线性方程,问最少当给出多少个方程时整个方程组有解. S ...
- a版本冲刺第一天
队名:Aruba 队员: 黄辉昌 李陈辉 林炳锋 鄢继仁 张秀锋 章 鼎 学号 昨天完成的任务 今天做的任务 明天要做的任务 困难点 体会 408 学习测试文档的编写 继续学习并借鉴,开始着手写 ...
- 洛谷P2434 [SDOI2005]区间
题目描述 现给定n个闭区间[ai, bi],1<=i<=n.这些区间的并可以表示为一些不相交的闭区间的并.你的任务就是在这些表示方式中找出包含最少区间的方案.你的输出应该按照区间的升序排列 ...
- SDL 截图、录像、录像播放
截图 使用sdl很简单,视频显示窗口大小,不是视频分辨率大小 int i = Sdl.SDL_SaveBMP(surfacePtr, path); if(i != 0) { MessageBox.Sh ...
- centos6.5升级python为2.7
今天线上服务器全部升级python环境为python-2.7.6的环境,我采用的方法是ansible+shell,代码如下,友提,Python-2.7.6.tgz.setuptools-14.3.1. ...