Knowledge Base scripting article, 355 coding environment in, 84 .zip file, 309 shortened version of Jupyter Notebook, 65 Microsoft Disk Operating System (MS-DOS) (platform), 22 trusting your, 89 MIME (Multipurpose Internet Mail Extensions), 332 Notebook Help (interface-specific help entry), 95 MIMEApplication, 332 notebooks, 57, 67–71 MIMEAudio, 332 Nuke, 356 MIMEImage, 332 # formatting specification, 240 MIMEMultipart, 332 numbers, defining character by using numbers, MIMEText, 332 Miniconda installer, 58 226–227 min(str) function, 234 numeric bases, 106 -m mod option, 40 numeric data types, 106, 108 Modo, 356 NumPy, 16, 18 Module Index, 220 modules, a.k.a. packages, 197 O modules basic help topic, 47 MorphOS (platform), 22 -O option, 41 MotionBuilder, 356 object, defined, 283 Move Selected Cells Down icon, 91 object-oriented coding style, 45 Move Selected Cells Up icon, 91 Object-Oriented Programming (OOP), 289 MS-DOS (Microsoft Disk Operating System) (platform), 22 objects, data stored as, 306 Mueller, John occupations that use Python regularly, 353–360 blog, 352 oct() command, 106 email address, 23 -OO option, 41 multiline comment, 78 Open the Command Palette icon, 91 multiple tasks, performing of, 138–139 Operating System 2 (OS/2) (platform), 22 Multipurpose Internet Mail Extensions (MIME), 332 Operating System 390 (OS/390) and z/OS (platform), 22 MyClass class, 296–299 operator overloading, 283 myVar variable, 105 operators. See also specific operators N categories of, 116 defining of, 116 __name__ attribute, 216 as helping applications control data, 114 nested decision statements, 146–149 overloading of, 294–296 nesting, 185 as Python’s main method for making comparisons, nesting loop statements, 162–164 network 114–115 understanding operator precedence, 122–123 accessing local network resources by using Twisted use of with lists, 253 Matrix, 378 working with, 115–123 orphaned product, 365 administering of as occupation that uses Python OS exceptions (exception category), 172 regularly, 356 OS X version 10.5, 27 OS X version 10.12, 27 “Network Management,” 356 os._exit() command, 52, 53 NEWS.txt file, 38 OS/2 (Operating System 2) (platform), 22 non-conda packages, 201 OS/390 (Operating System 390) and z/OS (platform), 22 None (Cell Toolbar menu option), 93 os.rmdir() function, 322 Not Trusted button, 89 other (special character category), 229 Notebook. See also Jupyter Notebook outputs, toggling of, 90 Index 387
P port (email address), 326, 328–330 positional arguments, 129 package cache, 201 Practical Extraction and Report Language (PERL), 19 package content, 216–218 .precision formatting specification, 240 Package Docs (Python Package Documentation), 219 PrettyTable, 374 package documentation, 219–223 prewritten code, 64 __package__ attribute, 216 print() command, 35, 43, 44, 48 packages print() function, 248 print() function argument, 129 built-in packages, 200 procedural coding style, 45 conda packages, 200, 210–215 procedure, 9–10, 11 considering package cache, 201 production server, never test on, 364 custom packages, 200 production-grade class, 299 defined, 197 A Programmer’s Guide to Data Mining, 358 downloading of from other sources, 209–216 programming language finding of on disk, 207–209 importing, 202–207 C#, 15, 16, 18 installing packages by using pip, 215–216 C/C++, 14, 15, 18, 198, 353 interacting with, 197–223 comparing Python to other languages, 18–20 a.k.a. modules, 197 creation of, 14 non-conda packages, 201 defined, 12 understanding package types, 200–201 Java, 14, 15, 18, 19, 377 viewing package content, 216–218 Perl, 19 viewing package documentation, 219–223 R, 19–20 packaging methods, as helping applications control why you need to know multiple programming data, 114 languages, 354 Paint Shop Pro, 356 programming resources, 343–352 PalmOS (platform), 22 programming skills, teaching of as occupation that uses parent class, 299 pass clause, 157–158 Python regularly, 357 Paste Cells Below editing command, 88 Psion (platform), 22 Paste Cells Below icon, 91 PyAudio, 374–375 Paste Cells editing command, 88 PyCrypto, 372 path, defined, 307 pydbgr, 367–368 path information, 207–209 Pydoc (Python Package Documentation) application, PDF via LaTeX (.pdf) download option, 84 pdoc, 365–366 219–220 PERL (Practical Extraction and Report Language), 19 PyGame, 375 Perl (programming language), 19 PyInstaller, 364–365 permanent storage, 306–311 PyPI (Python Package Index), 210 pip (Pip Installs Packages) utilities, 209, 215–216 .py files, 218 platforms PyQtGraph, 375–376 Python defined, 21 supported by Anaconda, 58 accessing of on your machine, 31–35 supported by Python, 22 case sensitivity of, 40, 170 PlayStation (platform), 22 coding styles of, 45 pop() function, 250 common uses of, 15–16 comparing of to other languages, 18–20 current version of, 23 388 Beginning Programming with Python For Dummies
deciding how you can personally benefit from, 15–16 PYTHONNOUSERSITE environment variable, 42 discovering which organizations use, 16–17 PYTHONOPTIMIZE=x environment variable, 42 documentation online, 344–345 PYTHONPATH=arg environment variable, 42 downloading the version you need, 21–24 PythonSpeed Performance Tips, 352 enhancing your experience with, 361–369 PYTHONSTARTUP=arg environment variable, 42 as fifth-ranked language on TIOBE, 1, 15 PYTHONUNBUFFERED=x environment variable, 42 finding useful applications written in, 17–18 PYTHONVERBOSE=x environment variable, 42 as first-ranked language on IEEE Spectrum, 15 python.vim utility, 349 getting your own copy of, 21–36 Pythonware site, 346 installation of, 24–31 PYTHONWARNINGS=arg environment variable, 42 interacting with, 37–53 PyUnit, 368–369 knowing why it doesn’t understand you, 166–167 as learning tool, 15, 353 Q main objective of creating it, 14 making your Python application fast, 352 q command, 220 performing web programming by using, 346 -q option, 41 programming resources, 343–352 QNX (platform), 22 reasons for using, 14–15 Quality Assurance (QA) departments, as occupation that starting, 38–39 as third-ranked language on Tech Rapidly, 15 uses Python regularly, 354 use of by colleges to teach coding, 15 queues, 244, 263, 275–277 ways to making a living with, 353–360 quick-access links, 220 why it’s so cool, 14–20 quit() command, 36 Python (.py) download option, 84 quit() command, 51, 52 Python 2.7.10, 27 Python 3.3.4, 21 R Python and GIS Resources, 357 Python: Common Newbie Mistakes, Part 1, 351 R (programming language), 19–20 Python: Common Newbie Mistakes, Part 2, 351 raising exceptions, 166, 188–191 Python DevelopmentTools, 362 range checking, 139–141 Python Encodings and Unicode, 352 range() function, 152 Python Package Documentation (Package Docs or Raspberry Pi, 357, 358 Raw Cell Format (Cell Toolbar menu option), 93 Pydoc), 219 raw NBConvert cell type, 87 Python Package Index (PyPI), 210 README file, 38 Python SayHello.py, 40 receiver (email), 331 PYTHONCASEOK=x environment variable, 42 Reconnect (kernel-specific command), 95 PYTHONDEBUG=x environment variable, 42 records, defined, 372 PYTHONDONTWRITEBYTECODE=x environment variable, 42 Red Hat, 28 PythonEditors wiki, 348 Red Hat Package Manager (RPM)-based distribution, 28 PYTHONFAULTHANDLER=x environment variable, 42 Relational DataBase Management System (RDBMS), 373 Python-h, 39 relational equality operator (==), 136 PYTHONHASHSEED=arg environment variable, 42 relational operators, 116, 118–119, 136, 137–138 PYTHONHOME=arg environment variable, 42 relative path, 307 PYTHONINSPECT=x environment variable, 42 relative path character sets, 307 PYTHONIOENCODING=arg environment variable, 42 remove() function, 250 repetitive tasks, performing of, 151–164 Index 389
replace(old, new [, max]) function, 237 setup process, on Windows, 25 repository, 65 “7 Python Libraries you should know about,” 371 reST (.rst) download option, 84 show (pip command), 216 Restart (kernel-specific command), 95 Shutdown (kernel-specific command), 95 Restart & Clear Output (kernel-specific command), 95 shutil.rmtree() function, 322 Restart & Run All (kernel-specific command), 95 sign formatting specification, 239 Restart the Kernel icon, 91 significand, 108 return keyword, 131 Simple Mail Transfer Protocol (SMTP), 323, 324–325, return values, 131–132 rfind(str, beg=0, end=len(string)) function, 237 336–337 rindex(str, beg=0, end=len(string)) function, 237 single quotes, use of, 227 RISC OS (originally Acorn) (platform), 22 single-line comment, 78 rjust(width, fillchar=\" \") function, 234 Siri (Apple), 7 Roundup Issue Tracker, 362–363 Slideshow (Cell Toolbar menu option), 93 rstrip() function, 234 socket, 327 Run Cell icon, 91 socket.gethostbyaddr() method, 330 runnable code, 198–199 Softimage, 356 Running tab (main Notebook page), 99, 100 Solaris (platform), 22 runtime error, 168–169 Solid State Drive (SSD), 305 sound, 374–375 S spaghetti code, 281 special characters, 229–231 -S option, 41 splitlines(num=string.count(’\\n’)) function, 235 -s option, 41 split(str=\" ,\" num=string.count(str)) function, safe access, ensuring of, 89 Save and Checkpoint icon, 90 234, 236 SaveData() method, 312 splitting a cell, 88 SayGoodbye() function, 199 SQL (Structured Query Language), 16, 353, 373 SayHello() function, 199 SQLAlchemy, 372–373 scientific tasks, carrying out of as occupation that uses square brackets ([]), 231 SSD (Solid State Drive), 305 Python regularly, 359 stacks, 244, 262, 273–275 SciPy, 16, 18 startswith(prefix, beg=0, end=len(string)) screenshots, 31, 58 Scribus, 356 function, 237 scripting, 355–356 storage search (pip command), 216 search libraries, 376 creating content for permanent storage, 308–311 Secure Digital (SD) card, 104 creating file, 311–314 secure environment, developing of by using of data in files, 305–322 deleting file, 321–322 PyCrypto, 372 reading file content, 314–317 selection tree, 146 understanding how permanent storage works, 306–307 semantic error, 170–171 updating file content, 317–321 sender (email), 331 storage boxes, 104 sequences, 244, 262 __str__() method, 297 Series 60 (platform), 22 strings creating of with special characters, 229–231 defining character by using numbers, 226–227 formatting, 238–241 390 Beginning Programming with Python For Dummies
locating a value in, 236–238 availability of, 56 selecting individual characters, 231–233 categories of, 361–362 slicing and dicing of, 233–236 defined, 361 understanding of, 110–111 topics basic help topic, 47 understanding that strings are different, 226–228 Topics link, 220 use of term, 227 transmission method (email), 334–335 using characters to create, 227–228 Trigger, 356 working with, 225–241 triple double quotes, 227 strip() function, 235 True, 110 structured data, 308 tuples, 244, 262, 263–266 Structured Query Language (SQL), 16, 353, 373 tutorials, 345, 349, 350, 352 str.upper() function, 186 Tutorials on XML Processing with Python, 350 SUSE, 28 Twisted Matrix, 378 swapcase() function, 235 type formatting specification, 240 switch statement, 146, 266, 270–272 type() method, 110 symbols basic help topic, 47, 48 typographical (special character category), 229 syntactical error, 170 syntax, checking of with greater ease, 348–349 U sys.exit() command, 52, 53 sys.path attribute, 208, 209 -u option, 41 Ubuntu 12.x, 30 T unary operators, 116, 117–118 Undo Delete Cells editing command, 88 tabular data, display of, 374 Unicode, 351–352 Tags (Cell Toolbar menu option), 94 Unicode Pain, 352 Tech Rapidly, 15 Unicode Tutorials and Overviews, 352 terminals, 99–100 uninstall (pip command), 216 ternary operators, 117 Universal Serial Bus (USB) flash drive, 104, 305 text editor, notebook compared to, 57 Unofficial Windows Binaries for Python Extension text message, 335–336 third-party support, 361–369 Packages, 371 3ds Max, 355 unstructured data, 308 throw an exception, 166 The Updated Guide to Unicode on Python, 351 time() command, 112 updates times, working with, 111–112 TIOBE, 15 of file content, 317–321 title() function, 235 of Python, 4, 23 TkInter, 373–374 upper() function, 235 Toggle Header option, 90 Useful Modules, 371 Toggle Line Numbers option, 91 user documentation, 365 Toggle option, 90 user input, 114, 132–133 Toggle Scrolling option, 90 Toggle Toolbar option, 90 V Tool Command Language (Tcl)/Toolkit (Tk), 374 tools -V option, 41 -v option, 41 ValueError exception, 173, 186, 190, 191, 192 Index 391
variable arguments, 293 Windows, 25–27, 32–34, 42, 61–64 variables Windows 32-bit (XP and later) (platform), 22 Windows 64-bit (platform), 22 class variable, 282–283, 290–292 Windows CE/Pocket PC (platform), 22 as code grouping, 198 winsound, 375 determining variable’s type, 110 W3Schools, 349, 350 environment variables, 41–43, 207 instance variable, 283, 290, 292–293 X putting information into, 105 seeing of as storage boxes, 104 XeTeX, 84 working with, 290–293 XML (eXtensible Markup Language), 16, 308, 349–350 -version option, 41 -X opt option, 41 virtual environment, creating, 363 -x option, 41 Virtual Memory System (VMS), 22 VirtualEnv, 363 Y Visual Basic, 15 Visual Studio, 355 Yellow Dog, 28 YouTube, on using Python to build embedded W system, 358 -W arg option, 41 warnings (exception category), 172 Z Web Programming in Python, 346 while loop, 162 0 formatting specification, 240 while statement, 159–162 ZeroDivisionError exception, 183 width formatting specification, 240 zfill (width) function, 235 392 Beginning Programming with Python For Dummies
About the Authors John Mueller is a freelance author and technical editor. He has writing in his blood, having produced 104 books and more than 600 articles to date. The topics range from networking to artificial intelligence and from database management to heads- down programming. Some of his current books include discussions of data science, machine learning, and algorithms — all of which use Python as a demonstration language. His technical editing skills have helped more than 70 authors refine the content of their manuscripts. John has provided technical editing services to various magazines, performed various kinds of consulting, and he writes certification exams. Be sure to read his blog at http://blog.j ohnmuellerbooks.com/. You can reach him by email at John@JohnMuellerBooks.com. He also has a website at http://www.johnmuellerbooks.com/.
Dedication This book is dedicated to the readers who take time to write me each day. Every morning I’m greeted by various emails — some with requests, a few with com- plaints, and then there are the very few that just say thank you. All these emails encourage and challenge me as an author — to better both my books and myself. Thank you!
Acknowledgments Thanks to my wife, Rebecca. Even though she is gone now, her spirit is in every book I write, in every word that appears on the page. She believed in me when no one else would. Russ Mullen deserves thanks for his technical edit of this book. He greatly added to the accuracy and depth of the material you see here. Russ is always providing me with great URLs for new products and ideas. However, it’s the testing that Russ does that helps most. He’s the sanity check for my work. Russ also has dif- ferent computer equipment from mine, so he’s able to point out flaws that I might not otherwise notice. Matt Wagner, my agent, deserves credit for helping me get the contract in the first place and taking care of all the details that most authors don’t really consider. I always appreciate his assistance. It’s good to know that someone wants to help. A number of people read all or part of this book to help me refine the approach, test the coding examples, and generally provide input that all readers wish they could have. These unpaid volunteers helped in ways too numerous to mention here. I especially appreciate the efforts of Eva Beattie, Glenn A. Russell, Col Onyebuche, Emanuel Jonas, Michael Sasseen, Osvaldo Téllez Almirall, and Thomas Zinckgraf, who provided general input, read the entire book, and selflessly devoted them- selves to this project. Finally, I would like to thank Katie Mohr, Susan Christophersen, and the rest of the editorial and production staff.
Publisher’s Acknowledgments Sr. Editorial Assistant: Cherie Case Production Editor: Antony Sami Senior Acquisitions Editor: Katie Mohr Cover Image: © Esin Deniz/Shutterstock Project Manager and Copy Editor: Susan Christophersen Technical Editor: Russ Mullen
WILEY END USER LICENSE AGREEMENT Go to www.wiley.com/go/eula to access Wiley’s ebook EULA.
Search
Read the Text Version
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
- 361
- 362
- 363
- 364
- 365
- 366
- 367
- 368
- 369
- 370
- 371
- 372
- 373
- 374
- 375
- 376
- 377
- 378
- 379
- 380
- 381
- 382
- 383
- 384
- 385
- 386
- 387
- 388
- 389
- 390
- 391
- 392
- 393
- 394
- 395
- 396
- 397
- 398
- 399
- 400
- 401
- 402
- 403
- 404
- 405
- 406
- 407
- 408
- 409
- 410
- 411