File tree 2 files changed +5
-5
lines changed 2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change 54
54
{
55
55
"data" : {
56
56
"text/plain" : [
57
- " <_io.TextIOWrapper name='test-file.txt' mode='w' encoding='UTF-8'>"
57
+ " <_io.TextIOWrapper name='/tmp/ test-file.txt' mode='w' encoding='UTF-8'>"
58
58
]
59
59
},
60
60
"execution_count" : 1 ,
Original file line number Diff line number Diff line change 29
29
open (' /tmp/test-file.txt' , ' w' )
30
30
```
31
31
32
- <_io.TextIOWrapper name='test-file.txt' mode='w' encoding='UTF-8'>
32
+ <_io.TextIOWrapper name='/tmp/ test-file.txt' mode='w' encoding='UTF-8'>
33
33
34
34
当然,更多的时候,我们会把这个函数的返回值,一个所谓的 [ file object] ( https://docs.python.org/3/glossary.html#term-file-object ) ,保存到一个变量中,以便后面调用这个 file object 的各种 Methods,比如获取文件名 ` file.name ` ,比如关闭文件 ` file.close() ` :
35
35
@@ -39,7 +39,7 @@ print(f.name)
39
39
f.close()
40
40
```
41
41
42
- test-file.txt
42
+ /tmp/ test-file.txt
43
43
44
44
## 删除文件
45
45
58
58
print (f ' { f.name} does not exist. ' )
59
59
```
60
60
61
- test-file1.txt
62
- test-file1.txt deleted.
61
+ /tmp/ test-file1.txt
62
+ /tmp/ test-file1.txt deleted.
63
63
64
64
## 读写文件
65
65
You can’t perform that action at this time.
0 commit comments