Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'dive into python-chapter 2. your first python', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Chapter 2. Your First Python Program You know how other books go on and on about programming fundamentals and finally work up to building a complete working program Let s skip all that. 2.1. Diving in Here is a complete working Python program. It probably makes absolutely no sense to you. Don t worry about that because you re going to dissect it line by line. But read through it first and see what if anything you can make of it. Example 2.1. odbchelper.py If you have not already done so you can download this and other examples used in this book. def buildConnectionString params Build a connection string from a dictionary of parameters. Returns string. return .join s s k v for k v in params.items if __name main__ myParams server mpilgrim database master uid sa pwd secret print buildConnectionString myParams Now run this program and see what happens. i In the ActivePython IDE on Windows you can run the Python program you re editing by choosing File- Run. Ctrl-R . Output is displayed in the interactive window. In the Python IDE on Mac OS you can run a Python program with Python- Run window. Cmd-R but there is an important option you must set first. Open the .py file in the IDE pop up the options menu by clicking the black triangle in the upper-right corner of the window and make sure the Run asmainoption is checked. This is a per-file setting but you ll only need to do it once per file. i On UNIX-compatible systems including Mac OS X you can run a Python program from the command line python odbchelper. py The output of odbchelper.py will look like this server mpilgrim uid sa database master pwd secret 2.2. Declaring Functions Python has functions like most other languages but it does not have separate header files like C or interface implementation sections like Pascal. When you need a function just declare it like this def buildConnectionString params Note that the keyword de f starts the function declaration followed by the function name followed by .