Skip to content

Commit 69d31f6

Browse files
committed
fix: ensure all code pass test in 3.13.7
1 parent 107d182 commit 69d31f6

6 files changed

Lines changed: 189 additions & 137 deletions

File tree

‎README-zh-cn.md‎

Lines changed: 53 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@
198198
... """
199199
>>> text1_lines = text1.splitlines()
200200
>>> text2_lines = text2.splitlines()
201-
>>> with open("HtmlDiff.html", "w", encoding="utf-8") as f: # make it a html file
202-
... HtmlDiff = d.make_file(text1_lines, text2_lines)
201+
>>> with open("generated/HtmlDiff.html", "w", encoding="utf-8") as f:
202+
... HtmlDiff = d.make_file(text1_lines, text2_lines) # make it a html file
203203
... f.write(HtmlDiff)
204204
...
205-
3331
205+
3391
206206
```
207207

208208
#### SequenceMatcher
@@ -259,7 +259,7 @@ Match(a=1, b=0, size=4)
259259
>>> unicodedata.name("(") # reverse to lookup
260260
'LEFT PARENTHESIS'
261261
>>> unicodedata.unidata_version
262-
'13.0.0'
262+
'15.1.0'
263263
```
264264

265265
## readline
@@ -379,7 +379,7 @@ deque(['a', 'b', 'c', 'd', 'e'])
379379
'None'
380380
>>> od = collections.OrderedDict([("a", 1), ("b", 2)]) # dict which always keeps the order
381381
>>> od
382-
OrderedDict([('a', 1), ('b', 2)])
382+
OrderedDict({'a': 1, 'b': 2})
383383
>>> c = collections.Counter() # dict subclass for counting hashable objects
384384
>>> for i in "Hello, World":
385385
... c[i] = c[i] + 1
@@ -733,9 +733,9 @@ False
733733
>>> import os.path
734734
>>> os.path.exists(".")
735735
True
736-
>>> os.path.getsize("./LICENSE")
737-
466
738-
>>> os.path.isfile("./README.md")
736+
>>> os.path.getsize("cmp1.txt")
737+
15
738+
>>> os.path.isfile("cmp1.txt")
739739
True
740740
>>> os.path.isdir("./doc")
741741
False
@@ -749,8 +749,8 @@ False
749749

750750
```python
751751
>>> import glob
752-
>>> glob.glob("*.pdf", recursive = True)
753-
['README-zh-cn.pdf', 'README.pdf']
752+
>>> glob.glob("*.txt", recursive = True)
753+
['cmp1.txt', 'cmp2.txt', 'doctest_example.txt']
754754
```
755755

756756
## tempfile
@@ -789,7 +789,7 @@ b'a'
789789

790790
```python
791791
>>> import filecmp
792-
>>> filecmp.cmp("test_env/cmp1.txt", "test_env/cmp2.txt")
792+
>>> filecmp.cmp("cmp1.txt", "cmp2.txt")
793793
True
794794
```
795795

@@ -799,17 +799,19 @@ True
799799

800800
```python
801801
>>> import os
802-
>>> cmd = os.popen("python examples/fileinput_example.py examples/cmp1.txt") # subprocess.Popen provides more features
802+
>>> cmd = os.popen("python fileinput_example.py cmp1.txt") # subprocess.Popen provides more features
803803
>>> print(cmd.read())
804-
examples/cmp1.txt | Line Number: 1 |: 1
804+
cmp1.txt | Line Number: 1 |: 1
805+
806+
cmp1.txt | Line Number: 2 |: 2
805807

806-
examples/cmp1.txt | Line Number: 2 |: 2
808+
cmp1.txt | Line Number: 3 |: 3
807809

808-
examples/cmp1.txt | Line Number: 3 |: 3
810+
cmp1.txt | Line Number: 4 |: 4
811+
812+
cmp1.txt | Line Number: 5 |: 5
809813

810-
examples/cmp1.txt | Line Number: 4 |: 4
811814

812-
examples/cmp1.txt | Line Number: 5 |: 5
813815
```
814816

815817
## shutil
@@ -818,11 +820,11 @@ examples/cmp1.txt | Line Number: 5 |: 5
818820

819821
```python
820822
>>> import shutil
821-
>>> shutil.copyfile("test_env/song.wav", "test_env/copysong.wav")
822-
'examples/copysong.wav'
823+
>>> shutil.copyfile("song.wav", "copysong.wav")
824+
'copysong.wav'
823825
>>> shutil.rmtree("shutil_tree") # can delete tree has contents, os.remove can't
824-
>>> shutil.move("test_env/copysong.wav", "myapp/copysong.wav")
825-
'myapp/copysong.wav'
826+
>>> shutil.move("copysong.wav", "generated/copysong_move.wav")
827+
'generated/copysong_move.wav'
826828
```
827829

828830
## linecache
@@ -831,7 +833,7 @@ examples/cmp1.txt | Line Number: 5 |: 5
831833

832834
```python
833835
>>> import linecache
834-
>>> linecache.getline("test_env/readme_snatcher.py", 1) # start from one, not zero
836+
>>> linecache.getline("readme_snatcher.py", 1) # start from one, not zero
835837
'from sys import exit\n'
836838
```
837839

@@ -905,11 +907,11 @@ b'Hello, python3!'
905907

906908
```python
907909
>>> import zipfile
908-
>>> with zipfile.ZipFile("test_env/g.zip") as f: # extract zip file
909-
... f.extractall()
910+
>>> with zipfile.ZipFile("g.zip") as f: # extract zip file
911+
... f.extractall("generated")
910912
...
911-
>>> with zipfile.ZipFile("a.zip", "a") as zip: # create zip file
912-
... zip.write("README.md") # use write method to write files into zip file
913+
>>> with zipfile.ZipFile("generated/a.zip", "a") as zip: # create zip file
914+
... zip.write("cmp1.txt") # use write method to write files into zip file
913915
...
914916
```
915917

@@ -920,8 +922,8 @@ b'Hello, python3!'
920922
```python
921923
>>> import configparser
922924
>>> config = configparser.ConfigParser() # create an instance
923-
>>> config.read("examples/config.ini")
924-
['examples/config.ini']
925+
>>> config.read("config.ini")
926+
['config.ini']
925927
>>> config.sections()
926928
['python', 'java']
927929
>>> config["python"]["type"] # all sections has values in DEFAULT
@@ -1092,6 +1094,7 @@ optional arguments:
10921094
-s SUM [SUM ...], --sum SUM [SUM ...]
10931095
-r REQUIRED, --required REQUIRED
10941096
-t, --true
1097+
10951098
```
10961099

10971100
## errno
@@ -1164,7 +1167,7 @@ Received b'Hello, world'
11641167
```python
11651168
>>> import html
11661169
>>> html.escape("As we all know, 2>1")
1167-
'As we all know, 2>1'
1170+
'As we all know, 2>1'
11681171
>>> html.unescape('As we all know, 2>1')
11691172
'As we all know, 2>1'
11701173
```
@@ -1189,31 +1192,11 @@ True
11891192

11901193
```python
11911194
>>> import wave
1192-
>>> f = wave.open("test_env/song.wav", "rb")
1195+
>>> f = wave.open("song.wav", "rb")
11931196
>>> f.getparams()
11941197
_wave_params(nchannels=2, sampwidth=2, framerate=44100, nframes=442368, comptype='NONE', compname='not compressed')
11951198
```
11961199

1197-
## sndhdr
1198-
1199-
#### what
1200-
1201-
```python
1202-
>>> import sndhdr
1203-
>>> sndhdr.what("examples/song.wav")
1204-
SndHeaders(filetype='wav', framerate=44100, nchannels=2, nframes=442368, sampwidth=16)
1205-
```
1206-
1207-
## imghdr
1208-
1209-
#### what
1210-
1211-
```python
1212-
>>> import imghdr
1213-
>>> imghdr.what("examples/china.jpg")
1214-
'jpeg'
1215-
```
1216-
12171200
## colorsys
12181201

12191202
#### rgb_to_yiq, rgb_to_hls, rgb_to_hsv
@@ -1280,7 +1263,7 @@ python tkinter_example.py
12801263

12811264
```python
12821265
>>> import doctest
1283-
>>> doctest.testfile("../examples/doctest_example.txt", verbose=True)
1266+
>>> doctest.testfile("doctest_example.txt", verbose=True)
12841267
Trying:
12851268
from doctest_example import factorial
12861269
Expecting nothing
@@ -1388,8 +1371,8 @@ python -m ensurepip --upgrade # upgrade pip
13881371

13891372
```python
13901373
>>> import zipapp
1391-
>>> zipapp.create_archive("myapp", "test_env/myapp.pyz")
1392-
>>> __import__("os").popen("python examples/myapp.pyz").read() # pyz file can also be executed
1374+
>>> zipapp.create_archive("myapp", "generated/myapp.pyz")
1375+
>>> __import__("os").popen("python generated/myapp.pyz").read() # pyz file can also be executed
13931376
'Hello, everyone!\n'
13941377
```
13951378

@@ -1488,7 +1471,7 @@ __exit__ cm
14881471
...
14891472
>>> user1 = UserOne()
14901473
>>> dir(user1)
1491-
['__abstractmethods__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_abc_impl', 'age', 'hello', 'unique_hello']
1474+
['__abstractmethods__', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__firstlineno__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__static_attributes__', '__str__', '__subclasshook__', '__weakref__', '_abc_impl', 'age', 'hello', 'unique_hello']
14921475
>>> isinstance(user1, User)
14931476
True
14941477
>>> class UserTwo():
@@ -1498,7 +1481,7 @@ True
14981481
<class '__main__.UserTwo'>
14991482
>>> user2 = UserTwo()
15001483
>>> dir(user2)
1501-
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__']
1484+
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__firstlineno__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__static_attributes__', '__str__', '__subclasshook__', '__weakref__']
15021485
>>> issubclass(UserTwo, User)
15031486
True
15041487
```
@@ -1598,13 +1581,13 @@ True
15981581

15991582
```python
16001583
>>> import zipimport
1601-
>>> zip = zipimport.zipimporter("test_env/g.zip")
1584+
>>> zip = zipimport.zipimporter("g.zip")
16021585
>>> zip.archive
1603-
'examples\\g.zip'
1586+
'g.zip'
16041587
>>>
16051588
>>> a = zip.load_module("a")
16061589
>>> a
1607-
<module 'a' from 'examples\\g.zip\\a.py'>
1590+
<module 'a' from 'D:\\GitHub\\python-cheatsheet-redefined\\test_env\\g.zip\\a.py'>
16081591
>>> a.main()
16091592
Hello everyone
16101593
```
@@ -1693,7 +1676,7 @@ ValueError: malformed node or string: <_ast.Call object at 0x00B11C50>
16931676
[1, 2, 3]
16941677
>>> hello_world = ast.parse("print('Hello World!')", "<string)", "exec") # abstract syntax trees
16951678
>>> ast.dump(hello_world)
1696-
"Module(body=[Expr(value=Call(func=Name(id='print', ctx=Load()), args=[Constant(value='Hello World!')], keywords=[]))], type_ignores=[])"
1679+
"Module(body=[Expr(value=Call(func=Name(id='print', ctx=Load()), args=[Constant(value='Hello World!')]))])"
16971680
```
16981681

16991682
## keyword
@@ -1703,7 +1686,7 @@ ValueError: malformed node or string: <_ast.Call object at 0x00B11C50>
17031686
```python
17041687
>>> import keyword
17051688
>>> keyword.kwlist
1706-
['False', 'None', 'True', '__peg_parser__', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
1689+
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
17071690
>>> keyword.iskeyword("True")
17081691
True
17091692
```
@@ -1718,12 +1701,13 @@ True
17181701
... print("Hello World")
17191702
...
17201703
>>> dis.dis(func)
1721-
2 0 LOAD_GLOBAL 0 (print)
1722-
2 LOAD_CONST 1 ('Hello World')
1723-
4 CALL_FUNCTION 1
1724-
6 POP_TOP
1725-
8 LOAD_CONST 0 (None)
1726-
10 RETURN_VALUE
1704+
1 RESUME 0
1705+
1706+
2 LOAD_GLOBAL 1 (print + NULL)
1707+
LOAD_CONST 1 ('Hello World')
1708+
CALL 1
1709+
POP_TOP
1710+
RETURN_CONST 0 (None)
17271711
>>> dis.show_code(func)
17281712
Name: func
17291713
Filename: <stdin>
@@ -1748,10 +1732,10 @@ Names:
17481732
```python
17491733
>>> import tabnanny
17501734
>>> tabnanny.verbose = True
1751-
>>> tabnanny.check("test_env/tabnanny_example.py")
1752-
'examples/tabnanny_example.py': *** Line 3: trouble in tab city! ***
1735+
>>> tabnanny.check("tabnanny_example.py")
1736+
'tabnanny_example.py': *** Line 3: trouble in tab city! ***
17531737
offending line: '\tprint(i)'
1754-
indent not greater e.g. at tab sizes 1, 2, 3, 4
1738+
inconsistent use of tabs and spaces in indentation
17551739
```
17561740

17571741
## this

0 commit comments

Comments
 (0)