Python2.7
VCHH
这个作者很懒,什么都没留下…
展开
-
python 删除文件夹下面的所有文件&&python删除文件夹下面的所有文件夹及子文件
一、python 删除文件夹下面的所有文件import osCUR_PATH = r'C:\Users\xxx\Desktop\新建文件夹'def del_file(path): ls = os.listdir(path) for i in ls: c_path = os.path.join(path, i) if os.path.isdir(c_path): del_file(c_path) else:原创 2021-08-30 16:15:07 · 6333 阅读 · 0 评论 -
Python处理JSON
Python处理JSON概念序列化(Serialization):将对象的状态信息转换为可以存储或可以通过网络传输的过程,传输的格式可以是JSON、XML等。反序列化就是从存储区域(JSON,XML)读取反序列化对象的状态,重新创建该对象。JSON(JavaScript Object Notation):一种轻量级数据交换格式,相对于XML而言更简单,也易于阅读和编写,机器也方转载 2016-07-16 14:42:41 · 327 阅读 · 0 评论 -
Python最好用的模板引擎Jinja
sudo pip install Jinja2原创 2016-07-14 18:13:32 · 1250 阅读 · 1 评论 -
python2.7:str
# coding=utf-8# delete char or str in strsstr = " hello"sstr.strip() #'\n', '\r', '\t', ' 'print sstrprint sstr.strip()str1 = "123abc"print str1.lstrip("21")print str1.rstrip('bc')# co原创 2016-03-29 19:38:38 · 1066 阅读 · 0 评论 -
Python 字符串操作(string替换、删除、截取、复制、连接、比较、查找、包含、大小写转换、分割等)
# coding=utf-8# delete char or str in strsstr = " hello"sstr.strip() #'\n', '\r', '\t', ' 'print sstrprint sstr.strip()str1 = "123abc"print str1.lstrip("21")print str1.rstrip('bc')# co转载 2016-04-19 20:05:37 · 426 阅读 · 0 评论 -
彻底关闭Pycharm拼写检查
Pycharm作为一款优秀的PythonIDE,唯一让我觉得不安的就是它的拼写检查机制实在有点严格,单词不能连写、变量名和函数名不能大写等等,网上百度了一下取消其拼写检查的方法,发现不是很全面,再次给大家奉上一个相对彻底的取消方法。 首先,关闭拼写检查,setting-->Inspections-->Spelling-->Typo,取消勾选: 第二步,关闭代码风格检查,settin原创 2016-03-28 13:02:50 · 33636 阅读 · 2 评论 -
python2.7:return func name and lineno
# coding=utf-8import sysdef get_cur_info(): print sys._getframe().f_code.co_name print sys._getframe().f_lineno print sys._getframe().f_back.f_code.co_nameget_cur_info()# log:# get_c转载 2016-03-28 19:17:43 · 774 阅读 · 0 评论 -
为pycharm修改Theme & Color
1.导入 (File --> Import Setting --> django.jar) 2.将文件pycharm-themes-master.zip解压,将里面的colors文件夹下的文件拷贝到目录:C:\Users\Administrator\.PyCharm40\config\colors下3.重启pycharm后可以在Editor --> Colors & Fonts 里转载 2016-03-26 19:04:16 · 6151 阅读 · 0 评论 -
python2.7;解决中文无法正常显示问题
# coding=utf-8 #第一行添加,以下6种写法,默认ascii编码所以要重定义编码格式以支持中文# coding= utf-8# encoding=utf-8# encoding= utf-8# -*- coding: utf-8 -*-# -*- coding:utf-8 -*-# 注意python 对空格敏感以下为错误写法# coding = utf-8# codi原创 2016-03-26 15:15:25 · 6217 阅读 · 0 评论 -
集合:高性能的容器类型之OrderedDict objects
OrderedDict objects Ordered dictionaries are just like regular dictionaries but they remember theorder that items were inserted. When iterating over an ordered dictionary,the items are returne原创 2016-07-16 17:51:34 · 835 阅读 · 0 评论 -
python vs ruby
作者:王骍链接:http://www.zhihu.com/question/19552194/answer/14326635来源:知乎著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。Python和Ruby阵营之间似乎一直在争论谁更好(貌似Ruby阵营的人们更狂热些),不信可以试试google一下“Python Ruby”。上面这篇文章我目前还没看,在看之前先转载 2016-07-06 16:49:55 · 438 阅读 · 0 评论 -
python 字符串 大小写转换 以及一系列字符串操作技巧
总结capitalize() 首字母大写,其余全部小写 upper() 全转换成大写 lower() 全转换成小写 title() 标题首字大写,如"i love python".title() "I Love Python" 转换大小写和其他语言一样,Python为string对象提供了转换大小写的方法:upper() 和 lower()。还不止这些,Python还为...转载 2019-02-07 10:37:13 · 787 阅读 · 0 评论 -
均匀的生成圆和三角形内的随机点
http://www.cnblogs.com/TenosDoIt/p/4025221.html转载 2018-08-23 18:44:55 · 897 阅读 · 0 评论 -
Python随机生成均匀分布在单位圆内的点代码示例
这篇文章主要介绍了Python随机生成均匀分布在单位圆内的点代码示例,具有一定参考价值,需要的朋友可以了解下。Python有一随机函数可以产生[0,1)区间内的随机数,但是如果我们想生成随机分布在单位圆上的,那么我们可以首先生成随机分布在单位圆边上的点,然后随机调整每个点距离原点的距离,但是我们发现这个距离不是均匀分布于[0,1]的,而是与扇形的面积相关的我们使用另外的随机函数生成从[0,...转载 2018-07-25 21:23:50 · 5101 阅读 · 0 评论 -
python 获取目录下文件(转)
获取指定目录下文件的文件名以及文件的数量,然后列出其中还存在的目录名称:import os,sysdef listdir(dir,file): file.write(dir +'\n') fielnum =0 list = os.listdir(dir)#列出目录下的所有文件和目录 for line in list: filepa...转载 2018-06-28 14:25:34 · 213 阅读 · 0 评论 -
一个Excel转换为Json格式的Python脚本
来自:http://blog.csdn.net/langresser_king/article/details/43051525项目路径:https://code.csdn.net/langresser/excel2json一个Python脚本,自动转换Excel里面的配置到Json格式。1、这个是为Unity准备的,不过稍作修改可运行于任何环境2、Excel内容要求为转载 2017-03-13 16:10:56 · 906 阅读 · 0 评论 -
pip vs easy_install
pip vs easy_installPage Status:CompleteLast Reviewed:2015-09-08easy_install was released in 2004, as part of setuptools. It wasnotable at the time for installing packag原创 2016-08-07 19:52:28 · 862 阅读 · 6 评论 -
Python 2.7 实战详解
项目地址:https://github.com/Minhowe/Python-Workspace原创 2016-06-17 16:34:12 · 484 阅读 · 0 评论 -
Python 实战之列表(list)实战详解
# coding=utf-8# 1.创建一个列表# 只要把逗号分隔的不同的数据项使用方括号括起来即可。如下所示:list1 = ['physics', 'chemistry', 1997, 2000]list2 = [1, 2, 3, 4, 5]list3 = ["a", "b", "c", "d"]print list1print list2print list3# 2.访原创 2016-07-29 17:47:11 · 592 阅读 · 0 评论 -
python2.7:dic2json 解决中文无法正常显示问题
# coding=utf-8# dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, # allow_nan=True, cls=None, indent=None, separators=None, default=None, sort_keys=False, **kw)import jsondic = {"原创 2016-03-25 17:19:23 · 1668 阅读 · 0 评论 -
python 输出冒号;引号嵌套问题
# coding=utf-8SUFFIX = "xls"path = "name.xls"pos_start = path.find(SUFFIX) - 1js_name = path[:pos_start] + "_Josn.js"print js_nameprint "''"print '""'print path[:pos_start]print '"path[:pos_s原创 2016-03-26 13:21:01 · 6327 阅读 · 0 评论 -
Json概述以及python对json的相关操作
什么是json:JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。易于人阅读和编写。同时也易于机器解析和生成。它基于JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999的一个子集。JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族的转载 2016-03-26 11:13:31 · 358 阅读 · 0 评论 -
python2.7:IOError: [Errno 2] No such file or directory:
import osprint os.getcwd() #打印出当前工作目录 os.chdir('the dir which include the file a.txt') #修改当前工作目录原创 2016-03-25 09:51:02 · 9537 阅读 · 0 评论 -
python2.7:urllib 和urllib2之间的区别
You might be intrigued by the existence of two separate URL modules in Python -urllib and urllib2. Even more intriguing: they are not alternatives for each other. So what is the difference between转载 2016-03-25 10:25:27 · 1464 阅读 · 0 评论 -
python2.7:文件编码检测chardet 详解
# coding=utf-8import os,chardetprint os.getcwd() # 打印当前工作目录os.chdir("C:\Users\Administrator\Desktop\Pyhton2.7Tests") # 修改当前工作目录f = open("open_file_test.txt", "r")result = chardet.detect(f.read())原创 2016-03-25 10:27:40 · 2542 阅读 · 0 评论 -
python2.7: open()文件处理使用介绍
#coding=utf-8#新建文件open_file_test.txt内容:# Hello World# This is a test fileimport osprint os.getcwd()os.chdir("C:\Users\Administrator\Desktop\Pyhton2.7Tests")test = [ "test1\n", "test2\n", "test3原创 2016-03-25 10:49:55 · 19359 阅读 · 0 评论 -
python2.7:str unicode 详解
# -*- coding: UTF-8 -*-# 1.区别:# (1)str和unicode都是basestring的子类sstr = "hello" #strustr = u"hello" #unicodeprint isinstance(sstr, basestring)print isinstance(ustr, basestring)# (2)str是字节串,由uni原创 2016-03-25 11:31:36 · 4936 阅读 · 0 评论 -
字符编码笔记:ASCII,Unicode和UTF-8
1. ASCII码我们知道,在计算机内部,所有的信息最终都表示为一个二进制的字符串。每一个二进制位(bit)有0和1两种状态,因此八个二进制位就可以组合出256种状态,这被称为一个字节(byte)。也就是说,一个字节一共可以用来表示256种不同的状态,每一个状态对应一个符号,就是256个符号,从0000000到11111111。上个世纪60年代,美国制定了一套字符编码,对英语字符与二进制位转载 2016-03-24 20:13:15 · 464 阅读 · 0 评论 -
python问题:IndentationError:expected an indented block错误解决
原文地址:http://blog.csdn.net/neilhappy/article/details/7724959Python语言是一款对缩进非常敏感的语言,给很多初学者带来了困惑,即便是很有经验的Python程序员,也可能陷入陷阱当中。最常见的情况是tab和空格的混用会导致错误,或者缩进不对,而这是用肉眼无法分别的。在编译时会出现这样的错IndentationError:转载 2016-03-23 19:23:33 · 1010 阅读 · 0 评论 -
什么是pyc文件
参考来源 http://www.cnblogs.com/dkblog/archive/2009/04/16/1980757.html什么是pyc文件pyc是一种二进制文件,是由py文件经过编译后,生成的文件,是一种byte code,py文件变成pyc文件后,加载的速度有所提高,而且pyc是一种跨平台的字节码,是由python的虚拟机来执行的,这个是类似于JAVA或者.NET的虚拟转载 2016-03-23 14:36:54 · 799 阅读 · 0 评论 -
python2.7:模块安装4种方法
一、方法1: 单文件模块直接把文件拷贝到 $python_dir/Lib二、方法2: 多文件模块,带setup.py下载模块包,进行解压,进入模块文件夹,执行:python setup.py install三、 方法3:easy_install 方式 先下载ez_setup.py,运行python ez_setup 进行easy_install工具的安装,之后就可以使用原创 2016-03-25 09:09:10 · 4489 阅读 · 0 评论 -
python2.7:中默认的编码格式是 ASCII 格式,在没修改编码格式时无法正确打印汉字,所以在读取中文时会报错。
python2.xPython中默认的编码格式是 ASCII 格式,在没修改编码格式时无法正确打印汉字,所以在读取中文时会报错。解决方法为只要在文件开头加入 # -*- coding: UTF-8 -*- 或者 #coding=utf-8 就行了。代码中包含中文,就需要在头部指定编码。注意:Python3.X 源码文件默认使用utf-8编码,所以可以正常解析中文,无需指定 UT原创 2016-03-24 15:29:55 · 3351 阅读 · 0 评论 -
python2.7:str.find 用法
函数原型:find(str, pos_start, pos_end)解释:str:被查找“字串”pos_start:查找的首字母位置(从0开始计数。默认:0)pos_end: 查找的末尾位置(默认-1)返回值:如果查到:返回查找的第一个出现的位置。否则,返回-1。举例论证: 1.str = "0123" pr原创 2016-03-24 19:22:13 · 5319 阅读 · 0 评论 -
python2.7:float2int 1.0=1 1.1=1.1
a = 1.0str = str(a)pos_start = str.find(".")if pos_start > 0: str = str[0:pos_start] print int(str) if(int(str) == a): a = int(str) print "yes" else: a = a原创 2016-03-24 19:24:46 · 942 阅读 · 0 评论 -
python操作Excel读写--使用xlrd
一、安装xlrd模块 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境。二、使用介绍 1、导入模块 import xlrd 2、打开Excel文件读取数据 data = xlrd.open_workbook('excelFile.xls')转载 2016-03-25 18:45:39 · 528 阅读 · 0 评论 -
python 冒号与逗号的区别
注意if\while\for等(或函数定义)语句在结尾处包含一个冒号——我们通过它告诉python下面跟着一个语句块。--------------冒号的用法if guess == number:print 'Congratulations, you guessed it.' # New block starts hereprint "(but you do not win any转载 2016-03-25 18:43:06 · 3777 阅读 · 0 评论 -
python None与Null
python None与Null一、Python对象要理解这个,首先要理解Python对象:python对象具有三个特性:身份、类型、值。三特性在对象创建时被赋值。只有值可以改变,其他只读。类型本身也是对象。二、Null与None是Python的特殊类型,Null对象或者是None Type,它只有一个值None.它不支持任何运算也没有任何内建方法.None转载 2016-03-25 18:25:26 · 825 阅读 · 0 评论 -
解决python问题:IndentationError :1. notepad++ 显示行号 2.tab自动转化为空格符
python安装 pyreadline 方法1.window 打开终端 2.执行easy_install pyreadlineor:pip install pyreadline以下解决IndentationError :1. notepad++ 显示行号 视图(V) ⇒ 显示符号 ⇒ 显示空格与制表符原创 2016-03-24 12:04:33 · 3854 阅读 · 0 评论 -
python2.7:创建修改删除目录
#coding=utf-8import osprint os.getcwd() #get current work diros.chdir("C:\Users\Administrator\Desktop\Pyhton2.7Tests") #change dirprint os.getcwd()print os.listdir(os.getcwd()) #filename list dir原创 2016-03-25 13:54:06 · 1307 阅读 · 0 评论 -
Python2.7:测试内部类型及type和isinstance用法区别
# -*- coding: UTF-8 -*-class test1: passclass test2(test1): passif __name__=="__main__": #判断类型 a=123 #int print type(a) a=123.1 #float print type(a) a=test1() # test1 print type(a) a=test2() #test2 pr原创 2016-03-24 14:15:43 · 4167 阅读 · 0 评论