Python Language
Total Page:16
File Type:pdf, Size:1020Kb
Python Language #python 1 1: Python 2 2 2 Python 3.x 2 Python 2.x 3 Examples 3 3 Python 3 IDLEPython 4 Hello World Python 4 Python shell 5 6 6 6 6 10 IDLE - Python GUI 11 11 12 12 12 12 13 13 14 14 14 15 15 16 19 20 20 24 25 - strrepr 26 26 STR 26 pip 27 / 27 27 27 Python 2.7.x3.x. 28 2: * args** kwargs 31 31 h11 31 h12 31 h13 31 Examples 32 * args 32 ** kwargs 32 * args 32 ** kwargs 33 * args 33 34 kwarg 34 ** kwargs 34 3: __name__ 36 36 36 Examples 36 __name__ =='__ main__' 36 1 36 2 36 function_class_or_module .__ name__ 36 37 4: 2to3 39 39 39 39 Examples 39 39 Unix 40 40 Unix 40 40 5: ArcPy 41 41 Examples 41 “” 41 createDissolvedGDBgdb 41 6: Asyncio 42 Examples 42 42 43 UVLoop 44 44 44 44 Websocket 45 asyncio 45 7: base64 47 47 47 47 48 Examples 48 Base64 48 Base32 49 Base16 50 ASCII85 50 Base85 51 8: ChemPy - python 52 52 Examples 52 52 52 52 52 53 53 9: configparser 55 55 55 55 Examples 55 55 55 10: ctypes 57 57 Examples 57 57 57 57 58 ctypes 58 ctypes 58 ctypes 59 59 11: Deque 61 61 61 61 Examples 61 61 deque 61 deque 61 62 12: dis 64 Examples 64 dis 64 Python 64 64 13: Django 66 66 Examples 66 DjangoHello World 66 14: Functools 68 Examples 68 68 total_ordering 68 68 lru_cache 69 cmp_to_key 69 15: hashlib 70 70 Examples 70 MD5 70 OpenSSL 70 16: Heapq 72 Examples 72 72 72 17: HTML 74 Examples 74 BeautifulSoup 74 BeautifulSoupCSS 74 PyQuery 75 18: ijson 76 76 Examples 76 76 19: IterablesIterators 77 Examples 77 Iterator vs Iterable vs Generator 77 78 78 iterable 78 79 79 20: Itertools 80 80 Examples 80 80 80 itertools.product 81 itertools.count 82 itertools.takewhile 82 itertools.dropwhile 83 84 Itertools 84 84 itertools.repeat 85 85 85 itertools.permutations 85 21: JSON 87 87 87 87 87 87 87 87 87 88 Examples 88 Python dictJSON 88 JSONPython dict 88 89 89 `load` vs`load``dump` vs`stacks` 89 `json.tool`JSON 90 JSON 90 90 91 91 JSON 91 22: kivy - NUIPython 93 93 Examples 93 93 23: Neo4jCypherPy2Neo 95 Examples 95 95 Neo4j 95 Neo4j 95 1 95 2 96 Cypher 96 24: os.path 97 97 97 Examples 97 97 97 97 98 98 98 25: os 99 99 99 99 Examples 99 99 99 99 99 POSIX 99 100 makedirs - 100 26: Pandas Transform 102 Examples 102 102 102 pandas transform 102 103 transform 103 27: Pickle 104 104 104 104 Pickleable 104 pickle 104 Examples 104 Pickle 104 104 105 picklebyte 105 105 28: pipPyPI 107 107 107 107 Examples 107 107 107 108 `pip` 108 108 Linux 108 Windows 108 requirements.txt 109 virtualenvrequirements.txt 109 Pythonpip 109 110 110 110 29: PostgreSQL 112 Examples 112 112 pip 112 112 30: py.test 113 Examples 113 py.test 113 113 113 113 113 114 py.test 115 116 31: pyaudio 117 117 117 Examples 117 I / O. 117 I / O. 118 32: pyautogui 120 120 Examples 120 120 120 ScreenShot 120 33: pygame 121 121 121 121 Examples 121 pygame 121 Pygame 121 121 122 122 34: Pyglet 123 123 Examples 123 PygletHello World 123 Pyglet 123 Pyglet 123 PygletOpenGL 123 PygletOpenGL 124 35: PyInstaller - Python 125 125 125 Examples 125 125 Pyinstaller 125 126 126 126 126 36: Python HTTP Server 127 Examples 127 HTTP 127 127 SimpleHTTPServerAPI 129 BaseHTTPRequestHandlerGETPOSTPUT 130 37: Python Lex-Yacc 132 132 132 Examples 132 PLY 132 “HelloWorld” PLY - 132 1Lex 134 135 h21 135 h22 135 h23 136 h24 136 h25 136 h26 136 h27 136 h28 137 h29 137 h210 137 2Yacc 137 138 h211 139 38: Python 140 140 Examples 140 140 140 141 39: PythonMutable vs ImmutableHashable 143 Examples 143 143 Immutables 143 143 Mutables 144 144 145 145 40: Python 146 146 Examples 146 Lambda 146 146 146 146 41: PythonShell 147 147 Examples 147 ssh 147 42: python 148 Examples 148 148 148 43: Pythonpyserial 149 149 149 149 Examples 149 149 149 149 44: Python 151 Examples 151 151 151 152 45: PythonExcel 153 Examples 153 Excel 153 OpenPyXL 153 xlsxwriterexcel 154 xlrdexcel 156 xlsxwriterExcel 157 46: Python 159 159 159 Examples 159 Python 159 160 47: Python 161 161 Examples 161 161 161 161 161 161 161 48: Python 163 163 Examples 163 SSE 163 Asyncio SSE 163 49: PythonCurses 164 164 Examples 164 164 wrapper 164 50: Python 166 Examples 166 166 166 Deque 167 167 ...... 168 51: Python 169 169 Examples 169 Python - 169 Http 169 TCP 170 UDP 170 Simple HttpServer 171 52: Python - virtualenv 172 172 Examples 172 172 172 Virtualenv 172 virtualenv 172 53: Python 174 174 Examples 174 174 175 175 175 176 177 54: setup.py 178 178 178 Examples 178 setup.py 178 python 178 setup.py 179 179 55: Sqlite3 181 Examples 181 Sqlite3 - 181 181 56: SYS 183 183 183 183 Examples 183 183 183 183 183 57: tempfile NamedTemporaryFile 185 185 Examples 185 185 58: Tkinter 186 186 186 Examples 186 tkinter 186 187 187 187 187 59: Unicode 189 189 189 Examples 189 189 Unicode 189 unicode 190 / 190 190 191 191 I / O. 191 60: WebWSGI 192 192 Examples 192 192 61: Web 193 193 193 193 193 Examples 194 URL 194 URL 195 62: “with”Statement 196 196 196 196 Examples 196 with 196 197 197 198 198 199 63: Python 2Python 3 200 200 200 Examples 200 200 Unicode 201 203 Reduce 205 xrange 205 206 Iterables 207 208 .next 210 211 211 212 execPython 3 212 Python 2hasattr 213 213 214 214 Python 3“” 214 <>``=repr 215 / 215 Python 3cmp 216 217 217 filtermapzip 218 / 219 220 I / O. 220 round 221 221 round 221 222 222 223 223 64: intfloatstrtuplefrozensets 225 Examples 225 225 225 Frozenset 225 65: 226 226 Examples 226 226 ParentChildren 226 C 227 PyPar 227 66: 228 228 Examples 228 228 228 228 67: 230 230 Examples 230 230 68: “pip”PyPI 231 231 231 Examples 231 231 ImportError 232 232 69: AMQPStormRabbitMQ 233 233 Examples 233 RabbitMQ 233 RabbitMQ 234 RabbitMQ 234 70: Pandas 237 237 Examples 237 Pandas 237 71: PythonWindows 239 239 Examples 239 Python 239 Flask Web 239 72: PythonRaspberry PI 241 Examples 241 - 241 73: PythonWeb 244 244 244 WebPython 244 244 requests 244 requests-cache 244 scrapy 244 selenium 244 HTML 244 BeautifulSoup 244 lxml 244 Examples 244 lxml 244 Web 245 Scrapy 245 Scrapy 246 BeautifulSoup4 246 Selenium WebDriver 246 urllib.requestWeb 247 247 74: Python 248 Examples 248 Matplotlib 248 Seaborn 249 Mayavi 252 Plotly 253 75: ZIP 255 255 255 Examples 255 Zip 255 Zipfile 255 zip 256 256 76: 257 Examples 257 257 77: 258 258 258 Examples 258 258 258 259 259 259 260 262 262 263 263 263 263 264 264 78: 266 266 266 266 Examples 266 266 266 267 267 268 269 269 269 269 269 269 270 270 79: 271 271 271 Examples 271 271 272 272 272 Python 23six 272 273 273 273 273 274 274 80: 276 276 Examples 276 PyTesseract 276 PyOCR 276 81: CLI 278 278 278 Examples 278 278 argparse 278 argparse 279 82: 281 281 Examples 281 math.sqrtcmath.sqrt 281 **pow 281 math.pow 282 math.expcmath.exp 282 1math.expm1 283 cmath 283 3pow 285 nth-root 285 286 83: 287 Examples 287 py2app 287 cx_Freeze 288 84: 289 289 289 Examples 289 “” 289 289 289 290 85: 291 291 291 291 Examples 291 291 292 292 292 293 293 294 296 296 297 298 298 299 86: 300 300 300 300 Examples 300 300 301 302 - 303 303 304 87: 305 Examples 305 305 305 305 305 305 306 306 306 307 88: 309 Examples 309 IPython%% timeittimeit 309 timeit 309 timeit 309 line_profiler 309 cProfileProfiler 310 89: Python 311 311 Examples 311 311 PyPI 311 .pypirc 311 testpypi 312 312 PyPI 313 313 313 313 313 90: 315 315 315 315 315 316 Examples 316 316 317 318 318 318 318 319 319 319 320 320 320 320 321 321 321 Lambda/ 321 323 324 325 325 326 326 328 Lambda 328 328 91: 330 Examples 330 330 330 Python 330 PYTHONSTARTUP 331 331 332 92: 334 334 Examples 334 334 335 335 336 336 del 337 del v 337 del v.name 337 del v[item] 337 del v[a:b] 337 338 338 338 339 global vs nonlocal Python 3 339 93: 341 341 341 341 Examples 341 341 342 347 347 348 348 348 348 349 350 350 351 352 94: 353 353 Examples 353 353 unittest.mock.create_autospec 353 test.TestCase 354 355 Unittests 356 pytest 357 95: GIL 360 360 GIL 360 GIL 360 GIL 360 GIL 360 360 Examples 361 Multiprocessing.Pool 361 David BeazleyGIL 361 Cython nogil 362 David BeazleyGIL 362 nogilCYTHON 362 96: 363 363 Examples 363 PyDotPlus 363 363 PyGraphviz 363 97: windowsvirtualenvwrapper 365 Examples 365 windowsvirtualenvwrapper 365 98: 366 366 Examples 366 366 99: 367 367 367 367 Examples 367 mapitertools.imapfuture_builtins.map 367 368 368 Map“None”python 2.x 370 370 100: 373 373 373 Examples 373 373 374 del 375 375 376 376 376 377 101: 378 Examples 378 inputraw_input 378 378 378 379 stdin 380 380 102: 382 382 382 382 Examples 382 ListStack 382 383 103: 384 Examples 384 384 384 104: 386 Examples 386 386 388 105: 389 Examples 389 389 ..