File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212print (f .readlines ())
1313f = open ("io/data/file1" ,mode = "rb" )
1414print (f .readlines ())
15+
16+ # write() error
17+ f = open ('io/data/file1' , 'r' )
18+ try :
19+ f .write ('x' )
20+ except OSError :
21+ print ('OSError' )
22+ f .close ()
23+
24+ # read(n) error on binary file
25+ f = open ('io/data/file1' , 'ab' )
26+ try :
27+ f .read (1 )
28+ except OSError :
29+ print ('OSError' )
30+ f .close ()
31+
32+ # read(n) error on text file
33+ f = open ('io/data/file1' , 'at' )
34+ try :
35+ f .read (1 )
36+ except OSError :
37+ print ('OSError' )
38+ f .close ()
39+
40+ # readall() error (call read() for compat with CPy)
41+ f = open ('io/data/file1' , 'ab' )
42+ try :
43+ f .read ()
44+ except OSError :
45+ print ('OSError' )
46+ f .close ()
Original file line number Diff line number Diff line change 55f = open ("io/data/file2" , "rb" )
66print (f .readinto (b ))
77print (b )
8+
9+ # readinto() on writable file
10+ f = open ('io/data/file1' , 'ab' )
11+ try :
12+ f .readinto (bytearray (4 ))
13+ except OSError :
14+ print ('OSError' )
Original file line number Diff line number Diff line change 44print (f .readline (4 ))
55print (f .readline (5 ))
66print (f .readline ())
7+
8+ # readline() on writable file
9+ f = open ('io/data/file1' , 'ab' )
10+ try :
11+ f .readline ()
12+ except OSError :
13+ print ('OSError' )
14+ f .close ()
Original file line number Diff line number Diff line change 2323print (f .read (5 ))
2424print (f .tell ())
2525f .close ()
26+
27+ # seek closed file
28+ f = open ('io/data/file1' , 'r' )
29+ f .close ()
30+ try :
31+ f .seek (1 )
32+ except (OSError , ValueError ):
33+ # CPy raises ValueError, uPy raises OSError
34+ print ('OSError or ValueError' )
You can’t perform that action at this time.
0 commit comments