@@ -108,7 +108,7 @@ Fork me on [GitHub](https://github.com/pynickle/python-cheatsheet-redefined).
108108
109109``` python
110110>> > import string
111-
111+ >> >
112112>> > # not locale-dependent
113113>> > string.ascii_letters
114114' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -959,7 +959,7 @@ pickle A
959959>> > import shelve
960960>> >
961961>> > # Open a shelf file (creates if not exists)
962- >> > with shelve.open(' geenrated /mydata.db' ) as db:
962+ >> > with shelve.open(' generated /mydata.db' ) as db:
963963... # Basic operations: set, get, delete, check existence
964964... db[' name' ] = ' Alice'
965965... db[' numbers' ] = [1 , 2 , 3 ]
@@ -978,12 +978,12 @@ pickle A
978978... # Sync to ensure data is written to disk
979979... db.sync()
980980...
981- Alice
981+ ' Alice'
982982True
983983[' name' , ' numbers' ]
984984>> >
985985>> > # Re-open with writeback=True for direct modification
986- >> > db = shelve.open(' mydata.db' , writeback = True )
986+ >> > db = shelve.open(' generated/ mydata.db' , writeback = True )
987987>> > db[' numbers' ].append(5 ) # Direct modify (auto-persisted on close)
988988>> > db[' numbers' ]
989989[1 , 2 , 3 , 4 , 5 ]
@@ -1401,31 +1401,31 @@ _wave_params(nchannels=2, sampwidth=2, framerate=44100, nframes=442368, comptype
14011401>> >
14021402>> > zh_trans = gettext.translation(
14031403... DOMAIN ,
1404- ... localedir = LOCALE_DIR ,
1405- ... languages = [' zh' ],
1406- ... fallback = True # 找不到 .mo 时不报错
1404+ ... localedir = LOCALE_DIR ,
1405+ ... languages = [' zh' ],
1406+ ... fallback = True
14071407... )
14081408>> >
14091409>> > en_trans = gettext.translation(
14101410... DOMAIN ,
1411- ... localedir = LOCALE_DIR ,
1412- ... languages = [' en' ],
1413- ... fallback = True
1411+ ... localedir = LOCALE_DIR ,
1412+ ... languages = [' en' ],
1413+ ... fallback = True
14141414... )
14151415>> >
14161416>> > _zh = zh_trans.gettext # Get the specific gettext function from the instance
14171417>> > _zh(' hello_world' )
1418- 你好,世界!
1418+ ' 你好,世界!'
14191419>> >
14201420>> > # Install the Chinese translation globally
14211421>> > # This sets the global _() function for all modules to use zh_trans.
14221422>> > zh_trans.install()
1423- >> > _(' hello_world' ))
1424- 你好,世界!
1423+ >> > _(' hello_world' )
1424+ ' 你好,世界!'
14251425>> >
14261426>> > en_trans.install()
14271427>> > _(' hello_world' )
1428- Hello, world!
1428+ ' Hello, world!'
14291429```
14301430
14311431# # turtle
@@ -1797,14 +1797,10 @@ True
17971797# ### importer
17981798
17991799```python
1800- >> > import zipimport
1801- >> > zip = zipimport.zipimporter(" g.zip" )
1802- >> > zip .archive
1803- ' g.zip'
1804- >> >
1805- >> > a = zip .load_module(" a" )
1806- >> > a
1807- < module ' a' from ' D:\\ GitHub\\ python-cheatsheet-redefined\\ test_env\\ g.zip\\ a.py' >
1800+ >> > # the zipimport module is not explicitly used
1801+ >> > import sys
1802+ >> > sys.path.insert(0 , ' g.zip' )
1803+ >> > import a
18081804>> > a.main()
18091805Hello everyone
18101806```
0 commit comments