content

python基础(10):文件操作

我只是一个虾纸丫 提交于 2019-12-03 21:14:37
1. 初识文件操作 使⽤python来读写⽂件是非常简单的操作。我们使⽤open()函数来打开⼀个⽂件,获取到⽂ 件句柄,然后通过⽂件句柄就可以进⾏各种各样的操作了,根据打开⽅式的不同能够执⾏的操 作也会有相应的差异。 打开⽂件的⽅式: r, w, a, r+, w+, a+, rb, wb, ab, r+b, w+b, a+b 默认使⽤的是r(只读)模式 2. 只读操作(r,rb) f = open("护⼠少妇嫩模.txt",mode="r", encoding="utf-8") content = f.read() print(content) f.close() 需要注意encoding表⽰编码集,根据⽂件的实际保存编码进⾏获取数据,对于我们⽽⾔,更 多的是utf-8. rb:读取出来的数据是bytes类型,在rb模式下,不能选择encoding字符集。 f = open("护⼠少妇嫩模.txt",mode="rb" ) content = f.read() print(content) f.close() 结果: b'\xe6\xaf\x85\xe5\x93\xa5, \xe5\xa4\xaa\xe7\x99\xbd, wuse\n\xe5\x91\xb5\xe5\x91\xb5\n\xe6\x97\xa5\xe5\xa4\xa9' rb的作⽤: 在读取非⽂本⽂件的时候

python 习题

柔情痞子 提交于 2019-12-03 21:14:33
文件内容为一个多层元组,遍历该元组,当全为数字时输出数字之和,全为字母输出字符串, 有数字有字母输出False,并将该内容写入到该文件的下一行中 # 方法一: t1= ((1,2,3),("a","b","c"),("a",1,2)) import pickle with open('D:\\a.txt', 'wb') as f: pickle.dump(t1,f) with open('D:\\a.txt', 'rb') as f1: content = pickle.load(f1) # 用这个方法一参数的形式写入,然后读出来也是参数 tup = tuple(content) result = [] def func(tup): for i in tup: if isinstance(i, tuple): func(i) else: result.append(i) list1 = list(filter(lambda x:type(x)==int, result)) list2 = list(filter(lambda x:type(x)==str, result)) if len(result) == len(list1): print(True) elif len(result) == len(list2): print(False) else: with open('D

js实现文本的复制粘贴的功能

