• python FileError


      1 >>> ls1=["nihia"]
      2 >>> ls1
      3 ['nihia']
      4 >>> ls1.pop()
      5 'nihia'
      6 >>> ls1.append("sssss")
      7 >>> ls1
      8 ['sssss']
      9 >>> assert len(ls1)>0
     10 >>> ls1.pop()
     11 'sssss'
     12 >>> assert len(ls1)>0
     13 
     14 Traceback (most recent call last):
     15   File "<pyshell#38>", line 1, in <module>
     16     assert len(ls1)>0
     17 AssertionError
     18 >>> 
     19 >>> ls1.fishc
     20 
     21 Traceback (most recent call last):
     22   File "<pyshell#40>", line 1, in <module>
     23     ls1.fishc
     24 AttributeError: 'list' object has no attribute 'fishc'
     25 >>> 
     26 >>> ms1[3]
     27 
     28 Traceback (most recent call last):
     29   File "<pyshell#42>", line 1, in <module>
     30     ms1[3]
     31 NameError: name 'ms1' is not defined
     32 >>> ls1[3]
     33 
     34 Traceback (most recent call last):
     35   File "<pyshell#43>", line 1, in <module>
     36     ls1[3]
     37 IndexError: list index out of range
     38 >>> 
     39 >>> dict1={'one':1 ,'two':2}
     40 >>> dict1['one']
     41 1
     42 >>> dict1['four']
     43 
     44 Traceback (most recent call last):
     45   File "<pyshell#47>", line 1, in <module>
     46     dict1['four']
     47 KeyError: 'four'
     48 >>> dixt1.get('four')
     49 
     50 Traceback (most recent call last):
     51   File "<pyshell#48>", line 1, in <module>
     52     dixt1.get('four')
     53 NameError: name 'dixt1' is not defined
     54 >>> dict1.get('four')
     55 >>> dict1.get('two')
     56 2
     57 >>> 1+'1'
     58 
     59 Traceback (most recent call last):
     60   File "<pyshell#51>", line 1, in <module>
     61     1+'1'
     62 TypeError: unsupported operand type(s) for +: 'int' and 'str'
     63 >>> 5/0
     64 
     65 Traceback (most recent call last):
     66   File "<pyshell#52>", line 1, in <module>
     67     5/0
     68 ZeroDivisionError: integer division or modulo by zero
     69 >>> 
     70 >>> 
     71 >>> 
     72 >>> 
     73 >>> ================================ RESTART ================================
     74 >>> 
     75 
     76 Traceback (most recent call last):
     77   File "/tmp/guest-WX48w4/文档/py1.py", line 2, in <module>
     78     file_name=open('myname')
     79 IOError: [Errno 2] No such file or directory: 'myname'
     80 >>> ================================ RESTART ================================
     81 >>> 
     82 
     83 Traceback (most recent call last):
     84   File "/tmp/guest-WX48w4/文档/py1.py", line 2, in <module>
     85     file_name=open('myname.txt')
     86 IOError: [Errno 2] No such file or directory: 'myname.txt'
     87 >>> ================================ RESTART ================================
     88 >>> 
     89 wrong
     90 [Errno 2] No such file or directory: 'myname.txt'
     91 >>> ================================ RESTART ================================
     92 >>> 
     93 wrong
     94 [Errno 2] No such file or directory: 'myname.txt'
     95 >>> ================================ RESTART ================================
     96 >>> 
     97 
     98 Traceback (most recent call last):
     99   File "/tmp/guest-WX48w4/文档/py1.py", line 2, in <module>
    100     name=a+'1'
    101 NameError: name 'a' is not defined
    102 >>> ================================ RESTART ================================
    103 >>> 
    104 wrong
    105 unsupported operand type(s) for +: 'int' and 'str'
    106 >>> ================================ RESTART ================================
    107 >>> 
    108 
    109 Traceback (most recent call last):
    110   File "/tmp/guest-WX48w4/文档/py1.py", line 2, in <module>
    111     int ('abc')
    112 ValueError: invalid literal for int() with base 10: 'abc'
    113 >>> ================================ RESTART ================================
    114 >>> 
    115 
    116 Traceback (most recent call last):
    117   File "/tmp/guest-WX48w4/文档/py1.py", line 5, in <module>
    118     print (file_name.read())
    119 NameError: name 'file_name' is not defined
    120 >>> 1/0
    121 
    122 Traceback (most recent call last):
    123   File "<pyshell#57>", line 1, in <module>
    124     1/0
    125 ZeroDivisionError: integer division or modulo by zero
    126 >>> raise 1/0
    127 
    128 Traceback (most recent call last):
    129   File "<pyshell#58>", line 1, in <module>
    130     raise 1/0
    131 ZeroDivisionError: integer division or modulo by zero
    132 >>> 
     1 try:
     2     int ('123')
     3     #name=1+'1'
     4     #file_name=open('myname.txt')
     5     print (file_name.read())
     6     file_name.close()
     7 except IOError as reason:  #eg1
     8     print ('wrong
    '+str(reason))
     9 except TypeError as reason:
    10     print ('wrong
    '+str(reason))
    11 except:     #eg2
    12     print ('wrong
    '+str(reason))
    13 except (TypeError,IOError):     #eg3
    14     print ('wrong
    '+str(reason))
    15 finally:    #keep away from not closing the  file
    16     file_name.close()
    17 
    18     
  • 相关阅读:
    centos文件与权限
    python执行centos命令
    Centos下新建用户及修改用户目录
    微信现金红包 python
    图像直方图
    十三种基于直方图的图像全局二值化算法原理、实现、代码及效果。
    图像处理之常见二值化方法汇总
    OpenCV中对图像进行二值化的关键函数——cvThreshold()。
    cvLoadImage
    cvGet2D的用法
  • 原文地址:https://www.cnblogs.com/13224ACMer/p/6049473.html
Copyright © 2020-2023  润新知