Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
(BQ) Part 2 book "Texts in computational science and engineering" has contents: Advanced python, fortran programming with NumPy arrays; C and C++ programming with NumPy arrays; more advanced GUI programming, tools and examples. | Chapter 8 Advanced Python This chapter extends the overview of Python functionality in Chapter 3. Miscellaneous topics like modules for parsing command-line arguments and how to generate Python code at run time are discussed in Chapter 8.1. The comprehensive Chapter 8.2 is devoted to regular expressions for interpreting and editing text. Lots of tools for storing and retrieving data in files are covered in Chapter 8.3, while Chapter 8.4 explores compact file storage of numerical data represented as NumPy arrays. Chapter 8.5 outlines methods for working with a local and a remote host when doing tasks like simulation and visualization. Chapter 8.6 treats numerous topics related to class programming. Chapter 8.7 discusses scope of variables. Error handling via exceptions is described in Chapter 8.8. Extending for loops to iterate over user-defined data structures via Python iterators is the subject of Chapter 8.9. Finally, in Chapter 8.10 we present methods for investigating the efficiency of a script and provide some advice on optimizing Python codes. Readers who are interested in more advanced Python material are highly recommended to read the “Python Cookbook” [23]. 8.1 Miscellaneous Topics This subchapter describes various useful modules and constructs of wide applications in Python scripts. Parsing command-line arguments is a frequently encountered task in scripting, and the process can be automated using two modules presented in Chapter 8.1.1. Although most operations in Python scripts have a uniform syntax independent of the underlying operating system, some operations demand platform-specific hooks. Chapter 8.1.2 explains how this can be done. A nice feature of Python and other dynamically typed languages is the possibility to build code at run time based on user input. Chapter 8.1.3 gives a quick intro to this topic. 8.1.1 Parsing Command-Line Arguments In Chapter 2.3 we demonstrate simple manual parsing of command-line arguments. However, the recommended .