upload/wll/ENTER/Science/IT & AI/IT Library/Programming/Python/Python Scripting For Computational Science.pdf
Python Scripting for Computational Science (Texts in Computational Science and Engineering) (v. 3) 🔍
Hans Petter Langtangen
Springer Berlin, Texts in Computational Science and Engineering, 1, 2004
English [en] · PDF · 5.1MB · 2004 · 📘 Book (non-fiction) · 🚀/lgli/lgrs/nexusstc/upload/zlib · Save
description
The goal of this book is to teach computational scientists and engineers how to develop tailored, flexible, and efficient working environments built from small programs (scripts) written in the easy-to-learn, very high-level language Python. The focus is on examples and applications of relevance to computational science: gluing existing applications and tools, e.g. for automating simulation, data analysis, and visualization; steering simulations and computational experiments; equipping programs with graphical user interfaces; making computational Web services; creating interactive interfaces with a Maple/Matlab-like syntax to numerical applications in C/C++ or Fortran; and building flexible object-oriented programming interfaces to existing C/C++ or Fortran libraries. In short, scripting with Python makes you much more productive, increases the reliability of your scientific work and lets you have more fun - under Unix, Windows and MacIntosh.
Alternative filename
upload/misc/Y9EgLx762wKqWqG7nloH/Books/Gentoomen Library/Programming/Python/Python Scripting For Computational Science.pdf
Alternative filename
upload/motw_shc_2025_10/shc/Python Scripting for Computational Science - Hans Petter Langtangen.pdf
Alternative filename
motw/Python Scripting for Computational Science - Hans Petter Langtangen.pdf
Alternative filename
lgli/dvd44/Langtangen H.P. - Python Scripting for Computational Science(2004)(726).pdf
Alternative filename
lgrsnf/dvd44/Langtangen H.P. - Python Scripting for Computational Science(2004)(726).pdf
Alternative filename
nexusstc/Python Scripting for Computational Science/d03376022b7556d68383b9d4f01e9ebd.pdf
Alternative filename
zlib/Computers/Programming/Hans Petter Langtangen/Python Scripting for Computational Science_489358.pdf
Alternative author
LaTeX with hyperref package
Alternative author
Langtangen, Hans Petter
Alternative publisher
Springer Spektrum. in Springer-Verlag GmbH
Alternative publisher
Steinkopff. in Springer-Verlag GmbH
Alternative edition
Texts in computational science and engineering -- 3, Texts in computational science and engineering -- 3., 3rd ed., Berlin, Germany, 2009
Alternative edition
Texts in computational science and engineering, 3, 3. ed., corrected 2. print, Berlin ; Heidelberg, 2009
Alternative edition
Texts in computational science and engineering : TCSE -- 3, Berlin [etc.], Germany, 2004
Alternative edition
Texts in computational science and engineering,, 3, Berlin, New York, Germany, 2004
Alternative edition
Springer Nature (Textbooks & Major Reference Works), Berlin, Heidelberg, 2007
Alternative edition
Springer Nature (Textbooks & Major Reference Works), Berlin, Heidelberg, 2004
Alternative edition
Texts in computational science and engineering, 3, 3rd ed, Berlin, ©2008
Alternative edition
Germany, Germany
Alternative edition
3rd, 2007
metadata comments
mexmat -- 44
metadata comments
lg56976
metadata comments
producers:
dvips + GNU Ghostscript 7.07
dvips + GNU Ghostscript 7.07
metadata comments
{"edition":"1","isbns":["3540435085","9783540435082"],"last_page":745,"publisher":"Springer","series":"Texts in Computational Science and Engineering"}
metadata comments
Memory of the World Librarian: Quintus
metadata comments
类型: 图书
metadata comments
出版日期: 2004.09
metadata comments
出版社: Springer
metadata comments
页码: 726
metadata comments
开本: $186.80
metadata comments
价格: 9.1 x 6.3 x 1.3 inches
metadata comments
Includes bibliographical references (p. [715]-716) and index.
metadata comments
Previous ed.: 2006.
Includes bibliographical references (p. [739]-740) and index.
Includes bibliographical references (p. [739]-740) and index.
metadata comments
РГБ
metadata comments
Russian State Library [rgb] MARC:
=001 002794035
=005 20060117143627.0
=008 040602s2004\\\\gw\a\\\\\b\\\\001\0\eng\\
=017 \\ $a И13962-05
=020 \\ $a 3540435085
=035 \\ $a (OCoLC)ocm53963082
=040 \\ $a UKM $b rus $e rcr $c UKM $d OCLCQ $d OHX $d AZS $d RuMoRGB
=041 0\ $a eng
=044 \\ $a gw
=072 \7 $a QA $2 lcco
=084 \\ $a З973.2-018.19Python,0 $2 rubbk
=100 1\ $a Langtangen, Hans Petter $d 1962-
=245 00 $a Python scripting for computational science / $c Hans Petter Langtangen.
=260 \\ $a Berlin [etc.] $b Springer, $c cop. 2004.
=300 \\ $a XXII, 726 с. : $b ил. ; $c 24 см
=490 0\ $a Texts in computational science and engineering : TCSE, $v 3 $x 1611-0994 ;
=504 \\ $a Includes bibliographical references (p. [715]-716) and index.
=650 \7 $a Вычислительная техника -- Вычислительные машины электронные цифровые -- Языки программирования -- Python $2 rubbk
=852 4\ $a РГБ $b FB $j 5 05-11/155 $x 90
=001 002794035
=005 20060117143627.0
=008 040602s2004\\\\gw\a\\\\\b\\\\001\0\eng\\
=017 \\ $a И13962-05
=020 \\ $a 3540435085
=035 \\ $a (OCoLC)ocm53963082
=040 \\ $a UKM $b rus $e rcr $c UKM $d OCLCQ $d OHX $d AZS $d RuMoRGB
=041 0\ $a eng
=044 \\ $a gw
=072 \7 $a QA $2 lcco
=084 \\ $a З973.2-018.19Python,0 $2 rubbk
=100 1\ $a Langtangen, Hans Petter $d 1962-
=245 00 $a Python scripting for computational science / $c Hans Petter Langtangen.
=260 \\ $a Berlin [etc.] $b Springer, $c cop. 2004.
=300 \\ $a XXII, 726 с. : $b ил. ; $c 24 см
=490 0\ $a Texts in computational science and engineering : TCSE, $v 3 $x 1611-0994 ;
=504 \\ $a Includes bibliographical references (p. [715]-716) and index.
=650 \7 $a Вычислительная техника -- Вычислительные машины электронные цифровые -- Языки программирования -- Python $2 rubbk
=852 4\ $a РГБ $b FB $j 5 05-11/155 $x 90
Alternative description
1.1.1 Why Scripting is Useful in Computational Science......Page 21
1.1.2 Classification of Programming Languages......Page 24
1.1.3 Productive Pairs of Programming Languages......Page 25
1.1.4 Gluing Existing Applications......Page 26
1.1.5 Scripting Yields Shorter Code......Page 27
1.1.6 Efficiency......Page 28
1.1.7 Type-Specification (Declaration) of Variables......Page 29
1.1.8 Flexible Function Interfaces......Page 31
1.1.9 Interactive Computing......Page 32
1.1.10 Creating Code at Run Time......Page 33
1.1.11 Nested Heterogeneous Data Structures......Page 34
1.1.12 GUI Programming......Page 36
1.1.13 Mixed Language Programming......Page 37
1.1.14 When to Choose a Dynamically Typed Language......Page 39
1.1.15 Why Python?......Page 40
1.1.16 Script or Program?......Page 41
1.2 Preparations for Working with This Book......Page 42
2.1 A Scientific Hello World Script......Page 47
2.1.1 Executing Python Scripts......Page 48
2.1.2 Dissection of the Scientific Hello World Script......Page 49
2.2.1 Problem Specification......Page 52
2.2.3 Dissection......Page 53
2.2.4 Working with Files in Memory......Page 56
2.2.5 Efficiency Measurements......Page 57
2.2.6 Exercises......Page 58
2.3 Automating Simulation and Visualization......Page 60
2.3.1 The Simulation Code......Page 61
2.3.2 Using Gnuplot to Visualize Curves......Page 63
2.3.3 Functionality of the Script......Page 64
2.3.4 The Complete Code......Page 65
2.3.5 Dissection......Page 67
2.3.6 Exercises......Page 69
2.4 Conducting Numerical Experiments......Page 72
2.4.1 Wrapping a Loop Around Another Script......Page 73
2.4.2 Generating an HTML Report......Page 74
2.4.3 Making Animations......Page 76
2.4.4 Varying Any Parameter......Page 77
2.5 File Format Conversion......Page 80
2.5.1 The First Version of the Script......Page 81
2.5.2 The Second Version of the Script......Page 82
3.1.1 Recommended Python Documentation......Page 85
3.1.2 Testing Statements in the Interactive Shell......Page 86
3.1.3 Control Statements......Page 88
3.1.4 Running an Application......Page 89
3.1.5 File Reading and Writing......Page 90
3.1.6 Output Formatting......Page 92
3.1.7 Exercises......Page 93
3.2.1 Boolean Types......Page 94
3.2.2 The None Variable......Page 95
3.2.3 Numbers and Numerical Expressions......Page 96
3.2.4 Lists and Tuples......Page 97
3.2.5 Dictionaries......Page 104
3.2.6 Splitting and Joining Text......Page 107
3.2.7 String Operations......Page 108
3.2.8 Text Processing......Page 109
3.2.9 The Basics of a Python Class......Page 111
3.2.10 Determining a Variable's Type......Page 113
3.2.11 Exercises......Page 116
3.3 Functions......Page 121
3.3.1 Keyword Arguments......Page 122
3.3.3 Variable Number of Arguments......Page 123
3.3.4 Call by Reference......Page 124
3.3.5 Treatment of Input and Output Arguments......Page 126
3.3.6 Function Objects......Page 127
3.4 Working with Files and Directories......Page 128
3.4.2 Testing File Types......Page 129
3.4.3 Copying and Renaming Files......Page 130
3.4.5 Splitting Pathnames......Page 131
3.4.7 Traversing Directory Trees......Page 132
3.4.8 Exercises......Page 135
4 Numerical Computing in Python......Page 141
4.1.1 Creating Arrays......Page 143
4.1.2 Array Indexing......Page 144
4.1.3 Array Computations......Page 146
4.1.4 Type Testing......Page 147
4.1.5 Hidden Temporary Arrays......Page 149
4.1.6 Exercises......Page 150
4.2 Vectorized Algorithms......Page 151
4.2.1 Arrays as Function Arguments......Page 152
4.2.2 Slicing......Page 153
4.2.3 Remark on Efficiency......Page 154
4.2.4 Exercises......Page 156
4.3.1 Random Numbers......Page 157
4.3.3 The Gnuplot Module......Page 159
4.3.4 Example: Curve Fitting......Page 162
4.3.5 Arrays on Structured Grids......Page 164
4.3.6 File I/O with NumPy Arrays......Page 166
4.3.7 Reading and Writing Tables with NumPy Arrays......Page 167
4.3.8 Functionality in the Numpytools Module......Page 170
4.3.9 Exercises......Page 172
4.4.1 The ScientificPython Package......Page 176
4.4.2 The SciPy Package......Page 181
4.4.3 The Python--Matlab Interface......Page 185
4.4.4 Some Useful Python Modules......Page 186
4.5 A Database for NumPy Arrays......Page 187
4.5.1 The Structure of the Database......Page 188
4.5.2 Pickling......Page 190
4.5.3 Formatted ASCII Storage......Page 191
4.5.4 Shelving......Page 192
4.5.5 Comparing the Various Techniques......Page 193
5.1.1 Applications of Mixed Language Programming......Page 195
5.1.2 Calling C from Python......Page 196
5.1.3 Automatic Generation of Wrapper Code......Page 198
5.2 Scientific Hello World Examples......Page 200
5.2.1 Combining Python and Fortran......Page 201
5.2.2 Combining Python and C......Page 206
5.2.3 Combining Python and C++ Functions......Page 212
5.2.4 Combining Python and C++ Classes......Page 214
5.2.5 Exercises......Page 217
5.3 A Simple Computational Steering Example......Page 218
5.3.1 Modified Time Loop for Repeated Simulations......Page 219
5.3.2 Creating a Python Interface......Page 220
5.3.3 The Steering Python Script......Page 222
5.3.4 Equipping the Steering Script with a GUI......Page 225
5.4 Scripting Interfaces to Large Libraries......Page 227
6.1.1 Introductory Topics......Page 231
6.1.2 The First Python/Tkinter Encounter......Page 234
6.1.3 Binding Events......Page 237
6.1.4 Changing the Layout......Page 238
6.1.5 The Final Scientific Hello World GUI......Page 242
6.1.6 An Alternative to Tkinter Variables......Page 244
6.1.7 About the Pack Command......Page 245
6.1.8 An Introduction to the Grid Geometry Manager......Page 247
6.1.9 Implementing a GUI as a Class......Page 249
6.1.10 A Simple Graphical Function Evaluator......Page 251
6.1.11 Exercises......Page 253
6.2.1 A Simulation and Visualization Script with a GUI......Page 255
6.2.2 Improving the Layout......Page 258
6.2.3 Exercises......Page 261
6.3 A List of Common Widget Operations......Page 262
6.3.2 Label......Page 265
6.3.4 Text Entry......Page 267
6.3.5 Balloon Help......Page 269
6.3.7 Slider......Page 270
6.3.9 Making a Simple Megawidget......Page 271
6.3.10 Menu Bar......Page 272
6.3.11 List Data......Page 274
6.3.12 Listbox......Page 275
6.3.13 Radio Button......Page 278
6.3.14 Combo Box......Page 279
6.3.15 Message Box......Page 280
6.3.16 User-Defined Dialogs......Page 282
6.3.17 Color-Picker Dialogs......Page 283
6.3.18 File Selection Dialogs......Page 286
6.3.19 Toplevel......Page 287
6.3.20 Some Other Types of Widgets......Page 288
6.3.21 Adapting Widgets to the User's Resize Actions......Page 289
6.3.22 Customizing Fonts and Colors......Page 291
6.3.23 Widget Overview......Page 293
6.3.24 Exercises......Page 295
7 Web Interfaces and CGI Programming......Page 301
7.1.1 Web Forms and CGI Scripts......Page 302
7.1.2 Generating Forms in CGI Scripts......Page 305
7.1.3 Debugging CGI Scripts......Page 307
7.1.4 Security Issues......Page 309
7.1.5 A General Shell Script Wrapper for CGI Scripts......Page 310
7.2.1 A Class for Form Parameters......Page 312
7.2.2 Calling Other Programs......Page 315
7.2.3 Running Simulations......Page 316
7.2.4 Getting a CGI Script to Work......Page 317
7.2.5 Using Web Services from Scripts......Page 320
7.2.6 Exercises......Page 322
8.1.1 Parsing Command-Line Arguments......Page 325
8.1.2 Platform-Dependent Operations......Page 328
8.1.3 Run-Time Generation of Code......Page 329
8.1.4 Exercises......Page 330
8.2 Regular Expressions and Text Processing......Page 331
8.2.1 Motivation......Page 332
8.2.2 Special Characters......Page 335
8.2.3 Regular Expressions for Real Numbers......Page 336
8.2.5 Extracting Interval Limits......Page 340
8.2.6 Extracting Multiple Matches......Page 345
8.2.7 Splitting Text......Page 349
8.2.8 Pattern-Matching Modifiers......Page 350
8.2.10 Example: Swapping Arguments in Function Calls......Page 353
8.2.11 A General Substitution Script......Page 357
8.2.12 Debugging Regular Expressions......Page 358
8.2.13 Exercises......Page 360
8.3.1 Writing and Reading Python Data Structures......Page 370
8.3.2 Pickling Objects......Page 372
8.3.3 Shelving Objects......Page 374
8.3.4 Writing and Reading Zip Archive Files......Page 375
8.3.5 Downloading Internet Files......Page 376
8.3.6 Binary Input/Output......Page 377
8.4 Scripts Involving Local and Remote Hosts......Page 379
8.4.1 Secure Shell Commands......Page 380
8.4.2 Distributed Simulation and Visualization......Page 381
8.4.4 Threads......Page 383
8.5.1 Class Programming......Page 385
8.5.2 Checking the Class Type......Page 389
8.5.4 Static Data......Page 390
8.5.6 Special Methods......Page 391
8.5.8 Using a Class as a C-like Structure......Page 393
8.5.9 Attribute Access via String Names......Page 394
8.5.10 Example: Turning String Formulas into Functions......Page 395
8.5.11 Example: Class for Structured Grids......Page 396
8.5.13 Implementing Get/Set Functions via Properties......Page 399
8.5.14 Subclassing Built-in Types......Page 401
8.5.15 Copy and Assignment......Page 403
8.5.16 Building Class Interfaces at Run Time......Page 406
8.5.17 Building Flexible Class Interfaces......Page 409
8.5.18 Exercises......Page 416
8.6.1 Global, Local, and Class Variables......Page 419
8.6.2 Nested Functions......Page 421
8.6.3 Dictionaries of Variables in Namespaces......Page 422
8.7 Exceptions......Page 424
8.7.1 Handling Exceptions......Page 425
8.7.2 Raising Exceptions......Page 426
8.8.1 Constructing an Iterator......Page 427
8.8.2 A Pointwise Grid Iterator......Page 429
8.8.3 A Vectorized Grid Iterator......Page 433
8.8.4 Generators......Page 435
8.8.5 Some Aspects of Generic Programming......Page 437
8.9.1 CPU-Time Measurements......Page 441
8.9.2 Profiling Python Scripts......Page 444
8.9.3 Optimization of Python Code......Page 445
9.1 Problem Definition......Page 449
9.2.1 The Fortran Subroutine......Page 452
9.2.2 Building and Inspecting the Extension Module......Page 453
9.3.1 Generating an Erroneous Interface......Page 455
9.3.2 Array Storage in C and Fortran......Page 457
9.3.3 Input and Output Arrays as Function Arguments......Page 458
9.3.4 F2PY Interface Files......Page 464
9.3.5 Hiding Work Arrays......Page 468
9.4.1 Callbacks to Vectorized Python Functions......Page 469
9.4.2 Avoiding Callbacks to Python......Page 472
9.4.3 Compiled Inline Callback Functions......Page 473
9.6.1 Exercises......Page 476
10.1 C Programming with NumPy Arrays......Page 481
10.1.1 Basics of the NumPy C API......Page 482
10.1.2 The Handwritten Extension Code......Page 484
10.1.3 Sending Arguments from Python to C......Page 485
10.1.4 Consistency Checks......Page 486
10.1.5 Computing Array Values......Page 487
10.1.6 Returning an Output Array......Page 489
10.1.7 Convenient Macros......Page 490
10.1.8 Module Initialization......Page 491
10.1.9 Extension Module Template......Page 492
10.1.10 Compiling, Linking, and Debugging the Module......Page 494
10.1.11 Writing a Wrapper for a C Function......Page 495
10.2.1 Wrapping a NumPy Array in a C++ Object......Page 498
10.2.2 Using SCXX......Page 500
10.2.3 NumPy--C++ Class Conversion......Page 503
10.3.1 Efficiency......Page 512
10.3.2 Error Handling......Page 515
10.3.3 Summary......Page 516
10.3.4 Exercises......Page 517
11.1 Adding Plot Areas in GUIs......Page 523
11.1.1 The BLT Graph Widget......Page 524
11.1.2 Animation of Functions in BLT Graph Widgets......Page 530
11.1.3 Other Tools for Making GUIs with Plots......Page 532
11.1.4 Exercises......Page 534
11.2.1 Binding Events to Functions with Arguments......Page 537
11.2.2 A Text Widget with Tailored Keyboard Bindings......Page 540
11.2.3 A Fancy List Widget......Page 543
11.3 Animated Graphics with Canvas Widgets......Page 546
11.3.1 The First Canvas Encounter......Page 547
11.3.2 Coordinate Systems......Page 548
11.3.3 The Mathematical Model Class......Page 552
11.3.4 The Planet Class......Page 553
11.3.5 Drawing and Moving Planets......Page 555
11.3.6 Dragging Planets to New Positions......Page 556
11.3.7 Using Pmw's Scrolled Canvas Widget......Page 560
11.4 Tools for Simulation & Visualization Scripts......Page 562
11.4.1 Restructuring the Script......Page 563
11.4.2 Representing a Parameter by a Class......Page 565
11.4.3 Improved Command-Line Script......Page 579
11.4.4 Improved GUI Script......Page 580
11.4.5 Improved CGI Script......Page 581
11.4.6 Parameters with Physical Dimensions......Page 582
11.4.7 Adding a Curve Plot Area......Page 584
11.4.8 Automatic Generation of Scripts......Page 586
11.4.9 Applications of the Tools......Page 587
11.4.10 Allowing Physical Units in Input Files......Page 592
11.4.11 Converting Input Files to GUIs......Page 596
12.1 Running Series of Computer Experiments......Page 599
12.1.1 Multiple Values of Input Parameters......Page 600
12.1.2 Implementation Details......Page 603
12.1.3 Further Applications......Page 608
12.2.1 Functions Defined by String Formulas......Page 612
12.2.2 A Unified Interface to Functions......Page 614
12.2.3 Interactive Drawing of Functions......Page 620
12.2.4 A Notebook for Selecting Functions......Page 626
12.3 Solving Partial Differential Equations......Page 632
12.3.1 Numerical Methods for 1D Wave Equations......Page 633
12.3.2 Implementations of 1D Wave Equations......Page 636
12.3.3 Classes for Solving 1D Wave Equations......Page 642
12.3.4 A Problem Solving Environment......Page 649
12.3.5 Numerical Methods for 2D Wave Equations......Page 655
12.3.6 Implementations of 2D Wave Equations......Page 658
A.1 Installation on Unix Systems......Page 669
A.1.2 Setting Some Environment Variables......Page 670
A.1.3 Installing Tcl/Tk and Additional Modules......Page 671
A.1.4 Installing Python......Page 672
A.1.5 Installing Python Modules......Page 674
A.1.7 Installing SWIG......Page 678
A.1.9 Testing the Installation of Scripting Utilities......Page 679
A.2 Installation on Windows Systems......Page 680
B.1.1 Single-File Modules......Page 685
B.1.2 Multi-File Modules......Page 688
B.1.3 Debugging and Troubleshooting......Page 690
B.2 Tools for Documenting Python Software......Page 692
B.2.1 Doc Strings......Page 693
B.2.2 Tools for Automatic Documentation......Page 694
B.3.1 Style Guide......Page 698
B.3.2 Pythonic Programming......Page 702
B.4.1 Automating Regression Tests......Page 707
B.4.2 Implementing a Tool for Regression Tests......Page 712
B.4.3 Writing a Test Script......Page 715
B.4.4 Verifying Output from Numerical Computations......Page 716
B.4.5 Automatic Doc String Testing......Page 720
B.4.6 Unit Testing......Page 722
B.5 Version Control Management......Page 724
B.5.1 Getting Started with CVS......Page 725
B.6 Exercises......Page 729
1.1.2 Classification of Programming Languages......Page 24
1.1.3 Productive Pairs of Programming Languages......Page 25
1.1.4 Gluing Existing Applications......Page 26
1.1.5 Scripting Yields Shorter Code......Page 27
1.1.6 Efficiency......Page 28
1.1.7 Type-Specification (Declaration) of Variables......Page 29
1.1.8 Flexible Function Interfaces......Page 31
1.1.9 Interactive Computing......Page 32
1.1.10 Creating Code at Run Time......Page 33
1.1.11 Nested Heterogeneous Data Structures......Page 34
1.1.12 GUI Programming......Page 36
1.1.13 Mixed Language Programming......Page 37
1.1.14 When to Choose a Dynamically Typed Language......Page 39
1.1.15 Why Python?......Page 40
1.1.16 Script or Program?......Page 41
1.2 Preparations for Working with This Book......Page 42
2.1 A Scientific Hello World Script......Page 47
2.1.1 Executing Python Scripts......Page 48
2.1.2 Dissection of the Scientific Hello World Script......Page 49
2.2.1 Problem Specification......Page 52
2.2.3 Dissection......Page 53
2.2.4 Working with Files in Memory......Page 56
2.2.5 Efficiency Measurements......Page 57
2.2.6 Exercises......Page 58
2.3 Automating Simulation and Visualization......Page 60
2.3.1 The Simulation Code......Page 61
2.3.2 Using Gnuplot to Visualize Curves......Page 63
2.3.3 Functionality of the Script......Page 64
2.3.4 The Complete Code......Page 65
2.3.5 Dissection......Page 67
2.3.6 Exercises......Page 69
2.4 Conducting Numerical Experiments......Page 72
2.4.1 Wrapping a Loop Around Another Script......Page 73
2.4.2 Generating an HTML Report......Page 74
2.4.3 Making Animations......Page 76
2.4.4 Varying Any Parameter......Page 77
2.5 File Format Conversion......Page 80
2.5.1 The First Version of the Script......Page 81
2.5.2 The Second Version of the Script......Page 82
3.1.1 Recommended Python Documentation......Page 85
3.1.2 Testing Statements in the Interactive Shell......Page 86
3.1.3 Control Statements......Page 88
3.1.4 Running an Application......Page 89
3.1.5 File Reading and Writing......Page 90
3.1.6 Output Formatting......Page 92
3.1.7 Exercises......Page 93
3.2.1 Boolean Types......Page 94
3.2.2 The None Variable......Page 95
3.2.3 Numbers and Numerical Expressions......Page 96
3.2.4 Lists and Tuples......Page 97
3.2.5 Dictionaries......Page 104
3.2.6 Splitting and Joining Text......Page 107
3.2.7 String Operations......Page 108
3.2.8 Text Processing......Page 109
3.2.9 The Basics of a Python Class......Page 111
3.2.10 Determining a Variable's Type......Page 113
3.2.11 Exercises......Page 116
3.3 Functions......Page 121
3.3.1 Keyword Arguments......Page 122
3.3.3 Variable Number of Arguments......Page 123
3.3.4 Call by Reference......Page 124
3.3.5 Treatment of Input and Output Arguments......Page 126
3.3.6 Function Objects......Page 127
3.4 Working with Files and Directories......Page 128
3.4.2 Testing File Types......Page 129
3.4.3 Copying and Renaming Files......Page 130
3.4.5 Splitting Pathnames......Page 131
3.4.7 Traversing Directory Trees......Page 132
3.4.8 Exercises......Page 135
4 Numerical Computing in Python......Page 141
4.1.1 Creating Arrays......Page 143
4.1.2 Array Indexing......Page 144
4.1.3 Array Computations......Page 146
4.1.4 Type Testing......Page 147
4.1.5 Hidden Temporary Arrays......Page 149
4.1.6 Exercises......Page 150
4.2 Vectorized Algorithms......Page 151
4.2.1 Arrays as Function Arguments......Page 152
4.2.2 Slicing......Page 153
4.2.3 Remark on Efficiency......Page 154
4.2.4 Exercises......Page 156
4.3.1 Random Numbers......Page 157
4.3.3 The Gnuplot Module......Page 159
4.3.4 Example: Curve Fitting......Page 162
4.3.5 Arrays on Structured Grids......Page 164
4.3.6 File I/O with NumPy Arrays......Page 166
4.3.7 Reading and Writing Tables with NumPy Arrays......Page 167
4.3.8 Functionality in the Numpytools Module......Page 170
4.3.9 Exercises......Page 172
4.4.1 The ScientificPython Package......Page 176
4.4.2 The SciPy Package......Page 181
4.4.3 The Python--Matlab Interface......Page 185
4.4.4 Some Useful Python Modules......Page 186
4.5 A Database for NumPy Arrays......Page 187
4.5.1 The Structure of the Database......Page 188
4.5.2 Pickling......Page 190
4.5.3 Formatted ASCII Storage......Page 191
4.5.4 Shelving......Page 192
4.5.5 Comparing the Various Techniques......Page 193
5.1.1 Applications of Mixed Language Programming......Page 195
5.1.2 Calling C from Python......Page 196
5.1.3 Automatic Generation of Wrapper Code......Page 198
5.2 Scientific Hello World Examples......Page 200
5.2.1 Combining Python and Fortran......Page 201
5.2.2 Combining Python and C......Page 206
5.2.3 Combining Python and C++ Functions......Page 212
5.2.4 Combining Python and C++ Classes......Page 214
5.2.5 Exercises......Page 217
5.3 A Simple Computational Steering Example......Page 218
5.3.1 Modified Time Loop for Repeated Simulations......Page 219
5.3.2 Creating a Python Interface......Page 220
5.3.3 The Steering Python Script......Page 222
5.3.4 Equipping the Steering Script with a GUI......Page 225
5.4 Scripting Interfaces to Large Libraries......Page 227
6.1.1 Introductory Topics......Page 231
6.1.2 The First Python/Tkinter Encounter......Page 234
6.1.3 Binding Events......Page 237
6.1.4 Changing the Layout......Page 238
6.1.5 The Final Scientific Hello World GUI......Page 242
6.1.6 An Alternative to Tkinter Variables......Page 244
6.1.7 About the Pack Command......Page 245
6.1.8 An Introduction to the Grid Geometry Manager......Page 247
6.1.9 Implementing a GUI as a Class......Page 249
6.1.10 A Simple Graphical Function Evaluator......Page 251
6.1.11 Exercises......Page 253
6.2.1 A Simulation and Visualization Script with a GUI......Page 255
6.2.2 Improving the Layout......Page 258
6.2.3 Exercises......Page 261
6.3 A List of Common Widget Operations......Page 262
6.3.2 Label......Page 265
6.3.4 Text Entry......Page 267
6.3.5 Balloon Help......Page 269
6.3.7 Slider......Page 270
6.3.9 Making a Simple Megawidget......Page 271
6.3.10 Menu Bar......Page 272
6.3.11 List Data......Page 274
6.3.12 Listbox......Page 275
6.3.13 Radio Button......Page 278
6.3.14 Combo Box......Page 279
6.3.15 Message Box......Page 280
6.3.16 User-Defined Dialogs......Page 282
6.3.17 Color-Picker Dialogs......Page 283
6.3.18 File Selection Dialogs......Page 286
6.3.19 Toplevel......Page 287
6.3.20 Some Other Types of Widgets......Page 288
6.3.21 Adapting Widgets to the User's Resize Actions......Page 289
6.3.22 Customizing Fonts and Colors......Page 291
6.3.23 Widget Overview......Page 293
6.3.24 Exercises......Page 295
7 Web Interfaces and CGI Programming......Page 301
7.1.1 Web Forms and CGI Scripts......Page 302
7.1.2 Generating Forms in CGI Scripts......Page 305
7.1.3 Debugging CGI Scripts......Page 307
7.1.4 Security Issues......Page 309
7.1.5 A General Shell Script Wrapper for CGI Scripts......Page 310
7.2.1 A Class for Form Parameters......Page 312
7.2.2 Calling Other Programs......Page 315
7.2.3 Running Simulations......Page 316
7.2.4 Getting a CGI Script to Work......Page 317
7.2.5 Using Web Services from Scripts......Page 320
7.2.6 Exercises......Page 322
8.1.1 Parsing Command-Line Arguments......Page 325
8.1.2 Platform-Dependent Operations......Page 328
8.1.3 Run-Time Generation of Code......Page 329
8.1.4 Exercises......Page 330
8.2 Regular Expressions and Text Processing......Page 331
8.2.1 Motivation......Page 332
8.2.2 Special Characters......Page 335
8.2.3 Regular Expressions for Real Numbers......Page 336
8.2.5 Extracting Interval Limits......Page 340
8.2.6 Extracting Multiple Matches......Page 345
8.2.7 Splitting Text......Page 349
8.2.8 Pattern-Matching Modifiers......Page 350
8.2.10 Example: Swapping Arguments in Function Calls......Page 353
8.2.11 A General Substitution Script......Page 357
8.2.12 Debugging Regular Expressions......Page 358
8.2.13 Exercises......Page 360
8.3.1 Writing and Reading Python Data Structures......Page 370
8.3.2 Pickling Objects......Page 372
8.3.3 Shelving Objects......Page 374
8.3.4 Writing and Reading Zip Archive Files......Page 375
8.3.5 Downloading Internet Files......Page 376
8.3.6 Binary Input/Output......Page 377
8.4 Scripts Involving Local and Remote Hosts......Page 379
8.4.1 Secure Shell Commands......Page 380
8.4.2 Distributed Simulation and Visualization......Page 381
8.4.4 Threads......Page 383
8.5.1 Class Programming......Page 385
8.5.2 Checking the Class Type......Page 389
8.5.4 Static Data......Page 390
8.5.6 Special Methods......Page 391
8.5.8 Using a Class as a C-like Structure......Page 393
8.5.9 Attribute Access via String Names......Page 394
8.5.10 Example: Turning String Formulas into Functions......Page 395
8.5.11 Example: Class for Structured Grids......Page 396
8.5.13 Implementing Get/Set Functions via Properties......Page 399
8.5.14 Subclassing Built-in Types......Page 401
8.5.15 Copy and Assignment......Page 403
8.5.16 Building Class Interfaces at Run Time......Page 406
8.5.17 Building Flexible Class Interfaces......Page 409
8.5.18 Exercises......Page 416
8.6.1 Global, Local, and Class Variables......Page 419
8.6.2 Nested Functions......Page 421
8.6.3 Dictionaries of Variables in Namespaces......Page 422
8.7 Exceptions......Page 424
8.7.1 Handling Exceptions......Page 425
8.7.2 Raising Exceptions......Page 426
8.8.1 Constructing an Iterator......Page 427
8.8.2 A Pointwise Grid Iterator......Page 429
8.8.3 A Vectorized Grid Iterator......Page 433
8.8.4 Generators......Page 435
8.8.5 Some Aspects of Generic Programming......Page 437
8.9.1 CPU-Time Measurements......Page 441
8.9.2 Profiling Python Scripts......Page 444
8.9.3 Optimization of Python Code......Page 445
9.1 Problem Definition......Page 449
9.2.1 The Fortran Subroutine......Page 452
9.2.2 Building and Inspecting the Extension Module......Page 453
9.3.1 Generating an Erroneous Interface......Page 455
9.3.2 Array Storage in C and Fortran......Page 457
9.3.3 Input and Output Arrays as Function Arguments......Page 458
9.3.4 F2PY Interface Files......Page 464
9.3.5 Hiding Work Arrays......Page 468
9.4.1 Callbacks to Vectorized Python Functions......Page 469
9.4.2 Avoiding Callbacks to Python......Page 472
9.4.3 Compiled Inline Callback Functions......Page 473
9.6.1 Exercises......Page 476
10.1 C Programming with NumPy Arrays......Page 481
10.1.1 Basics of the NumPy C API......Page 482
10.1.2 The Handwritten Extension Code......Page 484
10.1.3 Sending Arguments from Python to C......Page 485
10.1.4 Consistency Checks......Page 486
10.1.5 Computing Array Values......Page 487
10.1.6 Returning an Output Array......Page 489
10.1.7 Convenient Macros......Page 490
10.1.8 Module Initialization......Page 491
10.1.9 Extension Module Template......Page 492
10.1.10 Compiling, Linking, and Debugging the Module......Page 494
10.1.11 Writing a Wrapper for a C Function......Page 495
10.2.1 Wrapping a NumPy Array in a C++ Object......Page 498
10.2.2 Using SCXX......Page 500
10.2.3 NumPy--C++ Class Conversion......Page 503
10.3.1 Efficiency......Page 512
10.3.2 Error Handling......Page 515
10.3.3 Summary......Page 516
10.3.4 Exercises......Page 517
11.1 Adding Plot Areas in GUIs......Page 523
11.1.1 The BLT Graph Widget......Page 524
11.1.2 Animation of Functions in BLT Graph Widgets......Page 530
11.1.3 Other Tools for Making GUIs with Plots......Page 532
11.1.4 Exercises......Page 534
11.2.1 Binding Events to Functions with Arguments......Page 537
11.2.2 A Text Widget with Tailored Keyboard Bindings......Page 540
11.2.3 A Fancy List Widget......Page 543
11.3 Animated Graphics with Canvas Widgets......Page 546
11.3.1 The First Canvas Encounter......Page 547
11.3.2 Coordinate Systems......Page 548
11.3.3 The Mathematical Model Class......Page 552
11.3.4 The Planet Class......Page 553
11.3.5 Drawing and Moving Planets......Page 555
11.3.6 Dragging Planets to New Positions......Page 556
11.3.7 Using Pmw's Scrolled Canvas Widget......Page 560
11.4 Tools for Simulation & Visualization Scripts......Page 562
11.4.1 Restructuring the Script......Page 563
11.4.2 Representing a Parameter by a Class......Page 565
11.4.3 Improved Command-Line Script......Page 579
11.4.4 Improved GUI Script......Page 580
11.4.5 Improved CGI Script......Page 581
11.4.6 Parameters with Physical Dimensions......Page 582
11.4.7 Adding a Curve Plot Area......Page 584
11.4.8 Automatic Generation of Scripts......Page 586
11.4.9 Applications of the Tools......Page 587
11.4.10 Allowing Physical Units in Input Files......Page 592
11.4.11 Converting Input Files to GUIs......Page 596
12.1 Running Series of Computer Experiments......Page 599
12.1.1 Multiple Values of Input Parameters......Page 600
12.1.2 Implementation Details......Page 603
12.1.3 Further Applications......Page 608
12.2.1 Functions Defined by String Formulas......Page 612
12.2.2 A Unified Interface to Functions......Page 614
12.2.3 Interactive Drawing of Functions......Page 620
12.2.4 A Notebook for Selecting Functions......Page 626
12.3 Solving Partial Differential Equations......Page 632
12.3.1 Numerical Methods for 1D Wave Equations......Page 633
12.3.2 Implementations of 1D Wave Equations......Page 636
12.3.3 Classes for Solving 1D Wave Equations......Page 642
12.3.4 A Problem Solving Environment......Page 649
12.3.5 Numerical Methods for 2D Wave Equations......Page 655
12.3.6 Implementations of 2D Wave Equations......Page 658
A.1 Installation on Unix Systems......Page 669
A.1.2 Setting Some Environment Variables......Page 670
A.1.3 Installing Tcl/Tk and Additional Modules......Page 671
A.1.4 Installing Python......Page 672
A.1.5 Installing Python Modules......Page 674
A.1.7 Installing SWIG......Page 678
A.1.9 Testing the Installation of Scripting Utilities......Page 679
A.2 Installation on Windows Systems......Page 680
B.1.1 Single-File Modules......Page 685
B.1.2 Multi-File Modules......Page 688
B.1.3 Debugging and Troubleshooting......Page 690
B.2 Tools for Documenting Python Software......Page 692
B.2.1 Doc Strings......Page 693
B.2.2 Tools for Automatic Documentation......Page 694
B.3.1 Style Guide......Page 698
B.3.2 Pythonic Programming......Page 702
B.4.1 Automating Regression Tests......Page 707
B.4.2 Implementing a Tool for Regression Tests......Page 712
B.4.3 Writing a Test Script......Page 715
B.4.4 Verifying Output from Numerical Computations......Page 716
B.4.5 Automatic Doc String Testing......Page 720
B.4.6 Unit Testing......Page 722
B.5 Version Control Management......Page 724
B.5.1 Getting Started with CVS......Page 725
B.6 Exercises......Page 729
Alternative description
1 Introduction 21
1.1 Scripting versus Traditional Programming 21
1.1.1 Why Scripting is Useful in Computational Science 21
1.1.2 Classification of Programming Languages 24
1.1.3 Productive Pairs of Programming Languages 25
1.1.4 Gluing Existing Applications 26
1.1.5 Scripting Yields Shorter Code 27
1.1.6 Efficiency 28
1.1.7 Type-Specification (Declaration) of Variables 29
1.1.8 Flexible Function Interfaces 31
1.1.9 Interactive Computing 32
1.1.10 Creating Code at Run Time 33
1.1.11 Nested Heterogeneous Data Structures 34
1.1.12 GUI Programming 36
1.1.13 Mixed Language Programming 37
1.1.14 When to Choose a Dynamically Typed Language 39
1.1.15 Why Python? 40
1.1.16 Script or Program? 41
1.2 Preparations for Working with This Book 42
2 Getting Started with Python Scripting 47
2.1 A Scientific Hello World Script 47
2.1.1 Executing Python Scripts 48
2.1.2 Dissection of the Scientific Hello World Script 49
2.2 Reading and Writing Data Files 52
2.2.1 Problem Specification 52
2.2.2 The Complete Code 53
2.2.3 Dissection 53
2.2.4 Working with Files in Memory 56
2.2.5 Efficiency Measurements 57
2.2.6 Exercises 58
2.3 Automating Simulation and Visualization 60
2.3.1 The Simulation Code 61
2.3.2 Using Gnuplot to Visualize Curves 63
2.3.3 Functionality of the Script 64
2.3.4 The Complete Code 65
2.3.5 Dissection 67
2.3.6 Exercises 69
2.4 Conducting Numerical Experiments 72
2.4.1 Wrapping a Loop Around Another Script 73
2.4.2 Generating an HTML Report 74
2.4.3 Making Animations 76
2.4.4 Varying Any Parameter 77
2.4.5 Exercises 80
2.5 File Format Conversion 80
2.5.1 The First Version of the Script 81
2.5.2 The Second Version of the Script 82
3 Basic Python 85
3.1 Introductory Topics 85
3.1.1 Recommended Python Documentation 85
3.1.2 Testing Statements in the Interactive Shell 86
3.1.3 Control Statements 88
3.1.4 Running an Application 89
3.1.5 File Reading and Writing 90
3.1.6 Output Formatting 92
3.1.7 Exercises 93
3.2 Variables of Different Types 94
3.2.1 Boolean Types 94
3.2.2 The None Variable 95
3.2.3 Numbers and Numerical Expressions 96
3.2.4 Lists and Tuples 97
3.2.5 Dictionaries 104
3.2.6 Splitting and Joining Text 107
3.2.7 String Operations 108
3.2.8 Text Processing 109
3.2.9 The Basics of a Python Class 111
3.2.10 Determining a Variable's Type 113
3.2.11 Exercises 116
3.3 Functions 121
3.3.1 Keyword Arguments 122
3.3.2 Doc Strings 123
3.3.3 Variable Number of Arguments 123
3.3.4 Call by Reference 124
3.3.5 Treatment of Input and Output Arguments 126
3.3.6 Function Objects 127
3.4 Working with Files and Directories 128
3.4.1 Listing Files in a Directory 129
3.4.2 Testing File Types 129
3.4.3 Copying and Renaming Files 130
3.4.4 Removing Files and Directories 131
3.4.5 Splitting Pathnames 131
3.4.6 Creating and Moving to Directories 132
3.4.7 Traversing Directory Trees 132
3.4.8 Exercises 135
4 Numerical Computing in Python 141
4.1 A Quick NumPy Primer 143
4.1.1 Creating Arrays 143
4.1.2 Array Indexing 144
4.1.3 Array Computations 146
4.1.4 Type Testing 147
4.1.5 Hidden Temporary Arrays 149
4.1.6 Exercises 150
4.2 Vectorized Algorithms 151
4.2.1 Arrays as Function Arguments 152
4.2.2 Slicing 153
4.2.3 Remark on Efficiency 154
4.2.4 Exercises 156
4.3 More Advanced Array Computing 157
4.3.1 Random Numbers 157
4.3.2 Linear Algebra 159
4.3.3 The Gnuplot Module 159
4.3.4 Example: Curve Fitting 162
4.3.5 Arrays on Structured Grids 164
4.3.6 File I/O with NumPy Arrays 166
4.3.7 Reading and Writing Tables with NumPy Arrays 167
4.3.8 Functionality in the Numpytools Module 170
4.3.9 Exercises 172
4.4 Other Tools for Numerical Computations 176
4.4.1 The ScientificPython Package 176
4.4.2 The SciPy Package 181
4.4.3 The Python--Matlab Interface 185
4.4.4 Some Useful Python Modules 186
4.5 A Database for NumPy Arrays 187
4.5.1 The Structure of the Database 188
4.5.2 Pickling 190
4.5.3 Formatted ASCII Storage 191
4.5.4 Shelving 192
4.5.5 Comparing the Various Techniques 193
5 Combining Python with Fortran, C, and C++ 195
5.1 About Mixed Language Programming 195
5.1.1 Applications of Mixed Language Programming 195
5.1.2 Calling C from Python 196
5.1.3 Automatic Generation of Wrapper Code 198
5.2 Scientific Hello World Examples 200
5.2.1 Combining Python and Fortran 201
5.2.2 Combining Python and C 206
5.2.3 Combining Python and C++ Functions 212
5.2.4 Combining Python and C++ Classes 214
5.2.5 Exercises 217
5.3 A Simple Computational Steering Example 218
5.3.1 Modified Time Loop for Repeated Simulations 219
5.3.2 Creating a Python Interface 220
5.3.3 The Steering Python Script 222
5.3.4 Equipping the Steering Script with a GUI 225
5.4 Scripting Interfaces to Large Libraries 227
6 Introduction to GUI Programming 231
6.1 Scientific Hello World GUI 231
6.1.1 Introductory Topics 231
6.1.2 The First Python/Tkinter Encounter 234
6.1.3 Binding Events 237
6.1.4 Changing the Layout 238
6.1.5 The Final Scientific Hello World GUI 242
6.1.6 An Alternative to Tkinter Variables 244
6.1.7 About the Pack Command 245
6.1.8 An Introduction to the Grid Geometry Manager 247
6.1.9 Implementing a GUI as a Class 249
6.1.10 A Simple Graphical Function Evaluator 251
6.1.11 Exercises 253
6.2 Adding GUIs to Scripts 255
6.2.1 A Simulation and Visualization Script with a GUI 255
6.2.2 Improving the Layout 258
6.2.3 Exercises 261
6.3 A List of Common Widget Operations 262
6.3.1 Frame 265
6.3.2 Label 265
6.3.3 Button 267
6.3.4 Text Entry 267
6.3.5 Balloon Help 269
6.3.6 Option Menu 270
6.3.7 Slider 270
6.3.8 Check Button 271
6.3.9 Making a Simple Megawidget 271
6.3.10 Menu Bar 272
6.3.11 List Data 274
6.3.12 Listbox 275
6.3.13 Radio Button 278
6.3.14 Combo Box 279
6.3.15 Message Box 280
6.3.16 User-Defined Dialogs 282
6.3.17 Color-Picker Dialogs 283
6.3.18 File Selection Dialogs 286
6.3.19 Toplevel 287
6.3.20 Some Other Types of Widgets 288
6.3.21 Adapting Widgets to the User's Resize Actions 289
6.3.22 Customizing Fonts and Colors 291
6.3.23 Widget Overview 293
6.3.24 Exercises 295
7 Web Interfaces and CGI Programming 301
7.1 Introductory CGI Scripts 302
7.1.1 Web Forms and CGI Scripts 302
7.1.2 Generating Forms in CGI Scripts 305
7.1.3 Debugging CGI Scripts 307
7.1.4 Security Issues 309
7.1.5 A General Shell Script Wrapper for CGI Scripts 310
7.2 Making a Web Interface to a Script 312
7.2.1 A Class for Form Parameters 312
7.2.2 Calling Other Programs 315
7.2.3 Running Simulations 316
7.2.4 Getting a CGI Script to Work 317
7.2.5 Using Web Services from Scripts 320
7.2.6 Exercises 322
8 Advanced Python 325
8.1 Miscellaneous Topics 325
8.1.1 Parsing Command-Line Arguments 325
8.1.2 Platform-Dependent Operations 328
8.1.3 Run-Time Generation of Code 329
8.1.4 Exercises 330
8.2 Regular Expressions and Text Processing 331
8.2.1 Motivation 332
8.2.2 Special Characters 335
8.2.3 Regular Expressions for Real Numbers 336
8.2.4 Using Groups to Extract Parts of a Text 340
8.2.5 Extracting Interval Limits 340
8.2.6 Extracting Multiple Matches 345
8.2.7 Splitting Text 349
8.2.8 Pattern-Matching Modifiers 350
8.2.9 Substitution and Backreferences 353
8.2.10 Example: Swapping Arguments in Function Calls 353
8.2.11 A General Substitution Script 357
8.2.12 Debugging Regular Expressions 358
8.2.13 Exercises 360
8.3 Tools for Handling Data in Files 370
8.3.1 Writing and Reading Python Data Structures 370
8.3.2 Pickling Objects 372
8.3.3 Shelving Objects 374
8.3.4 Writing and Reading Zip Archive Files 375
8.3.5 Downloading Internet Files 376
8.3.6 Binary Input/Output 377
8.3.7 Exercises 379
8.4 Scripts Involving Local and Remote Hosts 379
8.4.1 Secure Shell Commands 380
8.4.2 Distributed Simulation and Visualization 381
8.4.3 Client/Server Programming 383
8.4.4 Threads 383
8.5 Classes 385
8.5.1 Class Programming 385
8.5.2 Checking the Class Type 389
8.5.3 Private Data 390
8.5.4 Static Data 390
8.5.5 Special Attributes 391
8.5.6 Special Methods 391
8.5.7 Multiple Inheritance 393
8.5.8 Using a Class as a C-like Structure 393
8.5.9 Attribute Access via String Names 394
8.5.10 Example: Turning String Formulas into Functions 395
8.5.11 Example: Class for Structured Grids 396
8.5.12 New-Style Classes 399
8.5.13 Implementing Get/Set Functions via Properties 399
8.5.14 Subclassing Built-in Types 401
8.5.15 Copy and Assignment 403
8.5.16 Building Class Interfaces at Run Time 406
8.5.17 Building Flexible Class Interfaces 409
8.5.18 Exercises 416
8.6 Scope of Variables 419
8.6.1 Global, Local, and Class Variables 419
8.6.2 Nested Functions 421
8.6.3 Dictionaries of Variables in Namespaces 422
8.7 Exceptions 424
8.7.1 Handling Exceptions 425
8.7.2 Raising Exceptions 426
8.8 Iterators 427
8.8.1 Constructing an Iterator 427
8.8.2 A Pointwise Grid Iterator 429
8.8.3 A Vectorized Grid Iterator 433
8.8.4 Generators 435
8.8.5 Some Aspects of Generic Programming 437
8.9 Investigating Efficiency 441
8.9.1 CPU-Time Measurements 441
8.9.2 Profiling Python Scripts 444
8.9.3 Optimization of Python Code 445
9 Fortran Programming with NumPy Arrays 449
9.1 Problem Definition 449
9.2 Filling an Array in Fortran 452
9.2.1 The Fortran Subroutine 452
9.2.2 Building and Inspecting the Extension Module 453
9.3 Array Storage Issues 455
9.3.1 Generating an Erroneous Interface 455
9.3.2 Array Storage in C and Fortran 457
9.3.3 Input and Output Arrays as Function Arguments 458
9.3.4 F2PY Interface Files 464
9.3.5 Hiding Work Arrays 468
9.4 Increasing Callback Efficiency 469
9.4.1 Callbacks to Vectorized Python Functions 469
9.4.2 Avoiding Callbacks to Python 472
9.4.3 Compiled Inline Callback Functions 473
9.5 Summary 476
9.6 Exercises 476
9.6.1 Exercises 476
10 C and C++ Programming with NumPy Arrays 481
10.1 C Programming with NumPy Arrays 481
10.1.1 Basics of the NumPy C API 482
10.1.2 The Handwritten Extension Code 484
10.1.3 Sending Arguments from Python to C 485
10.1.4 Consistency Checks 486
10.1.5 Computing Array Values 487
10.1.6 Returning an Output Array 489
10.1.7 Convenient Macros 490
10.1.8 Module Initialization 491
10.1.9 Extension Module Template 492
10.1.10 Compiling, Linking, and Debugging the Module 494
10.1.11 Writing a Wrapper for a C Function 495
10.2 C++ Programming with NumPy Arrays 498
10.2.1 Wrapping a NumPy Array in a C++ Object 498
10.2.2 Using SCXX 500
10.2.3 NumPy--C++ Class Conversion 503
10.3 Comparison of the Implementations 512
10.3.1 Efficiency 512
10.3.2 Error Handling 515
10.3.3 Summary 516
10.3.4 Exercises 517
11 More Advanced GUI Programming 523
11.1 Adding Plot Areas in GUIs 523
11.1.1 The BLT Graph Widget 524
11.1.2 Animation of Functions in BLT Graph Widgets 530
11.1.3 Other Tools for Making GUIs with Plots 532
11.1.4 Exercises 534
11.2 Event Bindings 537
11.2.1 Binding Events to Functions with Arguments 537
11.2.2 A Text Widget with Tailored Keyboard Bindings 540
11.2.3 A Fancy List Widget 543
11.3 Animated Graphics with Canvas Widgets 546
11.3.1 The First Canvas Encounter 547
11.3.2 Coordinate Systems 548
11.3.3 The Mathematical Model Class 552
11.3.4 The Planet Class 553
11.3.5 Drawing and Moving Planets 555
11.3.6 Dragging Planets to New Positions 556
11.3.7 Using Pmw's Scrolled Canvas Widget 560
11.4 Tools for Simulation & Visualization Scripts 562
11.4.1 Restructuring the Script 563
11.4.2 Representing a Parameter by a Class 565
11.4.3 Improved Command-Line Script 579
11.4.4 Improved GUI Script 580
11.4.5 Improved CGI Script 581
11.4.6 Parameters with Physical Dimensions 582
11.4.7 Adding a Curve Plot Area 584
11.4.8 Automatic Generation of Scripts 586
11.4.9 Applications of the Tools 587
11.4.10 Allowing Physical Units in Input Files 592
11.4.11 Converting Input Files to GUIs 596
12 Tools and Examples 599
12.1 Running Series of Computer Experiments 599
12.1.1 Multiple Values of Input Parameters 600
12.1.2 Implementation Details 603
12.1.3 Further Applications 608
12.2 Tools for Representing Functions 612
12.2.1 Functions Defined by String Formulas 612
12.2.2 A Unified Interface to Functions 614
12.2.3 Interactive Drawing of Functions 620
12.2.4 A Notebook for Selecting Functions 626
12.3 Solving Partial Differential Equations 632
12.3.1 Numerical Methods for 1D Wave Equations 633
12.3.2 Implementations of 1D Wave Equations 636
12.3.3 Classes for Solving 1D Wave Equations 642
12.3.4 A Problem Solving Environment 649
12.3.5 Numerical Methods for 2D Wave Equations 655
12.3.6 Implementations of 2D Wave Equations 658
A Setting up the Required Software Environment 669
A.1 Installation on Unix Systems 669
A.1.1 A Suggested Directory Structure 670
A.1.2 Setting Some Environment Variables 670
A.1.3 Installing Tcl/Tk and Additional Modules 671
A.1.4 Installing Python 672
A.1.5 Installing Python Modules 674
A.1.6 Installing Gnuplot 678
A.1.7 Installing SWIG 678
A.1.8 Summary of Environment Variables 679
A.1.9 Testing the Installation of Scripting Utilities 679
A.2 Installation on Windows Systems 680
B Elements of Software Engineering 685
B.1 Building and Using Modules 685
B.1.1 Single-File Modules 685
B.1.2 Multi-File Modules 688
B.1.3 Debugging and Troubleshooting 690
B.2 Tools for Documenting Python Software 692
B.2.1 Doc Strings 693
B.2.2 Tools for Automatic Documentation 694
B.3 Coding Standards 698
B.3.1 Style Guide 698
B.3.2 Pythonic Programming 702
B.4 Verification of Scripts 707
B.4.1 Automating Regression Tests 707
B.4.2 Implementing a Tool for Regression Tests 712
B.4.3 Writing a Test Script 715
B.4.4 Verifying Output from Numerical Computations 716
B.4.5 Automatic Doc String Testing 720
B.4.6 Unit Testing 722
B.5 Version Control Management 724
B.5.1 Getting Started with CVS 725
B.5.2 Building Scripts to Simplify the Use of CVS 729
B.6 Exercises 729
1.1 Scripting versus Traditional Programming 21
1.1.1 Why Scripting is Useful in Computational Science 21
1.1.2 Classification of Programming Languages 24
1.1.3 Productive Pairs of Programming Languages 25
1.1.4 Gluing Existing Applications 26
1.1.5 Scripting Yields Shorter Code 27
1.1.6 Efficiency 28
1.1.7 Type-Specification (Declaration) of Variables 29
1.1.8 Flexible Function Interfaces 31
1.1.9 Interactive Computing 32
1.1.10 Creating Code at Run Time 33
1.1.11 Nested Heterogeneous Data Structures 34
1.1.12 GUI Programming 36
1.1.13 Mixed Language Programming 37
1.1.14 When to Choose a Dynamically Typed Language 39
1.1.15 Why Python? 40
1.1.16 Script or Program? 41
1.2 Preparations for Working with This Book 42
2 Getting Started with Python Scripting 47
2.1 A Scientific Hello World Script 47
2.1.1 Executing Python Scripts 48
2.1.2 Dissection of the Scientific Hello World Script 49
2.2 Reading and Writing Data Files 52
2.2.1 Problem Specification 52
2.2.2 The Complete Code 53
2.2.3 Dissection 53
2.2.4 Working with Files in Memory 56
2.2.5 Efficiency Measurements 57
2.2.6 Exercises 58
2.3 Automating Simulation and Visualization 60
2.3.1 The Simulation Code 61
2.3.2 Using Gnuplot to Visualize Curves 63
2.3.3 Functionality of the Script 64
2.3.4 The Complete Code 65
2.3.5 Dissection 67
2.3.6 Exercises 69
2.4 Conducting Numerical Experiments 72
2.4.1 Wrapping a Loop Around Another Script 73
2.4.2 Generating an HTML Report 74
2.4.3 Making Animations 76
2.4.4 Varying Any Parameter 77
2.4.5 Exercises 80
2.5 File Format Conversion 80
2.5.1 The First Version of the Script 81
2.5.2 The Second Version of the Script 82
3 Basic Python 85
3.1 Introductory Topics 85
3.1.1 Recommended Python Documentation 85
3.1.2 Testing Statements in the Interactive Shell 86
3.1.3 Control Statements 88
3.1.4 Running an Application 89
3.1.5 File Reading and Writing 90
3.1.6 Output Formatting 92
3.1.7 Exercises 93
3.2 Variables of Different Types 94
3.2.1 Boolean Types 94
3.2.2 The None Variable 95
3.2.3 Numbers and Numerical Expressions 96
3.2.4 Lists and Tuples 97
3.2.5 Dictionaries 104
3.2.6 Splitting and Joining Text 107
3.2.7 String Operations 108
3.2.8 Text Processing 109
3.2.9 The Basics of a Python Class 111
3.2.10 Determining a Variable's Type 113
3.2.11 Exercises 116
3.3 Functions 121
3.3.1 Keyword Arguments 122
3.3.2 Doc Strings 123
3.3.3 Variable Number of Arguments 123
3.3.4 Call by Reference 124
3.3.5 Treatment of Input and Output Arguments 126
3.3.6 Function Objects 127
3.4 Working with Files and Directories 128
3.4.1 Listing Files in a Directory 129
3.4.2 Testing File Types 129
3.4.3 Copying and Renaming Files 130
3.4.4 Removing Files and Directories 131
3.4.5 Splitting Pathnames 131
3.4.6 Creating and Moving to Directories 132
3.4.7 Traversing Directory Trees 132
3.4.8 Exercises 135
4 Numerical Computing in Python 141
4.1 A Quick NumPy Primer 143
4.1.1 Creating Arrays 143
4.1.2 Array Indexing 144
4.1.3 Array Computations 146
4.1.4 Type Testing 147
4.1.5 Hidden Temporary Arrays 149
4.1.6 Exercises 150
4.2 Vectorized Algorithms 151
4.2.1 Arrays as Function Arguments 152
4.2.2 Slicing 153
4.2.3 Remark on Efficiency 154
4.2.4 Exercises 156
4.3 More Advanced Array Computing 157
4.3.1 Random Numbers 157
4.3.2 Linear Algebra 159
4.3.3 The Gnuplot Module 159
4.3.4 Example: Curve Fitting 162
4.3.5 Arrays on Structured Grids 164
4.3.6 File I/O with NumPy Arrays 166
4.3.7 Reading and Writing Tables with NumPy Arrays 167
4.3.8 Functionality in the Numpytools Module 170
4.3.9 Exercises 172
4.4 Other Tools for Numerical Computations 176
4.4.1 The ScientificPython Package 176
4.4.2 The SciPy Package 181
4.4.3 The Python--Matlab Interface 185
4.4.4 Some Useful Python Modules 186
4.5 A Database for NumPy Arrays 187
4.5.1 The Structure of the Database 188
4.5.2 Pickling 190
4.5.3 Formatted ASCII Storage 191
4.5.4 Shelving 192
4.5.5 Comparing the Various Techniques 193
5 Combining Python with Fortran, C, and C++ 195
5.1 About Mixed Language Programming 195
5.1.1 Applications of Mixed Language Programming 195
5.1.2 Calling C from Python 196
5.1.3 Automatic Generation of Wrapper Code 198
5.2 Scientific Hello World Examples 200
5.2.1 Combining Python and Fortran 201
5.2.2 Combining Python and C 206
5.2.3 Combining Python and C++ Functions 212
5.2.4 Combining Python and C++ Classes 214
5.2.5 Exercises 217
5.3 A Simple Computational Steering Example 218
5.3.1 Modified Time Loop for Repeated Simulations 219
5.3.2 Creating a Python Interface 220
5.3.3 The Steering Python Script 222
5.3.4 Equipping the Steering Script with a GUI 225
5.4 Scripting Interfaces to Large Libraries 227
6 Introduction to GUI Programming 231
6.1 Scientific Hello World GUI 231
6.1.1 Introductory Topics 231
6.1.2 The First Python/Tkinter Encounter 234
6.1.3 Binding Events 237
6.1.4 Changing the Layout 238
6.1.5 The Final Scientific Hello World GUI 242
6.1.6 An Alternative to Tkinter Variables 244
6.1.7 About the Pack Command 245
6.1.8 An Introduction to the Grid Geometry Manager 247
6.1.9 Implementing a GUI as a Class 249
6.1.10 A Simple Graphical Function Evaluator 251
6.1.11 Exercises 253
6.2 Adding GUIs to Scripts 255
6.2.1 A Simulation and Visualization Script with a GUI 255
6.2.2 Improving the Layout 258
6.2.3 Exercises 261
6.3 A List of Common Widget Operations 262
6.3.1 Frame 265
6.3.2 Label 265
6.3.3 Button 267
6.3.4 Text Entry 267
6.3.5 Balloon Help 269
6.3.6 Option Menu 270
6.3.7 Slider 270
6.3.8 Check Button 271
6.3.9 Making a Simple Megawidget 271
6.3.10 Menu Bar 272
6.3.11 List Data 274
6.3.12 Listbox 275
6.3.13 Radio Button 278
6.3.14 Combo Box 279
6.3.15 Message Box 280
6.3.16 User-Defined Dialogs 282
6.3.17 Color-Picker Dialogs 283
6.3.18 File Selection Dialogs 286
6.3.19 Toplevel 287
6.3.20 Some Other Types of Widgets 288
6.3.21 Adapting Widgets to the User's Resize Actions 289
6.3.22 Customizing Fonts and Colors 291
6.3.23 Widget Overview 293
6.3.24 Exercises 295
7 Web Interfaces and CGI Programming 301
7.1 Introductory CGI Scripts 302
7.1.1 Web Forms and CGI Scripts 302
7.1.2 Generating Forms in CGI Scripts 305
7.1.3 Debugging CGI Scripts 307
7.1.4 Security Issues 309
7.1.5 A General Shell Script Wrapper for CGI Scripts 310
7.2 Making a Web Interface to a Script 312
7.2.1 A Class for Form Parameters 312
7.2.2 Calling Other Programs 315
7.2.3 Running Simulations 316
7.2.4 Getting a CGI Script to Work 317
7.2.5 Using Web Services from Scripts 320
7.2.6 Exercises 322
8 Advanced Python 325
8.1 Miscellaneous Topics 325
8.1.1 Parsing Command-Line Arguments 325
8.1.2 Platform-Dependent Operations 328
8.1.3 Run-Time Generation of Code 329
8.1.4 Exercises 330
8.2 Regular Expressions and Text Processing 331
8.2.1 Motivation 332
8.2.2 Special Characters 335
8.2.3 Regular Expressions for Real Numbers 336
8.2.4 Using Groups to Extract Parts of a Text 340
8.2.5 Extracting Interval Limits 340
8.2.6 Extracting Multiple Matches 345
8.2.7 Splitting Text 349
8.2.8 Pattern-Matching Modifiers 350
8.2.9 Substitution and Backreferences 353
8.2.10 Example: Swapping Arguments in Function Calls 353
8.2.11 A General Substitution Script 357
8.2.12 Debugging Regular Expressions 358
8.2.13 Exercises 360
8.3 Tools for Handling Data in Files 370
8.3.1 Writing and Reading Python Data Structures 370
8.3.2 Pickling Objects 372
8.3.3 Shelving Objects 374
8.3.4 Writing and Reading Zip Archive Files 375
8.3.5 Downloading Internet Files 376
8.3.6 Binary Input/Output 377
8.3.7 Exercises 379
8.4 Scripts Involving Local and Remote Hosts 379
8.4.1 Secure Shell Commands 380
8.4.2 Distributed Simulation and Visualization 381
8.4.3 Client/Server Programming 383
8.4.4 Threads 383
8.5 Classes 385
8.5.1 Class Programming 385
8.5.2 Checking the Class Type 389
8.5.3 Private Data 390
8.5.4 Static Data 390
8.5.5 Special Attributes 391
8.5.6 Special Methods 391
8.5.7 Multiple Inheritance 393
8.5.8 Using a Class as a C-like Structure 393
8.5.9 Attribute Access via String Names 394
8.5.10 Example: Turning String Formulas into Functions 395
8.5.11 Example: Class for Structured Grids 396
8.5.12 New-Style Classes 399
8.5.13 Implementing Get/Set Functions via Properties 399
8.5.14 Subclassing Built-in Types 401
8.5.15 Copy and Assignment 403
8.5.16 Building Class Interfaces at Run Time 406
8.5.17 Building Flexible Class Interfaces 409
8.5.18 Exercises 416
8.6 Scope of Variables 419
8.6.1 Global, Local, and Class Variables 419
8.6.2 Nested Functions 421
8.6.3 Dictionaries of Variables in Namespaces 422
8.7 Exceptions 424
8.7.1 Handling Exceptions 425
8.7.2 Raising Exceptions 426
8.8 Iterators 427
8.8.1 Constructing an Iterator 427
8.8.2 A Pointwise Grid Iterator 429
8.8.3 A Vectorized Grid Iterator 433
8.8.4 Generators 435
8.8.5 Some Aspects of Generic Programming 437
8.9 Investigating Efficiency 441
8.9.1 CPU-Time Measurements 441
8.9.2 Profiling Python Scripts 444
8.9.3 Optimization of Python Code 445
9 Fortran Programming with NumPy Arrays 449
9.1 Problem Definition 449
9.2 Filling an Array in Fortran 452
9.2.1 The Fortran Subroutine 452
9.2.2 Building and Inspecting the Extension Module 453
9.3 Array Storage Issues 455
9.3.1 Generating an Erroneous Interface 455
9.3.2 Array Storage in C and Fortran 457
9.3.3 Input and Output Arrays as Function Arguments 458
9.3.4 F2PY Interface Files 464
9.3.5 Hiding Work Arrays 468
9.4 Increasing Callback Efficiency 469
9.4.1 Callbacks to Vectorized Python Functions 469
9.4.2 Avoiding Callbacks to Python 472
9.4.3 Compiled Inline Callback Functions 473
9.5 Summary 476
9.6 Exercises 476
9.6.1 Exercises 476
10 C and C++ Programming with NumPy Arrays 481
10.1 C Programming with NumPy Arrays 481
10.1.1 Basics of the NumPy C API 482
10.1.2 The Handwritten Extension Code 484
10.1.3 Sending Arguments from Python to C 485
10.1.4 Consistency Checks 486
10.1.5 Computing Array Values 487
10.1.6 Returning an Output Array 489
10.1.7 Convenient Macros 490
10.1.8 Module Initialization 491
10.1.9 Extension Module Template 492
10.1.10 Compiling, Linking, and Debugging the Module 494
10.1.11 Writing a Wrapper for a C Function 495
10.2 C++ Programming with NumPy Arrays 498
10.2.1 Wrapping a NumPy Array in a C++ Object 498
10.2.2 Using SCXX 500
10.2.3 NumPy--C++ Class Conversion 503
10.3 Comparison of the Implementations 512
10.3.1 Efficiency 512
10.3.2 Error Handling 515
10.3.3 Summary 516
10.3.4 Exercises 517
11 More Advanced GUI Programming 523
11.1 Adding Plot Areas in GUIs 523
11.1.1 The BLT Graph Widget 524
11.1.2 Animation of Functions in BLT Graph Widgets 530
11.1.3 Other Tools for Making GUIs with Plots 532
11.1.4 Exercises 534
11.2 Event Bindings 537
11.2.1 Binding Events to Functions with Arguments 537
11.2.2 A Text Widget with Tailored Keyboard Bindings 540
11.2.3 A Fancy List Widget 543
11.3 Animated Graphics with Canvas Widgets 546
11.3.1 The First Canvas Encounter 547
11.3.2 Coordinate Systems 548
11.3.3 The Mathematical Model Class 552
11.3.4 The Planet Class 553
11.3.5 Drawing and Moving Planets 555
11.3.6 Dragging Planets to New Positions 556
11.3.7 Using Pmw's Scrolled Canvas Widget 560
11.4 Tools for Simulation & Visualization Scripts 562
11.4.1 Restructuring the Script 563
11.4.2 Representing a Parameter by a Class 565
11.4.3 Improved Command-Line Script 579
11.4.4 Improved GUI Script 580
11.4.5 Improved CGI Script 581
11.4.6 Parameters with Physical Dimensions 582
11.4.7 Adding a Curve Plot Area 584
11.4.8 Automatic Generation of Scripts 586
11.4.9 Applications of the Tools 587
11.4.10 Allowing Physical Units in Input Files 592
11.4.11 Converting Input Files to GUIs 596
12 Tools and Examples 599
12.1 Running Series of Computer Experiments 599
12.1.1 Multiple Values of Input Parameters 600
12.1.2 Implementation Details 603
12.1.3 Further Applications 608
12.2 Tools for Representing Functions 612
12.2.1 Functions Defined by String Formulas 612
12.2.2 A Unified Interface to Functions 614
12.2.3 Interactive Drawing of Functions 620
12.2.4 A Notebook for Selecting Functions 626
12.3 Solving Partial Differential Equations 632
12.3.1 Numerical Methods for 1D Wave Equations 633
12.3.2 Implementations of 1D Wave Equations 636
12.3.3 Classes for Solving 1D Wave Equations 642
12.3.4 A Problem Solving Environment 649
12.3.5 Numerical Methods for 2D Wave Equations 655
12.3.6 Implementations of 2D Wave Equations 658
A Setting up the Required Software Environment 669
A.1 Installation on Unix Systems 669
A.1.1 A Suggested Directory Structure 670
A.1.2 Setting Some Environment Variables 670
A.1.3 Installing Tcl/Tk and Additional Modules 671
A.1.4 Installing Python 672
A.1.5 Installing Python Modules 674
A.1.6 Installing Gnuplot 678
A.1.7 Installing SWIG 678
A.1.8 Summary of Environment Variables 679
A.1.9 Testing the Installation of Scripting Utilities 679
A.2 Installation on Windows Systems 680
B Elements of Software Engineering 685
B.1 Building and Using Modules 685
B.1.1 Single-File Modules 685
B.1.2 Multi-File Modules 688
B.1.3 Debugging and Troubleshooting 690
B.2 Tools for Documenting Python Software 692
B.2.1 Doc Strings 693
B.2.2 Tools for Automatic Documentation 694
B.3 Coding Standards 698
B.3.1 Style Guide 698
B.3.2 Pythonic Programming 702
B.4 Verification of Scripts 707
B.4.1 Automating Regression Tests 707
B.4.2 Implementing a Tool for Regression Tests 712
B.4.3 Writing a Test Script 715
B.4.4 Verifying Output from Numerical Computations 716
B.4.5 Automatic Doc String Testing 720
B.4.6 Unit Testing 722
B.5 Version Control Management 724
B.5.1 Getting Started with CVS 725
B.5.2 Building Scripts to Simplify the Use of CVS 729
B.6 Exercises 729
Alternative description
The primary purpose of this book is to help scientists and engineers work ing intensively with computers to become more productive, have more fun, and increase the reliability of their investigations. Scripting in the Python programming language can be a key tool for reaching these goals [27,29]. The term scripting means different things to different people. By scripting I mean developing programs of an administering nature, mostly to organize your work, using languages where the abstraction level is higher and program ming is more convenient than in Fortran, C, C++, or Java. Perl, Python, Ruby, Scheme, and Tel are examples of languages supporting such high-level programming or scripting. To some extent Matlab and similar scientific com puting environments also fall into this category, but these environments are mainly used for computing and visualization with built-in tools, while script ing aims at gluing a range of different tools for computing, visualization, data analysis, file/directory management, user interfaces, and Internet communi cation. So, although Matlab is perhaps the scripting language of choiee in computational science today, my use of the term scripting goes beyond typi cal Matlab scripts. Python stands out as the language of choice for scripting in computational science because of its very elean syntax, rieh modulariza tion features, good support for numerical computing, and rapidly growing popularity. What Scripting is About.
Alternative description
Numerous readers of the second edition have noti?ed me about misprints and possible improvements of the text and the associated computer codes. The resulting modi?cations have been incorporated in this new edition and its accompanying software. The major change between the second and third editions, however, is caused by the new implementation of Numerical Python, now called numpy. The new numpy package encourages a slightly di?erent syntax compared to the old Numeric implementation, which was used in the previous editions. Since Numerical Python functionality appears in a lot of places in the book, there are hence a huge number of updates to the new suggested numpy syntax, especially in Chapters 4, 9, and 10. The second edition was based on Python version 2.3, while the third edition contains updates for version 2.5. Recent Python features, such as generator expressions (Chapter 8.9.4), Ctypes for interfacing shared libraries in C (Chapter 5.2.2), the with statement (Chapter 3.1.4), and the subprocess module for running external processes (Chapter 3.1.3) have been exempli?ed to make the reader aware of new tools. Chapter 4.4.4 is new and gives a taste of symbolic mathematics in Python.
Erscheinungsdatum: 11.12.2007
Erscheinungsdatum: 11.12.2007
Alternative description
With a primary focus on examples and applications of relevance to computational scientists, this brilliantly useful book shows computational scientists how to develop tailored, flexible, and human-efficient working environments built from small scripts written in the easy-to-learn, high-level Python language. All the tools and examples in this book are open source codes. This third edition features lots of new material. It is also released after a comprehensive reorganization of the text. The author has inserted improved examples and tools and updated information, as well as correcting any errors that crept in to the first imprint.
Review From the reviews of the second edition: "This book addresses primarily a CSE (computational science and engineering) audience. ... gives a clear and detailed account on the ways in which the surprisingly powerful Python language may aid the CSE community." (H. Muthsam, Monatshefte für Mathematik, Vol. 151 (4), 2007)
Review From the reviews of the second edition: "This book addresses primarily a CSE (computational science and engineering) audience. ... gives a clear and detailed account on the ways in which the surprisingly powerful Python language may aid the CSE community." (H. Muthsam, Monatshefte für Mathematik, Vol. 151 (4), 2007)
Alternative description
"The goal of this book is to teach computational scientists how to develop tailored, flexible, and human-efficient working environments built from small programs (scripts) written in the easy-to-learn, high-level language Python. The focus is on examples and applications of relevance to computational scientists: gluing existing applications and tools, e.g. for automating simulation, data analysis, and visualization; steering simulations and computational experiments; equipping old programs with graphical user interfaces; making computational Web applications; and creating interactive interfaces with a Maple/Matlab-like syntax to numerical applications in C/C++ or Fortran. All the tools and examples in this book are open source codes. The third edition is compatible with the new NumPy implementation and features updated information, correction of errors, and improved associated software tools."--Jacket
date open sourced
2009-07-20
🚀 Fast downloads
Become a member to support the long-term preservation of books, papers, and more. To show our gratitude for your support, you get fast downloads. ❤️
- Fast Partner Server #1 (recommended)
- Fast Partner Server #2 (recommended)
- Fast Partner Server #3 (recommended)
- Fast Partner Server #4 (recommended)
- Fast Partner Server #5 (recommended)
- Fast Partner Server #6 (recommended)
- Fast Partner Server #7
- Fast Partner Server #8
- Fast Partner Server #9
- Fast Partner Server #10
- Fast Partner Server #11
🐢 Slow downloads
From trusted partners. More information in the FAQ. (might require browser verification — unlimited downloads!)
- Slow Partner Server #1 (slightly faster but with waitlist)
- Slow Partner Server #2 (slightly faster but with waitlist)
- Slow Partner Server #3 (slightly faster but with waitlist)
- Slow Partner Server #4 (slightly faster but with waitlist)
- Slow Partner Server #5 (no waitlist, but can be very slow)
- Slow Partner Server #6 (no waitlist, but can be very slow)
- Slow Partner Server #7 (no waitlist, but can be very slow)
- Slow Partner Server #8 (no waitlist, but can be very slow)
- After downloading: Open in our viewer
All download options have the same file, and should be safe to use. That said, always be cautious when downloading files from the internet, especially from sites external to Anna’s Archive. For example, be sure to keep your devices updated.
External downloads
-
For large files, we recommend using a download manager to prevent interruptions.
Recommended download managers: Motrix -
You will need an ebook or PDF reader to open the file, depending on the file format.
Recommended ebook readers: Anna’s Archive online viewer, ReadEra, and Calibre -
Use online tools to convert between formats.
Recommended conversion tools: CloudConvert and PrintFriendly -
You can send both PDF and EPUB files to your Kindle or Kobo eReader.
Recommended tools: Amazon‘s “Send to Kindle” and djazz‘s “Send to Kobo/Kindle” -
Support authors and libraries
✍️ If you like this and can afford it, consider buying the original, or supporting the authors directly.
📚 If this is available at your local library, consider borrowing it for free there.
Total downloads:
A “file MD5” is a hash that gets computed from the file contents, and is reasonably unique based on that content. All shadow libraries that we have indexed on here primarily use MD5s to identify files.
A file might appear in multiple shadow libraries. For information about the various datasets that we have compiled, see the Datasets page.
For information about this particular file, check out its JSON file. Live/debug JSON version. Live/debug page.