强颜欢笑 提交于 2019-12-03 20:53:18
本文介绍的js复制粘贴功能的实现是借助于textarea和document.execCommand来实现将文本复制到粘贴板上,具体的代码如下: <!DOCTYPE html> < html > < head > < title > copy </ title > < style type = "text/css" > .top { width : 300 px ; height : 200 px ; position : absolute ; z-index : 2 ; background : #fff ; overflow : hidden ; } .bottom { width : 300 px ; height : 200 px ; position : absolute ; z-index : 1 ; overflow : hidden ; } #btn { height : 30 px ; text-align : center ; border : 1 px #00a2ca solid ; cursor : pointer }; #btn :hover { background : #00a2ca ; color : #fff }; </ style > < script type = "text/javascript" > var copy = function (

Mixed Content: The page at was loaded over HTTPS, but requested an insecure image.

爱⌒轻易说出口 提交于 2019-12-03 19:44:54
让浏览器不再显示 https 页面中的 http 请求警报 HTTPS 是 HTTP over Secure Socket Layer,以安全为目标的 HTTP 通道,所以在 HTTPS 承载的页面上不允许出现 http 请求,一旦出现就是提示或报错: Mixed Content: The page at ‘ https://www.taobao.com/ ‘ was loaded over HTTPS, but requested an insecure image ‘ http://g.alicdn.com/s.gif ’. This content should also be served over HTTPS. HTTPS 改造之后,我们可以在很多页面中看到如下警报: 很多运营对 https 没有技术概念,在填入的数据中不免出现 http 的资源,体系庞大,出现疏忽和漏洞也是不可避免的。 CSP 设置upgrade-insecure-requests 好在 W3C 工作组考虑到了我们升级 HTTPS 的艰难,在 2015 年 4 月份就出了一个 Upgrade Insecure Requests 的 草案 ,他的作用就是让浏览器自动升级请求。 在我们服务器的响应头中加入: header ("Content-Security-Policy: upgrade-insecure

Jquery的事件和动画

穿精又带淫゛_ 提交于 2019-12-03 12:02:14
4.1JQuery中的事件 4.1.1 简写方式 三种方式等效: $(document).ready(function(){}) $(function(){}) $().ready(function(){}) 4.1.2事件的绑定 在文档装载完成时,如果打算为元素绑定事件来完成某些操作,则可以使用bind()方法来匹配元素进行特定事件的绑定 bind( type [ ,data],fn); 第一个参数是事件类型:blur、focus、load、resize、scroll;或者是自定义的名称 第二个参数是可选参数,作为event.data 属性值传递给事件对象的额外数据对象 第三个参数则是用来绑定处理函数。 <style type="text/css"> .content{ display: none; } </style></head><body> <div id="panel"> <h5 class="head">什么是Jquery</h5> <div class="content">Jquery是 </div> </div> <script> $(function () { $(".head").bind("click",function (){ $(this).next("div.content").show(); }) }) </script></body>加强效果

小练习(开班信息列表练习)

南楼画角 提交于 2019-12-03 10:28:31
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title></title> 6 <style type="text/css"> 7 *{ 8 /*先清除浏览器的默认样式*/ 9 margin: 0; 10 padding: 0; 11 } 12 /*统一页面字体*/ 13 body{ 14 font: 12px/1 "宋体"; 15 } 16 .outer{ 17 width: 300px; 18 /*height: 473px;*/ 19 background-color: white; 20 margin: 50px auto; 21 } 22 .title{ 23 height: 36px; 24 background-color: #f5f5f5; 25 /*上边框*/ 26 border-top: 2px solid #019e8d; 27 /*设置行高,这样字体可以居中*/ 28 line-height: 36px; 29 /*设置内边距,让文字向内居中*/ 30 padding: 0px 22px 0px 16px; 31 } 32 .title a{ 33 float: right; 34 color: red; 35 } 36 .title h3{ 37 font: "微软雅黑"

Pulling elements from a large string with PHP using CSS style selectors?

匿名 (未验证) 提交于 2019-12-03 09:13:36
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following long string returned from a SOAP call into a variable, and I need to find the contents of certain elements within it, namely the .MoreInfoZone .OfferZone #Heading .content and .MoreInfoZone .OfferZone #Description .content . I can't do it with javascript, as it is for populating metatags for Facebook Open Graph, and their spiders won't run the javascript. $soap = ' <?xml version="1.0" encoding="utf-16"?> <div class="MoreInfoZone"> <div class="OfferZone"> <div id="Heading" class="Group"> <div class="Label"> <h3>Activity<

Open particular Jquery accordion pan based on current page URL

匿名 (未验证) 提交于 2019-12-03 09:05:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a Jquery accordion , accordion has pan's, list elements and anchor tags in list elements, href attributes of anchor tags have current page URL's. I just want that when a page is visited a particular panel (which contains that anchor tag) automatically opens and its list element should become active. I have code which make accordion and snippet in end which make list element active. But list element is not active and panel is not opened. I think I am missing something badly. Here is code: <script> $.ajax({ url: "/categories", type:

How to show all share options in android?

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am developing an Android app and want to share some text by opening all the share options available in device. But currently the list is showing Email, bluetooth, Gmail and messaging. Other apps like BBC news are showing more options in the same device like Bump, Picasa, and others. How to show all available options and handle them? I am using this: Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIntent.setType("text/vcard"); sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,mailBody); startActivity

css image max-width not working with Firefox / IE

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Here's a JsFiddle . HTML : <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1, maximum-scale=1"> <div data-role="page" > <div id="contentwrap"> <div id="content" data-role="content"> <img width="300" src="http://upload.wikimedia.org/wikipedia/commons/f/f1/Ski_trail_rating_symbol_red_circle.png" /> asdad asd asd asd sadadada ad sad asd asd asd asd sadasdaad adsa dasd sa </div> </div> </div> CSS : html, body { height: 100%; } #contentwrap { display: table; height: 100%; max-width: 500px; margin: 0 auto; position