注:需要修改mimetypes.py文件(该文件可通过文章底部的网盘分享连接获取),否则会报错,类似如下
""" ################################################################################## Try to play an arbitrary media file. Allows for specific players instead of always using general web browser scheme. May not work on your system as is; audio files use filters and command lines on Unix, and filename associations on Windows via the start command (i.e., whatever you have on your machine to run .au files--an audio player, or perhaps a web browser). Configure and extend as needed. playknownfile assumes you know what sort of media you wish to open, and playfile tries to determine media type automatically using Python mimetypes module; both try to launch a web browser with Python webbrowser module as a last resort when mimetype or platform unknown. ################################################################################## """
学习python有半年左右,安装第三方库都是通过 pip install 或者 easy_install。每次都要打开命令行感觉太麻烦。还好Pycharm提供了安装第三方库和安装插件的功能。
Python自带了一些命令行工具,可以用来快速处理工作。我把这些命令行工具称之为 冷兵器 ,没有趁手工具时候可以顶替使用。这些工具都是python标准模块,具有 main 函数,直接使用 python -m 命令执行,多数可以使用 -h/--help查看帮助。
首先我们需要找到server.py文件所在的位置,一般都在python安装目录下的Lib目录下,例如我的电脑在D:\Miniconda3\Lib\http目录下,此时我们根据server.py的源码新增一个文件server2.py,代码如下:
通过分析github上5000个开源python项目,找出了最常用的库,下表是最常用的前670个。括号里的数字代表其出现的次数。
[Python]代码 #_*_encoding:utf-8_*_ #script for python3.2 #------------------------------------------------------------------------------- # Name: 发送邮件 # Purpose: # # Author: QiuChangJie # # Created: 10/09/2012 # Copyright: (c)
为什么会报错? 原因是pip安装python包会加载当前用户的用户目录,我的用户目录恰好是含有中文的,ascii不能进行编码。
1.首先更新pip版本的时候出现。这是出现在python2.7.16出现的问题 2.进入你的pyhton目录下的Lib\mimetypes.py 打开它 3.在import下面加入这代码 if sys
运行环境:python2.7,python3.x的话,把代码中的中文的字符前的u去掉就好,这是2与3基本的区别 # -*- coding: utf-8 -*- import smtplib impor
V站笔记 运行环境:python2.7,python3.x的话,把代码中的中文的字符前的u去掉就好,这是2与3基本的区别 📷 # -*- coding: utf-8 -*- import smtplib import email.MIMEMultipart # import MIMEMultipart import email.MIMEText # import MIMEText import email.MIMEBase # import MIMEBase import os.path import
下载对应版本repo文件, 放入/etc/yum.repos.d/(操作前请做好相应备份)
在Python 3.0中,%操作符通过一个更强的格式化方法format()进行了增强。对str.format()的支持已经被反向移植到了Python 2.6 在2.6中,8-bit字符串和Unicode字符串都有一个format()方法,这个方法会把字符串当作一个模版,通过传入的参数进行格式化。这个用来格式化的模版使用大括号({,})作为特殊字符。 # Substitute positional argument 0 into the string. "User ID: {0}".format("root") -> "User ID: root" # Use the named keyword arguments 'User ID: {uid} Last seen: {last_login}'.format( uid='root', last_login = '5 Mar 2008 07:20') -> 'User ID: root Last seen: 5 Mar 2008 07:20' 大括号可以写两遍来转义。 format("Empty dict: {{}}") -> "Empty dict: {}" 字段名字可以为整数,表示参数的位置。像{0}, {1}等。也可以是参数的名字。你以可以使用字段的组合来读取属性或者字典的key值。 import sys 'Platform: {0.platform}\nPython version: {0.version}'.format(sys) -> 'Platform: darwin\n Python version: 2.6a1+ (trunk:61261M, Mar 5 2008, 20:29:41) \n [GCC 4.0.1 (Apple Computer, Inc. build 5367)]' import mimetypes 'Content-type: {0[.mp4]}'.format(mimetypes.types_map) -> 'Content-type: video/mp4' 注意,当使用字典类型的表示方法,如[.mp4]时,你不需要引号将字符串(.mp4)引起来;它会查找用.mp4作为主键的值。以整数开头的字符串会被转换成一个整数。你不能在被格式化的字符串中写复杂的表达式。 到此,我们已经演示了怎样替换指定的字段。我们还可以通过在格式化指示符后面添加一个冒号来进行精确格式化。例如: # Field 0: left justify, pad to 15 characters # Field 1: right justify, pad to 6 characters fmt = '{0:15} ${1:>6}' fmt.format('Registration', 35) -> 'Registration $ 35' fmt.format('Tutorial', 50) -> 'Tutorial $ 50' fmt.format('Banquet', 125) -> 'Banquet $ 125' 格式化指示符可以通过嵌套进行引用。 fmt = '{0:{1}}' width = 15 fmt.format('Invoice #1234', width) -> 'Invoice #1234 ' width = 35 fmt.format('Invoice #1234', width) -> 'Invoice #1234 ' 可以指定所需长度的字符串的对齐方式。 效果字符: < (默认)左对齐 > 右对齐 ^ 中间对齐 = (只用于数字)在小数点后进行补齐 格式化指示符可以包含一个展示类型来控制格式。例如,浮点数可以被格式化为一般格式或用幂来表示。 >>> '{0:g}'.format(3.75) '3.75' >>> '{0:e}'.format(3.75) '3.750000e+00' 展示类型有很多。2.6的文档里有完整的列表。这里列出一些示例。 'b' - 二进制。将数字以2为基数进行输出。 'c' - 字符。在打印之前将整数转换成对应的Unicode字符串。 'd' - 十进制整数。将数字以10为基数进行输出。 'o' - 八进制。将数字以8为基数进行输出。 'x' - 十六进制。将数字以16为基数进行输出,9以上的位数用小写字母。 'e' - 幂符号。用科学计数法打印数字。用'e'表示幂。 'g' - 一般格式。将数值以fixed-point格式输出。当数值特别大的时候,用幂形式打印。 'n' - 数字。当值为整数时和'd'相同,值为浮点数时和'g'相同。不同的是它会根据区域设置插入数字分隔符。 '%' - 百分数。将数值乘以100然后以fixed-point
A few days ago,I have wrote down this post http://androidyue.github.io/blog/2014/01/19/scan-media-files-in-android/. Now I will paste my code snippet.
爬虫之上传文件,request如何上传文件,当我们遇到需要上传文件的接口时,如何破解上传文件的密码呢?
压缩可以大大的降低我们Web服务器的响应速度,压缩从而提高我们网页的加载速度,以及节省一定的带宽.
Yii 是一个高性能,基于组件的 PHP 框架,用于快速开发现代 Web 应用程序。 名字 Yii (读作 易)在中文里有“极致简单与不断演变”两重含义, 也可看作 Yes It Is! 的缩写。
当我们建好图床以后,会想着上传图片到媒体库中,毕竟空荡荡的图床多难受啊,不仅如此,以后我们也可以引用图床里的图片作为外链。当然,手动筛选并上传图片也是一种方式,这里更推荐全自动下载并上传的方式。(目前仅支持 Chevereto )
""" Count lines among all program source files in a tree named on the command line, and report totals grouped by file types (extension). A simple SLOC (source lines of code) metric: skip blank and comment lines if desired. """
""" #################################################################################### Test: "python ...\Tools\visitor.py dir testmask [string]". Uses classes and subclasses to wrap some of the details of os.walk call usage to walk and search; testmask is an integer bitmask with 1 bit per available self-test; see also: visitor_*/.py subclasses use cases; frameworks should generally use__X pseudo private names, but all names here are exported for use in subclasses and clients; redefine reset to support multiple independent walks that require subclass updates; #################################################################################### """
""" Use: "python ...\Tools\visitor_cpall.py fromDir toDir trace?" Like System\Filetools\cpall.py,
zope\plone\pylons\web2py\cherrypy\webware:web框架 pyjamas soap:web service Ironpython 1\ socket(AF_INET,SOCK_STREAM) SOCK_DGRAM AF_UNIF sobj.bind() sobj.listen con,dre=sobj.accept() con.receive() con.send() con.close() socket(xx) sobj.connect()
为了高质量的软件交付,组织必须转向自动化流程,手动流程太容易出错,效率低下。对于执行CD和devops的团队来说,自动化变得越来越重要,大家只需要专注在code和review中,其它过程都尽可能的自动化。
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE; /* * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Versio
pyQuery 是 jQuery 的Python实现,如果对Web前端有了解,特别是有用过 jQuery 的,那么 pyQuery 将会是你处理HTML内容的最佳选择。教程基于如下环境: 系统: Windows 7 64位 Python版本: 2.7 安装pyQuery pyQuery 需要通过 ez_install 安装。 1,下载 ez_install.py 脚本,右键保存即可 https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
本文,帮助了解响应压缩的一些知识及用法(大部分翻译于官网,英文水平有限,不准确之处,欢迎指正)。
import os, sys, ftplib from getpass import getpass from mimetypes import guess_type
""" Use: "python ...\Tools\visitor_collect.py searchstring rootdir". CollectVisitor simply collects a list of all files containing a search string, for display or later processing (e.g., replacement, auto-editing); pass in a test filename extensions list to constructor to override the default in SearchVisitor; this is roughy like find+grep for text exts; """
在tools\tolua目录下有个README,里面详述了在各个平台下怎么使用,这里只是稍微记述下windows下面的使用和遇到的问题。
开发一个web服务器,一次处理一个HTTP请求。您的web服务器应该接受并解析HTTP请求,从服务器的文件系统中获取请求的文件,创建HTTP响应头和响应体,然后将响应直接发送到客户。如果服务器中不存在请求的文件,则服务器应发送“404 Not Found”消息返回客户端。
gobuster dir -u http://10.10.10.168:8080 -w /usr/share/wordlists/dirbuster/directory-list-2.3-small.txt ,发现都是404.
分享一个真实案例,我们的服务部署在海外,国内访问时访问服务时,响应有点夸张;某些返回数据比较大的接口,耗时在 600ms+上,然而我们的服务 rt 却是在 20ms 以下,绝大部分的开销都花在了网络传输上
获取浏览器版本 <script> function getBrowser() { var UserAgent = navigator.userAgent.toLowerCase(); var browserInfo = {}; var browserArray = { IE: window.ActiveXObject || "ActiveXObject" in window,
下载 官网地址:http://www.goldgrid.com/jinge_download/index.aspx?num=5 解压后的文件 js文件中有两个重要的js文件iWebOffice
import os, sys, ftplib from getpass import getpass from mimetypes import guess_type, add_type
可以看到,我没有出现异常,按照正常的来走,先运行before后是responseProcessor,最后是after 那么我们制造一个异常看看有没有捕获到
然后在cmd进入命令行窗口, 进入ez_setup.py目录,我这里是下载放置在F盘,然后输入命令:python ez_setup.py 系统就会自动下载setuptools工具安装,最后的结局是显示编码错误:
在搭建很多服务器过程中,我们一般都使用Apache或者Nginx来搭建,但是很多情况下我们并不需要这么复杂的软件,或许只是想展示一个http页面或者ftp列表而已,我得去安装apache或者nginx
内容提供是实质上是个接口,后门,他给别人提供数据,系统联系人是个比较复杂的内容通过者。
我的博客已迁移到xdoujiang.com请去那边和我交流 一、基础环境 1、角色、ip、版本、内核 serverA 10.1.10.117 3.2.0-4-amd64 7.8 python readline rlcompleter python-2.7.3 二、python tab键自动补齐命令安装 1、安装python apt-get -y install python 2、查看下目前已安装的模块 python Python 2.7.3 (default, Mar 13 2014, 11:03:55
代码 function isChrome360() { if( navigator.userAgent.toLowerCase().indexOf('chrome') > -1 ) { var desc = navigator.mimeTypes['application/x-shockwave-flash'].description.toLowerCase(); if( desc.indexOf('shockwave') > -1 ) {
java中easyexcel导入导出带有图片的Excel(main方法方式),web方式详见另一篇
文件分类应该是大家每天都在做的事情。假设现在有一大批文件(这一大批文件类型不定,也就是说有些是文本文件有些是二进制文件)都被放在了一个文件夹中,需要对它们进行一个分类,该如何迅速地完成?手工操作文件数量少还可以接受,文件数量一旦多了起来就显得力不从心~!因此,编写一个程序来处理这个问题是很有必要的。下面我用最简单的例子为大家讲解如何快速完成文件分类的操作。
在上一篇文章介绍了Node.js基础API 接下来我们做一个案例,用Node.js实现静态资源服务器
记录下如何使用python中的boto3,连接并操作S3对象服务 # python版本 boto3 api官方文档 # -*- coding: utf-8 -*- """ @Time : 2021/9/23 17:19 @Author : summer @File : s3_client.py @Software: PyCharm """ import json import os from collections import defaultdict import urllib3 imp
Rollup是一个JavaScript模块打包器,它可以将多个模块打包成一个单独的文件,以便在浏览器中使用。与其他打包工具相比,Rollup的主要优势在于它可以生成更小、更快的代码。在本文中,我们将深入了解Rollup的插件开发。
Brotli是一种全新的数据格式,可以提供比Zopfli高20-26%的压缩比。据谷歌研究,Brotli压缩速度同zlib的Deflate实现大致相同,而在Canterbury语料库上的压缩密度比LZMA和bzip2略大。 链接:Google开源Brotli压缩算法 微软使用了一种基于谷歌提供的C代码的实现,向.NET Core 2.1添加了Brotli压缩支持。由于Brotli得到了许多Web浏览器和Web服务器的广泛支持,所以.NET Core提供对这项技术的支持是非常有用的。 什么是 Brotli 压
领取专属 10元无门槛券
手把手带您无忧上云