Chapter 10 Creating and Modifying Text.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Chapter 10 Creating and Modifying Text.ppt

* Demo eliza here. Where’s the temperature? The word “temperature” doesn’t really show up. But the temperature always follows the word “Currently”, and always comes before the “bdeg;/b” td img src=/shared-local/weather/images/ps.gif width=48 height=48 border=0font size=-2br/fontfont size=-1 face=Arial, Helvetica, sans-serifbCurrently/bbr Partly sunnybr font size=+254bdeg;/b/fontfont face=Arial, Helvetica, sans-serif size=+1F/font/font/td /tr We can use the same algorithm we’ve seen previously Grab the content out of a file in a big string. (We’ve saved the HTML page previously. Soon, we’ll see how to grab it directly.) Find the starting indicator (“Currently”) Find the ending indicator (“bdeg;”) Read the previous characters Finding the temperature def findTemperature(): weatherFile = getMediaPath(ajc-weather.html) file = open(weatherFile,rt) weather = file.read() file.close() # Find the Temperature curloc = weather.find(Currently) if curloc -1: # Now, find the bdeg; following the temp temploc = weather.find(bdeg;,curloc) tempstart = weather.rfind(,0,temploc) print Current temperature:,weather[tempstart+1:temploc] if curloc == -1: print They must have changed the page format -- cant find the temp Adding new capabilities: Modules What we need to do is to add capabilities to Python that we haven’t seen so far. We do this by importing external modules. A module is a file with a bunch of additional functions and objects defined within it. Some kind of module capability exists in virtually every programming language. By importing the module, we make the module’s capabilities available to our program. Literally, we are evaluating the module, as if we’d typed them into our file. Python’s Standard Library Python has an extensive library of modules that come with it. The Python standard library includes modules that allow us to access the Internet, deal with time, generate random numbers, and…access files in a directory. Accessing pieces

文档评论(0)

gsgtshb + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档