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: PythonMutable vs ImmutableHashable 140 Examples 140 140 Immutables 140 140 Mutables 141 141 142 142 39: Python 143 143 Examples 143 Lambda 143 143 143 143 40: PythonShell 144 144 Examples 144 ssh 144 41: python 145 Examples 145 145 145 42: Pythonpyserial 146 146 146 146 Examples 146 146 146 146 43: Python 148 Examples 148 148 148 149 44: PythonExcel 150 Examples 150 Excel 150 OpenPyXL 150 xlsxwriterexcel 151 xlrdexcel 153 xlsxwriterExcel 154 45: Python 156 156 Examples 156 156 156 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 226 226 66: CPython 228 228 228 Examples 229 CPython 229 CPython 229 67: 231 231 Examples 231 if / else 231 231 232 232 68: CSV 234 234 234 234 Examples 234 234 CSV 235 69: 236 236 Examples 236 236 70: “pip”PyPI 237 237 237 Examples 237 237 ImportError 238 238 71: AMQPStormRabbitMQ 239 239 Examples 239 RabbitMQ 239 RabbitMQ 240 RabbitMQ 240 72: Pandas 243 243 Examples 243 Pandas 243 73: PythonWindows 245 245 Examples 245 Python 245 Flask Web 245 74: PythonRaspberry PI 247 Examples 247 - 247 75: PythonWeb 250 250 250 WebPython 250 250 requests 250 requests-cache 250 scrapy 250 selenium 250 HTML 250 BeautifulSoup 250 lxml 250 Examples 250 lxml 250 Web 251 Scrapy 251 Scrapy 252 BeautifulSoup4 252 Selenium WebDriver 252 urllib.requestWeb 253 253 76: Python 254 Examples 254 Matplotlib 254 Seaborn 255 Mayavi 258 Plotly 259 77: ZIP 261 261 261 Examples 261 Zip 261 Zipfile 261 zip 262 262 78: 263 Examples 263 263 79: 264 264 264 Examples 264 264 264 265 265 265 266 268 268 269 269 269 269 270 270 80: 272 272 272 Examples 272 272 273 273 273 Python 23six 273 274 274 274 274 275 275 81: 277 277 277 277 Examples 277 277 277 278 278 279 280 280 280 280 280 280 281 281 82: 282 282 Examples 282 PyTesseract 282 PyOCR 282 83: CLI 284 284 284 Examples 284 284 argparse 284 argparse 285 84: 287 Examples 287 CHello World 287 C Extensions 287 Cc ++Boost 288 C ++ 288 85: 290 Examples 290 py2app 290 cx_Freeze 291 86: 292 292 292 Examples 292 “” 292 292 292 293 87: 294 294 294 294 Examples 294 294 295 295 295 296 296 297 299 299 300 301 301 302 88: 303 303 303 303 Examples 303 303 304 305 - 306 306 307 89: 308 Examples 308 308 308 308 308 308 309 309 309 310 90: Python 312 312 Examples 312 312 PyPI 312 .pypirc 312 testpypi 313 313 PyPI 314 314 314 314 314 91: 316 Examples 316 IPython%% timeittimeit 316 timeit 316 timeit 316 line_profiler 316 cProfileProfiler 317 92: 318 318 318 318 318 319 Examples 319 319 320 321 321 321 321 322 322 322 323 323 323 323 324 324 324 Lambda/ 324 326 327 328 328 329 329 331 Lambda 331 331 93: 333 333 Examples 333 333 unittest.mock.create_autospec 333 test.TestCase 334 335 Unittests 336 pytest 337 94: 340 340 340 Examples 340 340 next 340 340 341 341 343 343 - 344 344 345 345 346 346 346 95: 348 Examples 348 348 348 Python 348 PYTHONSTARTUP 349 349 350 96: 352 352 Examples 352 352 353 353 354 354 del 355 del v 355 del v.name 355 del v[item] 355 del v[a:b] 355 356 356 356 357 global vs nonlocal Python 3 357 97: 359 359 359 359 Examples 359 359 360 365 365 366 366 366 366 367 368 368 369 370 98: GIL 371 371 GIL 371 GIL 371 GIL 371 GIL 371 371 Examples 372 Multiprocessing.Pool 372 David BeazleyGIL 372 Cython nogil 373 David BeazleyGIL 373 nogilCYTHON 373 99: 374 374 Examples 374 PyDotPlus 374 374 PyGraphviz 374 100: windowsvirtualenvwrapper 376 Examples 376 windowsvirtualenvwrapper 376 101: 377 377 Examples 377 377 102: 378 378 378 378 Examples 378 mapitertools.imapfuture_builtins.map 378 379 379 Map“None”python 2.x 381 381 103: 384 384 384 Examples 384 384 385 del 386 386 387 387 387 388 104: 389 Examples 389 inputraw_input 389 389 389 390 stdin 391 391 105: 393 393 393 393 Examples 393 ListStack 393 394 106: 395 Examples 395 395 395 395 395 395 107: 397 397 Examples 397 397 397 108: 399 Examples 399 399 399 109: 401 Examples 401 401 403 110: 404 404 Examples 404 404 405 405 406 406 while 408 111: 409 Examples 409 409 ..