English-012 DiveIntoPython

本文深入探讨Python编程中的关键概念,包括异常处理、文件操作、循环结构及模块使用等。通过具体实例,展示了如何利用这些特性来增强程序的健壮性和灵活性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

English-012 DiveIntoPython

1.You're already intimately familiar with repr and you don't even know it.
intimately adv. 亲切地;熟悉地;私下地 intimate ['intimət] adj. 亲密的;私人的;精通的;[婉]有性关系的

2.gotcha ['ɡɔtʃə] [发音拼写] =(I have) got you [常用作插入语]

3.tagDataMap is a class attribute: literally, an attribute of the class. It is available before creating any instances of the class.
literally ['litərəli] adv. 逐字地;照字面地

4.If the name of a Python function, class method, or attribute starts with (but doesn't end with) two underscores, it's private; everything else is public. Python has no concept of protected class methods (accessible only in their own class and descendant classes). Class methods are either private (accessible only in their own class) or public (accessible from anywhere).
underscore vt. 强调;划线于…下 n. 底线,下划线
either or 二者择一的;要么…要么…

5.If you try to call a private method, Python will raise a slightly misleading exception, saying that the method does not exist.
slight [slait] adj. 轻微的,少量的;脆弱的;细长的;不重要
misleading [,mis'li:diŋ] adj. 令人误解的;引入歧途的

6.internally, the names of private methods and attributes are mangled and unmangled on the fly to make them seem inaccessible by their given names.
mangle ['mæŋɡl] vt. 乱砍;轧布;损坏

7.but like many other things in Python, their privateness is ultimately a matter of convention, not force.
ultimately adv. 最后;根本;基本上
ultimate ['ʌltimət] adj. 最终的;根本的;极限的

8.That's it for the hard-core object trickery. You'll see a real-world application of special class methods in Chapter 12, which uses getattr to create a proxy to a remote web service.
trickery ['trikəri] n. 欺骗;奸计;诡计
real-world adj. 现实生活的;工作的

9.In this chapter, you will dive into exceptions, file objects, for loops, and the os and sys modules. If you've used exceptions in another programming language, you can skim the first section to get a sense of Python's syntax. Be sure to tune in again for file handling.
skim [skim] vi. 掠过;浏览
section ['sekʃən] n. 章节;地区;截面;部门
tune [tju:n, tu:n] vt. 调整;为…调音;使一致 tune in 收听;调谐;使…协调

10.An error occurred, the exception was printed (depending on your IDE, perhaps in an intentionally jarring shade of red).
jarring ['dʒɑ:riŋ] adj. 刺耳的;不和谐的;辗轧

11.When the exception was raised, there was no code to explicitly notice it and deal with it, so it bubbled its way back to the default behavior built in to Python, which is to spit out some debugging information and give up. In the IDE, that's no big deal, but if that happened while your actual Python program was running, the entire program would come to a screeching halt.
bubble ['bʌbl] vt. 使冒泡;滔滔不绝地说 vi. 沸腾,冒泡;发出气泡声
spit [spit] vt. 吐,吐出;发出;发射 spit out 吐出
screeching ['skri:tʃiŋ] n. 发动机啸声;尖叫
halt [hɔ:lt] vi. 停止;踌躇,犹豫;立定 n. 停止;立定;休息

12.Sometimes an exception is really because you have a bug in your code (like accessing a variable that doesn't exist), but many times, an exception is something you can anticipate.
anticipate [æn'tisipeit] vt. 预期,期望;占先,抢先;提前使用

13.If you're connecting to a database, it might be unavailable, or you might not have the correct security credentials to access it.
credential [kri'denʃəl] n. 国书,凭据,印信

14.When the open method raises an IOError exception, you're ready for it. The except IOError: line catches the exception and executes your own block of code, which in this case just prints a more pleasant error message.
pleasant ['plezənt] adj. 令人愉快的,舒适的;讨人喜欢的,和蔼可亲的

15.I'm sure you've experienced this, and you know it's not fun.

16.The next example demonstrates how to use an exception to support platform-specific functionality. This code comes from the getpass module, a wrapper module for getting a password from the user. Getting a password is accomplished differently on UNIX, Windows, and Mac OS platforms, but this code encapsulates all of those differences.
demonstrate ['demənstreit] vt. 证明;论证;展示
accomplished [ə'kʌmpliʃt] adj. 熟练的,有技巧的;完成的;有修养的;有学问的
encapsulate [in'kæpsəleit] vt. 压缩;将…装入胶囊;将…封进内部

17.Open files consume system resources, and depending on the file mode, other programs may not be able to access them. It's important to close files as soon as you're finished with them.
consume [kən'sju:m] vt. 消耗,消费;使…著迷;挥霍

18.Just because a file is closed doesn't mean that the file object ceases to exist.
cease [si:s] vi. 停止;终了 vt. 停止;结束

19.file is a synonym for open. This one-liner opens the file, reads its contents, and prints them.
synonym ['sinənim] n. 同义词

20.It's amazing how often you use for loops in other languages when all you really want is a join or a list comprehension.

21.Don't ever do this. This is Visual Basic-style thinking. Break out of it. Just iterate through the list, as shown in the previous example.
ever ['evə] adv. 曾经;究竟;永远

22.The sys module contains system-level information, such as the version of Python you're running (sys.version or sys.version_info), and system-level options such as the maximum allowed recursion depth (sys.getrecursionlimit() and sys.setrecursionlimit()).
maximum ['mæksiməm] n. 极大,最大限度;最大量
recursion [ri'kə:ʃən] 循环,递归

23.You'll plow through this line later, after you dive into the os module.
plow [plau] vi. 犁;耕地;破浪前进;开路

24.Iterating through the list with f, you use os.path.normcase(f) to normalize the case according to operating system defaults. normcase is a useful little function that compensates for case-insensitive operating systems that think that mahadeva.mp3 and mahadeva.MP3 are the same file.
normalize ['nɔ:məlaiz] vt. 使规格化,使标准化;使正常化
compensate ['kɔmpenseit] vi. 补偿,赔偿;抵消
case-insensitive: 区分大小写;大小写不敏感;区分大小

25.The glob module, on the other hand, takes a wildcard and returns the full path of all files and directories matching the wildcard. Here the wildcard is a directory path plus "*.mp3", which will match all .mp3 files. Note that each element of the returned list already includes the full path of the file.
wildcard n. [计]通配符

26.Now consider this scenario: you have a music directory, with several subdirectories within it, with .mp3 files within each subdirectory. You can get a list of all of those with a single call to glob, by using two wildcards at once. One wildcard is the "*.mp3" (to match .mp3 files), and one wildcard is within the directory path itself, to match any subdirectory within c:\music.
scenario [si'nɑ:riəu, -'næ-, -'nεə-] n. 情节;剧本;方案

27.The nested function getFileInfoClass can be called only from the function in which it is defined, listDirectory. As with any other function, you don't need an interface declaration or anything fancy; just define the function and code it.
fancy ['fænsi] n.幻想;爱好

28.which classes are defined that could potentially handle those files.
potential [pəu'tenʃəl] adj. 可能的;潜在的

29. It inspects the directory for the files to process, and then introspects its own module to see what special handler classes (like MP3FileInfo) are defined.
inspect [in'spekt] vt. 检查;视察;检阅

30.listDirectory will handle them all, without modification, by handing off the real work to the appropriate classes and collating the results.
collate [kɔ'leit] vt. 核对,校对;校勘
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值