`
sillycat
  • 浏览: 2486908 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

English-013 DiveIntoPython

阅读更多
English-013 DiveIntoPython

1. regular expression   正则表达式;正规表达式  regular ['reɡjulə]  adj. 整齐的;定期的;有规律的;合格的

2.But if you find yourself using a lot of different string functions with if statements to handle special cases, or if you're combining them with split and join and list comprehensions in weird unreadable ways, you may need to move up to regular expressions.
combine [kəm'bain]  vt. 使联合,使结合;使化合
weird [wiəd]    adj. 怪异的;不可思议的;超自然的

3.Although the regular expression syntax is tight and unlike normal code, the result can end up being more readable than a hand-rolled solution that uses a long chain of string functions. There are even ways of embedding comments within regular expressions to make them practically self-documenting.

4.This series of examples was inspired by a real-life problem I had in my day job several years ago, when I needed to scrub and standardize street addresses exported from a legacy system before importing them into a newer system.
series ['siəri:z, -riz]   n. 系列,连续;丛书;[电]串联;[数]级数
inspired [in'spaiəd]  adj. 有灵感的;官方授意的
scrub [skrʌb] vt. 用力擦洗;使净化
standardize ['stændədaiz]  vt. 使标准化;用标准检验
legacy ['leɡəsi]  n. 遗赠,遗产

5.My goal is to standardize a street address so that 'ROAD' is always abbreviated as 'RD.'. At first glance, I thought this was simple enough that I could just use the string method replace. After all, all the data was already uppercase, so case mismatches would not be a problem. And the search string, 'ROAD', was a constant. And in this deceptively simple example, s.replace does indeed work.
abbreviated [ə'bri:vi,eitid]  adj. 小型的;简短的;服装超短的  v. 缩写;节略(abbreviate的过去分词
deceptive [di'septiv]   adj. 迷惑的;欺诈的;虚伪的
indeed [in'di:d]  adv. 真正地;的确;甚至;实在  int. 真的(表示惊讶、怀疑、讽刺等

6.Life, unfortunately, is full of counterexamples, and I quickly discovered this one.
counterexample ['kauntəriɡ'zɑ:mpl]  n. 反例

7.What I really wanted was to match 'ROAD' when it was at the end of the string and it was its own whole word, not a part of some larger word. To express this in a regular expression, you use \b, which means “a word boundary must occur right here”.
boundary ['baundəri]  n. 分界线;边界;范围

8.In Python, this is complicated by the fact that the '\' character in a string must itself be escaped. This is sometimes referred to as the backslash plague, and it is one reason why regular expressions are easier in Perl than in Python.
plague [pleiɡ] n. 瘟疫;灾祸;麻烦;讨厌的人

9.Then it has the new part, in parentheses, which defines a set of three mutually exclusive patterns, separated by vertical bars: CM, CD, and D?C?C?C? (which is an optional D followed by zero to three optional C characters). The regular expression parser checks for each of these patterns in order (from left to right), takes the first one that matches, and ignores the rest.
mutually ['mju:tʃuəli, -tjuəli] adv. 互相地;互助
exclusive [ik'sklu:siv]   adj.专一的;独有的

10.So far you've just been dealing with what I'll call “compact” regular expressions. As you've seen, they are difficult to read, and even if you figure out what one does, that's no guarantee that you'll be able to understand it six months later. What you really need is inline documentation.
compact [kəm'pækt, 'kɔmpækt]  adj. 紧凑的,紧密的;简洁的
verbose [və:'bəus]  adj. 冗长的;啰嗦的  verbose regular expression

11.This example came from another real-world problem I encountered, again from a previous day job.
encounter [in'kauntə] vt. 遭遇,邂逅;遇到

12.I scoured the Web and found many examples of regular expressions that purported to do this, but none of them were permissive enough.
scour ['skauə]  vt. 擦亮,洗涤;冲洗,清除
purport ['pə:pət, -pɔ:t]  vt. 声称;意指;意图;打算
permissive [pə'misiv]   adj. 许可的;宽容的;(两性关系)放纵的;自由的

13.\D+. What the heck is that? Well, \D matches any character except a numeric digit, and + means “1 or more”. So \D+ matches one or more characters that are not digits.
heck [hek]   int. 真见鬼(hell的委婉说法)

14.Using \D+ instead of - means you can now match phone numbers where the parts are separated by spaces instead of hyphens.
hyphen ['haifən]  n. 连字号

15.I hate to be the bearer of bad news, but you're not finished yet.
bearer ['bεərə]  n. [建]承木;托架;持票人;送信人;搬运工人

16.This is where regular expressions make me want to gouge my eyes out with a blunt object.
gouge [ɡaudʒ]  vt. 用半圆凿子挖;欺骗
blunt [blʌnt]  adj. 钝的,不锋利的;生硬的;直率的

17.it's not obvious how any of these class methods ever get called. Don't worry, all will be revealed in due time.
obvious ['ɔbviəs] adj. 明显的;显著的;平淡无奇的
reveal [ri'vi:l]   vt. 揭露;显示;透露;泄露   n. 揭露;暴露;门侧,窗侧
due [dju:, du:]   adj. 到期的;应得的;应付的;预期的

18.HTML processing is broken into three steps: breaking down the HTML into its constituent pieces, fiddling with the pieces, and reconstructing the pieces into HTML again. The first step is done by sgmllib.py, a part of the standard Python library.
constituent [kən'stitjuənt]   adj. 构成的;选举的
fiddle ['fidl]  vi. 瞎搞;拉小提琴

19.An escaped character referenced by its decimal or hexadecimal equivalent, like  . When found, SGMLParser calls handle_charref with the text of the decimal or hexadecimal character equivalent.
decimal ['desiməl]  adj. 小数的;十进位的
hexadecimal [heksə'desim(ə)l]  十六进制,十六进制的
equivalent [i'kwivələnt]  adj. 等价的,相等的;同意义的 n. 等价物,相等物

20.The urllib module is part of the standard Python library. It contains functions for getting information about and actually retrieving data from Internet-based URLs (mainly web pages).
retrieve [ri'tri:v]  vt.检索;恢复 vi. 找回猎物

21.Let's digress from HTML processing for a minute and talk about how Python handles variables.
digress [dai'ɡres]  vi. 离题;走向岔道

22.Are you confused yet? Don't despair! This is really cool, I promise.

23.Just so you don't get intimidated, remember that you've seen all this before.
intimidate [in'timideit]  vt. 恐吓,威胁;胁迫
intimidated  adj. 害怕的;受到恐吓的

24.Contrast this with htmlentitydefs, which was imported using import. That means that the htmlentitydefs module itself is in the namespace, but the entitydefs variable defined within htmlentitydefs is not.
contrast [kən'trɑ:st, -'træst, 'kɔntrɑ:st, -træst]  vi. 对比;形成对照 vt. 使对比;使与…对照

25.There is one other important difference between the locals and globals functions, which you should learn now before it bites you. It will bite you anyway, but at least then you'll remember learning it.

26.Since foo is called with 3, this will print {'arg': 3, 'x': 1}. This should not be a surprise.

分享到:
评论

相关推荐

    Dive into python (英文)

    Dive into python, English version

    Test-Driven Development with Python [2017]

    Dive into the TDD workflow, including the unit test/code cycle and refactoring Use unit tests for classes and functions, and functional tests for user interactions within the browser Learn when and ...

    MQTT Essentials - A Lightweight IoT Protocol

    Dive deep into one of IoT's extremely lightweight machines to enable connectivity protocol with some real-world examples Learn to take advantage of the features included in MQTT for IoT and Machine-to...

    Large Scale Machine Learning with Python

    Dive into scalable machine learning and the three forms of scalability. Speed up algorithms that can be used on a desktop computer with tips on parallelization and memory allocation. Get to grips with...

    Python Data Analysis Cookbook

    In this book, you will dive deeper into recipes on spectral analysis, smoothing, and bootstrapping methods. Moving on, you will learn to rank stocks and check market efficiency, then work with metrics...

    Python Deep Learning

    Whether you want to dive deeper into Deep Learning, or want to investigate how to get more out of this powerful technology, you’ll find everything inside. What you will learn Get a practical deep ...

    LargeScaleMachineLearningwithPython.pdf

    Large Scale Machine Learning with Python [PDF + EPUB + CODE] Packt Publishing | August 4, 2016 | English | 439 pages Large Python machine learning projects involve new problems associated with ...

    Hands-On Machine Learning with Scikit-Learn and TensorFlow [EPUB]

    decision trees, random forests, and ensemble methods Use the TensorFlow library to build and train neural nets Dive into neural net architectures, including convolutional nets, recurrent nets, and ...

    Hands-On Machine Learning with Scikit-Learn and TensorFlow [Kindle Edition]

    Dive into neural net architectures, including convolutional nets, recurrent nets, and deep reinforcement learning Learn techniques for training and scaling deep neural nets Apply practical code ...

    Machine.Learning.in.Python

    The chapters on penalized linear regression and ensemble methods dive deep into each of the algorithms, and you can use the sample code in the book to develop your own data analysis solutions. ...

    Machine Learning in Python 无水印pdf 0分

    The chapters on penalized linear regression and ensemble methods dive deep into each of the algorithms, and you can use the sample code in the book to develop your own data analysis solutions....

    Python Machine Learning By Example [2017].azw3电子书下载

    Dive deep into the world of analytics to predict situations correctly Implement machine learning classification and regression algorithms from scratch in Python Be amazed to see the algorithms in ...

    Advanced Analytics with Spark: Patterns for Learning from Data at Scale

    You’ll start with an introduction to Spark and its ecosystem, and then dive into patterns that apply common techniques—including classification, clustering, collaborative filtering, and anomaly ...

    Building Recommendation Engines

    Dive into the various techniques of recommender systems such as collaborative, content-based, and cross-recommendations Create efficient decision-making systems that will ease your work Familiarize ...

    Raspberry Pi Zero Cookbook

    Deep dive into the components of the small yet powerful Raspberry Pi Zero Get into grips with integrating various hardware, programming, and networking concepts with the so-called “cheapest computer...

    Packt.Django.Project.Blueprints.2016

    Dive deep into Django forms and how they work internally About the Author Asad Jibran Ahmed is an experienced programmer who has worked mostly with Django-based web applications for the past 5 years. ...

    React and React Native [Kindle Edition]

    Dive deep into each platform, from routing in React to creating native mobile applications that can run offline Use Facebook's Relay, React and GraphQL technologies, to create a unified architecture ...

Global site tag (gtag.js) - Google Analytics