TAILIEUCHUNG - Dive Into Python-Chapter 4. The Power Of Introspection

Tham khảo tài liệu 'dive into python-chapter 4. the power of introspection', 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 4. The Power Of Introspection This chapter covers one of Python s strengths introspection. As you know everything in Python is an object and introspection is code looking at other modules and functions in memory as objects getting information about them and manipulating them. Along the way you ll define functions with no name call functions with arguments out of order and reference functions whose names you don t even know ahead of time. . Diving In Here is a complete working Python program. You should understand a good deal about it just by looking at it. The numbered lines illustrate concepts covered in Chapter 2 Your First Python Program. Don t worry if the rest of the code looks intimidating you ll learn all about it throughout this chapter. Example . If you have not already done so you can download this and other examples used in this book. def info object spacing 10 collapse 1 O Print methods and doc strings. Takes module class list dictionary or string. methodList method for method in dir object if callable getattr object method processFunc collapse and lambda s .join or lambda s s print n .join s s spacing processFunc str getattr object method .__doc__ for method in methodList if __name main print O O This module has one function info. According to its function declaration it takes three parameters obj ect spacing and collapse. The last two are actually optional parameters as you ll see shortly. e The info function has a multi-line doc string that succinctly describes the function s purpose. Note that no return value is mentioned this function will be used solely for its effects rather than its value. Code within the function is indented. The i f _name__trick allows this program do something useful when run by itself without interfering with its use as a module for other programs. In this case the program simply prints out the doc string of the info function. 0 if statements use for .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.