@@ -28,7 +28,7 @@ Document's Author: Mahmoud Harmouch
2828 1.2.5 [Zip](#1.2.5)
2929 1.3 [Other Builtin Functions](#1.3)
30302 . [ File I/O] ( #2 )
31- 3 . [ Generators ] ( #3 )
31+ 3 . [ Standard Modules ] ( #3 )
3232
3333## 1. Functions. <a name =" 1 " ></a >
3434
@@ -458,6 +458,8 @@ For more information about functionnal progamming, please refer to [python docs]
458458
459459## 1.3 Other Builtin Functions. <a name =" 1.3 " ></a >
460460
461+ [ Python Docs.] ( https://docs.python.org/3/library/functions.html )
462+
461463These functions are grouped together in the ` __builtins__ ` module.
462464
463465``` python
@@ -1889,4 +1891,229 @@ False
18891891True
18901892```
18911893
1894+ # # 3. [Standard Modules.](https://docs.python.org/3/library/index.html) <a name="3"></a>
1895+
1896+ Standard modules can be divided into groups by topic.
1897+
1898+ pathlib — Object- oriented filesystem paths
1899+ os.path — Common pathname manipulations
1900+ fileinput — Iterate over lines from multiple input streams
1901+ stat — Interpreting stat() results
1902+ filecmp — File and Directory Comparisons
1903+ tempfile — Generate temporary files and directories
1904+ glob — Unix style pathname pattern expansion
1905+ fnmatch — Unix filename pattern matching
1906+ linecache — Random access to text lines
1907+ shutil — High- level file operations
1908+
1909+
1910+ | Topic | Modules |
1911+ | -- - | -- - |
1912+ | Internet Data Handling | base64, binhex, binascii, email, json, mailbox, mailcap, mimetypes, quopri, uu. |
1913+ | Development Tools | unittest, typing , pydoc, doctest, test, 2to3
1914+ | Debugging and Profiling | cProfile, faulthandler , pdb, profile, trace, tracemalloc. |
1915+ | Graphical | IDLE , PyGObject, PyGTK, PyQt, PySide2, wxPython, Tkinter. |
1916+ | Internet Protocols | cgi, cgitb, imaplib, ipaddress, nntplib, poplib, smtplib, socket, syncore, telnetlib, urllib, urllib2. |
1917+ | Platform | UNIX : pwd , grp , fcntl , resource , termios. |
1918+ | Language Services | ast, compileall, dis, keyword, parser, pickletools, pyclbr, py_compile, symbol, symtable, tabnanny, token, tokenize. |
1919+ | Networking | asyncio, asynchat, asyncore, mmap, select, selectors, signal, socket, ssl. |
1920+ | Concurrent Execution | concurrent.futures, multiprocessing, multiprocessing.shared_memory, queue, sched, subprocess, threading, _thread. |
1921+ | OS Services | argparse, ctypes, curses, curses.ascii, curses.panel, curses.textpad, errno, io, logging, logging.config, logging.handlers , getopt, getpass, platform, time, os. |
1922+ | Cryptographic Services | hashlib, hmac, secrets. |
1923+ | File Formats | configparser, csv, netrc, plistlib, xdrlib. |
1924+ | Data Compression | bz2, gzip, lzma, tarfile, zlib, zipfile. |
1925+ | Data Persistence | copyreg, dbm, marshal, pickle, shelve, sqlite3. |
1926+ | File and Directory Access | filecmp, fileinput, fnmatch, glob, linecache, os.path, pathlib, stat, shutil, tempfile. |
1927+ | Functional Programming | functools, itertools , operator. |
1928+ | Numeric and Mathematics | cmath, decimal, fractions, math, numbers, random, statistics. |
1929+ | Data Types | array, bisect, calendar, collections, collections.abc, copy, datetime, enum, graphlib, heapq, pprint, reprlib, types, weakref, zoneinfo,
1930+ | Runtime Services | array, atexit, calendar, cmath, copy, datetime, gettext, itertools, locale, math, random, sets, struct, sys, traceback. |
1931+ | Text Processing Services | string, re, difflib, textwrap, unicodedata, stringprep, readline, rlcompleter. |
1932+ | Binary Data Services | struct, codecs. |
1933+
1934+
1935+ # ## [base64](https://docs.python.org/3.9/library/base64.html)
1936+
1937+ This module provides binary data encoding and decoding functions in the formats defined by RFC3548 for base16, base32, and base64. It is used in the HTTP protocol for binary data transmission.
1938+
1939+ ```python
1940+ >> > dir (base64)
1941+ [' MAXBINSIZE' , ' MAXLINESIZE' , ' _85encode' , ' _A85END' , ' _A85START' , ' __all__' , ' __builtins__' , ' __cached__' ,
1942+ ' __doc__' , ' __file__' , ' __loader__' , ' __name__' , ' __package__' , ' __spec__' , ' _a85chars' , ' _a85chars2' ,
1943+ ' _b32alphabet' , ' _b32rev' , ' _b32tab2' , ' _b85alphabet' , ' _b85chars' , ' _b85chars2' , ' _b85dec' ,
1944+ ' _bytes_from_decode_data' , ' _input_type_check' , ' _urlsafe_decode_translation' , ' _urlsafe_encode_translation' ,
1945+ ' a85decode' , ' a85encode' , ' b16decode' , ' b16encode' , ' b32decode' , ' b32encode' , ' b64decode' , ' b64encode' , ' b85decode' ,
1946+ ' b85encode' , ' binascii' , ' bytes_types' , ' decode' , ' decodebytes' , ' decodestring' , ' encode' , ' encodebytes' , ' encodestring' ,
1947+ ' main' , ' re' , ' standard_b64decode' , ' standard_b64encode' , ' struct' , ' test' , ' urlsafe_b64decode' , ' urlsafe_b64encode' ]
1948+ ```
1949+
1950+ # ### Base64 encoding and decoding
1951+
1952+ ** b64encode syntax**
1953+
1954+ `b64encode(s, altchars = None )`
1955+
1956+ Encodes a bytes - like object `s` . If `altchars` is specified( not None ), it is a byte string object of length 2 , which defines special characters for the `+ ` and `/ ` characters.
1957+
1958+ ```python
1959+ >> > import base64
1960+ >> > string = " Hi There!"
1961+ >> > bytes_ = string.encode(" UTF-8" )
1962+ >> > b64 = base64.b64encode(bytes_) # takes a bytes object not string !!!
1963+ >> > b64
1964+ b ' SGkgVGhlcmUh'
1965+ >> > type (b64)
1966+ < class ' bytes' >
1967+ >> > type (bytes_)
1968+ < class ' bytes' >
1969+ >> > b64_decode = b64.decode(" UTF-8" ) # converts bytes object to string object. !!!
1970+ >> > b64_decode
1971+ ' SGkgVGhlcmUh'
1972+ >> > type (b64_decode)
1973+ < class ' str' >
1974+ ```
1975+
1976+ ** b64decode syntax**
1977+
1978+ `b64decode(s, altchars = None , validate = False )`
1979+
1980+ Decode the Base64 encoded bytes - like object or ASCII string s. It returns as a bytes object .
1981+
1982+ ```python
1983+ >> > b64_decode = base64.b64decode(b64)
1984+ >> > b64_decode
1985+ b ' Hi There!'
1986+ >> > b64_decode.decode(' utf-8' )
1987+ ' Hi There!'
1988+ ```
1989+
1990+ ** base64 encode decode a file **
1991+
1992+ ```python
1993+ >> > import base64
1994+ >> > for line in open (" file.txt" ):
1995+ ... line_bytes = line.encode(' ascii' )
1996+ ... line_b64_enc = base64.b64encode(line_bytes)
1997+ ... print (line_b64_enc)
1998+ ... line_decode = base64.b64decode(line_b64_enc)
1999+ ... line_dec = line_decode.decode(' ascii' )
2000+ ... print (line_dec)
2001+ ... with open (" file1.b64" , " ab+" ) as f: # append each line in binairy.
2002+ ... f.write(line_b64_enc)
2003+ ...
2004+ b ' bGluZV8wMQkJPC0tLS0tLQo='
2005+ line_01 < ------
2006+
2007+ 24
2008+ b ' bGluZV8wMiAJPC0tLS0tLQo='
2009+ line_02 < ------
2010+
2011+ 24
2012+ b ' bGluZV8wMwkJPC0tLS0tLQo='
2013+ line_03 < ------
2014+
2015+ 24
2016+ b ' bGluZV8wNCAJPC0tLS0tLQo='
2017+ line_04 < ------
2018+
2019+ 24
2020+ b ' bGluZV8wNSAJPC0tLS0tLQo='
2021+ line_05 < ------
2022+
2023+ 24
2024+ b ' bGluZV8wNiAJPC0tLS0tLQo='
2025+ line_06 < ------
2026+
2027+ 24
2028+ b ' bGluZV8wNyAJPC0tLS0tLQ=='
2029+ line_07 < ------
2030+ 24
2031+
2032+ # content of file1.b64
2033+ bGluZV8wNyAJPC0tLS0tLQ== bGluZV8wMQkJPC0tLS0tLQo = bGluZV8wMiAJPC0tLS0tLQo = bGluZV8wMwkJPC0tLS0tLQo = bGluZV8wNCAJPC0tLS0tLQo = bGluZV8wNSAJPC0tLS0tLQo = bGluZV8wNiAJPC0tLS0tLQo = bGluZV8wNyAJPC0tLS0tLQ==
2034+ ```
2035+
2036+ # ### Base32 encoding and decoding
2037+
2038+ ```python
2039+ >> > import base64
2040+ >> > string = " Hi There!"
2041+ >> > bytes_ = string.encode(" ascii" )
2042+ >> > b32 = base64.b32encode(bytes_)
2043+ >> > b32
2044+ b ' JBUSAVDIMVZGKII='
2045+ >> > b32_decode = base64.b32decode(b32)
2046+ >> > b32_decode
2047+ b ' Hi There!'
2048+ >> > b32_decode.decode(' ascii' )
2049+ ' Hi There!'
2050+
2051+ ```
2052+
2053+ # ### hexadecimal(Base16) encoding and decoding
2054+
2055+ ```python
2056+ >> > import base64
2057+ >> > string = " Hi There!"
2058+ >> > bytes_ = string.encode(" ascii" )
2059+ >> > b16 = base64.b16encode(bytes_)
2060+ >> > b16
2061+ b ' 486920546865726521'
2062+ >> > b16_decode = base64.b16decode(b16)
2063+ >> > b16_decode
2064+ b ' Hi There!'
2065+ >> > b16_decode.decode(' ascii' )
2066+ ' Hi There!'
2067+ ```
2068+
2069+ # ## [binhex](https://docs.python.org/3.9/library/binhex.html)
2070+
2071+ This module provides binary data encoding and decoding functions in binhex4 format .
2072+
2073+ ** binhex.binhex syntax**
2074+
2075+ `binhex(infilename, outfilename)`
2076+
2077+ ```python
2078+ >> > import binhex
2079+ >> > binhex.binhex(' file.txt' , ' file1.hqx' )
2080+ >> > for line in open (' file1.hqx' , ' r' ):
2081+ ... print (line)
2082+ ...
2083+ (This file must be converted with BinHex 4.0 )
2084+
2085+
2086+
2087+ :# 'CTE'8ZG(Kd!&4&@&3rN!3!N!9f!*!%ET*XD@jPAc!a#3Nm,C!'#QaTEQ9I-$)
2088+
2089+ J# 6`YN!B+E'PZC9m`-`N*2#f3"JTXD@jPAc!d)!Nm,C!'#QaTEQ9I-$8J#6`YN!B
2090+
2091+ + E' PZC9m`0L!*2#f3"JTXD@jPAc!h)!Nm,C!' 2Jd !!!:
2092+ ```
2093+
2094+ ** binhex.hexbin syntax**
2095+
2096+ `hexbin(infilename, outfilename)`
2097+
2098+ ```python
2099+ >> > binhex.hexbin(' file1.hqx' , ' file1.txt' )
2100+ >> > for line in open (' file1.txt' , ' r' ):
2101+ ... print (line)
2102+ ...
2103+ line_01 < ------
2104+
2105+ line_02 < ------
2106+
2107+ line_03 < ------
2108+
2109+ line_04 < ------
2110+
2111+ line_05 < ------
2112+
2113+ line_06 < ------
2114+
2115+ line_07 < ------
2116+ ```
2117+
2118+ # ## [binascii](https://docs.python.org/3.9/library/binascii.html?highlight=binascii)
18922119
0 commit comments