TAILIEUCHUNG - Dive Into Python-Chapter 5. Objects and Object-Orientation

Tham khảo tài liệu 'dive into python-chapter 5. objects and object-orientation', 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 5. Objects and Object-Orientation This chapter and pretty much every chapter after this deals with object-oriented Python programming. . Diving In Here is a complete working Python program. Read the doc strings of the module the classes and the functions to get an overview of what this program does and how it works. As usual don t worry about the stuff you don t understand that s what the rest of the chapter is for. Example . fileinfo .py If you have not already done so you can download this and other examples used in this book. Framework for getting filetype-specific metadata. Instantiate appropriate class with filename. Returned object acts like a dictionary with key-value pairs for each piece of metadata. import fileinfo info music ap print n .join s s k v for k v in Or use listDirectory function to get info on all files in a directory. for info in music ap .mp3 Framework can be extended by adding classes for particular file types . HTMLFileInfo MPGFileInfo DOCFileInfo. Each class is completely responsible for parsing its files appropriately see MP3FileInfo for example. import os import sys from UserDict import UserDict def stripnulls data strip whitespace and nulls return 00 .strip class FileInfo UserDict store file metadata def __init self filename None self self name filename class MP3FileInfo FileInfo store MP3 tags tagDataMap title 3 33 stripnulls artist 33 63 stripnulls album 63 93 stripnulls year 93 97 stripnulls comment 97 126 stripnulls genre 127 128 ord def __parse self filename parse tags from MP3 file try fsock open filename rb 0 try -128 2 tagdata 128 finally if tagdata 3 TAG for tag start end parseFunc in self tag parseFunc tagdata start end except lOError pass def __setitem self key item if key name and item item .

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.