Introduction to Python Version 1.1.5 (12/29/2008) [CG] Page 1 of 243
Introduction...6 About Python...7 The Python Interpreter...9 Exercises...11 Python Compilation...12 Python Scripts in Linux/Unix & Windows...14 Exercises...16 Whitespace Significance...17 Line Termination...19 Comments in Python...20 Basic Output Generation...21 Simple User Input...23 Exercises...24 Python Modules...25 Module Search Paths...28 Determining the System Search Path...29 Exercises...30 Working with Variables...31 Python Variables...32 Naming Conventions & Rules...37 Types as Objects...38 Variable References & Garbage Collection...40 Sequence Types...42 Table of Contents Membership Statements...44 List Iteration...45 List Enumeration...46 Sequence Assignments...47 Mutable vs Immutable Objects...49 Multi Target Assignments...51 Assignment Shorthand...52 Exercises...54 Numeric Operations...55 More About Numeric Types...56 Numeric Tools...59 The Decimal Module...60 Operator Precedence...61 Exercises...62 String Types...63 Generating Strings...64 Common String Methods...67 Type Conversion...76 Exercises...78 Formatting String Output...79 Variable Substitution...81 String Slicing...82 Exercises...83 Page 2 of 243
Lists & Tuples...84 Python Lists...85 Common List Methods...86 Other List Operations...89 The range() Function...91 Multi-Dimensional Lists (Matrices)...93 Tuples...94 Dictionaries...96 Python Dictionaries...97 Assigning Values to Dictionaries...98 Dictionary Methods...101 Dictionaries vs Lists & Tuples...105 Exercises...106 Python Compound Statements...107 Python Nesting Recap...108 Comparison Operations...109 The if Statement...111 The if Ternary Expression...112 Using try To Handle Errors...113 The while Loop...115 Exercises...117 The for Loop...118 Traversing Parallel Sets...119 Exercises...121 Basic Input/Output with Files...122 Opening Files...123 Working with Files...124 Controlling Output Location...127 Exercises...129 Understanding Iterators...130 Iterable Objects...131 The iter() Function...132 Using map With Iterators...133 Exercises...134 Python List Comprehension...135 Basic List Comprehensions...136 Compound List Comprehensions...138 Exercises...139 Creating Python Functions...140 Function Basics...141 Defining Functions...143 Function Polymorphism...144 Argument Defaults...145 Lambdas...146 Local Variables...148 Variable Masking...149 Understanding builtin...150 Preventing Variable Modifications...151 Exercises...152 Argument Matching Methods...153 Exercises...156 Modules & Packages...157 Module Basics...158 Packages...160 Page 3 of 243
Using all and _ Variables...163 Using name...164 Exercises...165 Object Oriented Python...166 About OOP...167 The Class Statements...168 Class Inheritance...170 Classes as Objects...172 Using Dictionaries...174 Understanding self...176 Overriding Inherited Methods...178 More Inheritance...179 Operator Overloading...180 The iter Method...182 The getitem Method...184 Empty Classes For Storage...185 Pickling & Shelving Objects...186 Exercises...188 Multiple Inheritance...189 Exceptions...191 About Exceptions...192 Python's Default Exception Handler...193 Using Try/Except/Finally Exceptions...194 Generating User Defined Exceptions...196 More on Exceptions...197 Exception Examples...198 Using Asserts...201 Exception Classes...202 Exercises...203 Python Generators...204 About Generators...205 Generator Syntax...206 Communicating with Generators with send()...207 Exercises...209 OS Interfacing...210 About the sys & os Modules...211 Gleaning More Using doc & help()...212 Common sys Module Attributes & Methods...213 Working With the os Module & Files/Directories...215 File & Path Examples...218 Working with os.path...219 os & os.path Module Examples...221 Running Shell Commands...222 Accessing Databases with Python...224 About Database Access...225 About psycopg2...227 PostgreSQL Connect Strings...228 Cursor Objects...231 PsychoPG2 Examples...233 Exercises...236 Python & the Web...237 About the Web...238 Understanding HTTP...239 Using the CGI Module...240 Page 4 of 243
Questions?...242 Where to Get Answers/Next Steps...243 Page 5 of 243