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) ...
随机推荐
- hdu[1711]number sequence
Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], .... ...
- 将“早期版本的Windows”改名
将“早期版本的Windows”改名,并修改系统等待时间 问题描述: 先装Windows XP,再装Windows 7,启动菜单会出现“早期版本的Windows”与“Windows 7”两个 ...
- jquery easyui 1.4.1 API( CHM版)
ChangeLog Bug The combogrid has different height than other combo components. fixed. datagrid: The r ...
- 扩展 DbUtility (1)
本文原始路径: https://www.zybuluo.com/Ivony/note/14074 前言 DbUtility v3 是一个开源的轻量级数据库访问框架,源代码通过 Apache 协议发布, ...
- jquery-leonaScroll-1.2-自定义滚动条插件
leonaScroll-1.2.js 下载链接地址:http://share.weiyun.com/bb531dd6b1916c0023c176897182dc15 (密码:iZck)[内含压缩版] ...
- 如何让tableViewCell的分割线从边框顶端开始
在ios8上 [TableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];不起作用 经过测试加入下面方法 在ios7 8上都可以正常工作 -(voi ...
- 关于解决asp.net mvc网站页面Banner图片即时更换css里背景图片url相对路径问题的新方案
最近在网站首页上想将Banner壁纸给做到后台上传随时更改的效果.遇到问题便是:将上传的图片路径动态添加到首页css代码中,结果尝试了网上提供的思路,更改相对路径,换为url中“../../Conte ...
- VS 团队资源管理 强制解锁锁定文件
故事是这样发生的: 以前有台电脑,在团队资源里看程序,可能冥冥中不小心按了个空格,so,文件被锁定 而我却没有发现 如果再给我一个机会,我只想说记得签入 然后,高潮来了 重装电脑 欣喜的装好新机子打开 ...
- Web Analytics 2.0 中文翻译 [ 系列索引 ]
引言 内容概述 第一章:网站分析2.0的新奇世界 第二章:选择你的网络分析灵魂伴侣的最佳策略 第三章:点击流分析的奇妙世界:指标 第四章:点击流分析的奇妙世界:实际的解决方案 第五章:荣耀之钥:度量成 ...
- linux之sed用法
参考 http://www.cnblogs.com/dong008259/archive/2011/12/07/2279897.html sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行 ...