mirror of
https://github.com/apachecn/ailearning.git
synced 2026-05-11 11:07:31 +08:00
2020-10-19 21:08:55
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
In [1]:
|
||||
|
||||
```
|
||||
```py
|
||||
import shutil
|
||||
import os
|
||||
|
||||
@@ -14,7 +14,7 @@ import os
|
||||
|
||||
In [2]:
|
||||
|
||||
```
|
||||
```py
|
||||
with open("test.file", "w") as f:
|
||||
pass
|
||||
|
||||
@@ -22,7 +22,7 @@ print "test.file" in os.listdir(os.curdir)
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
True
|
||||
|
||||
```
|
||||
@@ -31,7 +31,7 @@ True
|
||||
|
||||
In [3]:
|
||||
|
||||
```
|
||||
```py
|
||||
shutil.copy("test.file", "test.copy.file")
|
||||
|
||||
print "test.file" in os.listdir(os.curdir)
|
||||
@@ -39,7 +39,7 @@ print "test.copy.file" in os.listdir(os.curdir)
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
True
|
||||
True
|
||||
|
||||
@@ -49,7 +49,7 @@ True
|
||||
|
||||
In [4]:
|
||||
|
||||
```
|
||||
```py
|
||||
try:
|
||||
shutil.copy("test.file", "my_test_dir/test.copy.file")
|
||||
except IOError as msg:
|
||||
@@ -57,7 +57,7 @@ except IOError as msg:
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
[Errno 2] No such file or directory: 'my_test_dir/test.copy.file'
|
||||
|
||||
```
|
||||
@@ -70,7 +70,7 @@ except IOError as msg:
|
||||
|
||||
In [5]:
|
||||
|
||||
```
|
||||
```py
|
||||
os.renames("test.file", "test_dir/test.file")
|
||||
os.renames("test.copy.file", "test_dir/test.copy.file")
|
||||
|
||||
@@ -80,7 +80,7 @@ os.renames("test.copy.file", "test_dir/test.copy.file")
|
||||
|
||||
In [6]:
|
||||
|
||||
```
|
||||
```py
|
||||
shutil.copytree("test_dir/", "test_dir_copy/")
|
||||
|
||||
"test_dir_copy" in os.listdir(os.curdir)
|
||||
@@ -89,7 +89,7 @@ shutil.copytree("test_dir/", "test_dir_copy/")
|
||||
|
||||
Out[6]:
|
||||
|
||||
```
|
||||
```py
|
||||
True
|
||||
```
|
||||
|
||||
@@ -99,7 +99,7 @@ True
|
||||
|
||||
In [7]:
|
||||
|
||||
```
|
||||
```py
|
||||
try:
|
||||
os.removedirs("test_dir_copy")
|
||||
except Exception as msg:
|
||||
@@ -107,7 +107,7 @@ except Exception as msg:
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
[Errno 39] Directory not empty: 'test_dir_copy'
|
||||
|
||||
```
|
||||
@@ -116,7 +116,7 @@ except Exception as msg:
|
||||
|
||||
In [8]:
|
||||
|
||||
```
|
||||
```py
|
||||
shutil.rmtree("test_dir_copy")
|
||||
|
||||
```
|
||||
@@ -131,14 +131,14 @@ shutil.rmtree("test_dir_copy")
|
||||
|
||||
In [9]:
|
||||
|
||||
```
|
||||
```py
|
||||
shutil.get_archive_formats()
|
||||
|
||||
```
|
||||
|
||||
Out[9]:
|
||||
|
||||
```
|
||||
```py
|
||||
[('bztar', "bzip2'ed tar-file"),
|
||||
('gztar', "gzip'ed tar-file"),
|
||||
('tar', 'uncompressed tar file'),
|
||||
@@ -151,14 +151,14 @@ Out[9]:
|
||||
|
||||
In [10]:
|
||||
|
||||
```
|
||||
```py
|
||||
shutil.make_archive("test_archive", "zip", "test_dir/")
|
||||
|
||||
```
|
||||
|
||||
Out[10]:
|
||||
|
||||
```
|
||||
```py
|
||||
'/home/lijin/notes-python/11\. useful tools/test_archive.zip'
|
||||
```
|
||||
|
||||
@@ -166,7 +166,7 @@ Out[10]:
|
||||
|
||||
In [11]:
|
||||
|
||||
```
|
||||
```py
|
||||
os.remove("test_archive.zip")
|
||||
shutil.rmtree("test_dir/")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user