随笔分类 -  Python

摘要:1 def deco(func): 2 def _deco(): 3 print("Before") 4 func() 5 print("End") 6 #return func 这里不需要返回 7 return ... 阅读全文
posted @ 2015-06-27 13:44 奔雷手 阅读(140) 评论(0) 推荐(0)
摘要:1)MYSQL的中文问题:在MYSQL的安装目录下修改my.ini文件中的“default-character-set=”为GB2312或者UTF-8,修改这一项之后,会对MYSQL中的数据库全部起作用,如果你为了减少以后不必要的麻烦,你也可以只设置你当前要使用的数据库的编码,如:CREATE DA... 阅读全文
posted @ 2015-04-17 21:06 奔雷手 阅读(152) 评论(0) 推荐(0)
摘要:#encoding=utf-8##by panda#解释器模式def printInfo(info):# print unicode(info, 'utf-8').encode('gbk') print info;#上下文类:演奏内容class PlayContext(): tex... 阅读全文
posted @ 2015-03-29 21:10 奔雷手 阅读(221) 评论(0) 推荐(0)
摘要:待定 阅读全文
posted @ 2015-03-22 18:54 奔雷手 阅读(127) 评论(0) 推荐(0)
摘要:#coding:utf-8'''Created on 2015.3.22@author: ZQM'''from __future__ import divisiondef jia(x,y): return x+y;def jian(x,y): return x-ydef cheng(x,... 阅读全文
posted @ 2015-03-22 18:51 奔雷手 阅读(184) 评论(0) 推荐(0)
摘要:Python 的 Class 比较特别,和我们习惯的静态语言类型定义有很大区别。1. 使用一个名为 __init__ 的方法来完成初始化。2. 使用一个名为 __del__ 的方法来完成类似析购操作。3. 所有的实例方法都拥有一个 self 参数来传递当前实例,类似于 this。4. 可以使用 __... 阅读全文
posted @ 2015-03-21 11:25 奔雷手 阅读(418) 评论(0) 推荐(0)
摘要:在python中,静态方法和类方法都是可以通过类对象和类对象实例访问。但是区别是:@classmethod 是一个函数修饰符,它表示接下来的是一个类方法,而对于平常我们见到的则叫做实例方法。 类方法的第一个参数cls,而实例方法的第一个参数是self,表示该类的一个实例。 普通对象方法至少需要一个s... 阅读全文
posted @ 2015-03-20 21:38 奔雷手 阅读(167) 评论(0) 推荐(0)
摘要:# -*- coding: utf-8 -*-'''Created on 2015年3月20日@author: chliu.brook'''import json;data = {'b':789,'c':456,'a':123}print 'DATA:', repr(data)print 'repr... 阅读全文
posted @ 2015-03-20 16:41 奔雷手 阅读(125) 评论(0) 推荐(0)
摘要:# -*- coding: cp936 -*-'''Created on 2018年7月8日@author: chliu.brook'''#coding=utf-8;import struct;import sys;a=12.34;bytes=struct.pack("d",a);print(byt... 阅读全文
posted @ 2015-03-20 15:23 奔雷手 阅读(245) 评论(0) 推荐(0)
摘要:在文件头加入# -*- coding: cp936 -*-# -*- coding: UTF-8 -*-print('你好'); 阅读全文
posted @ 2015-03-20 15:22 奔雷手 阅读(86) 评论(0) 推荐(0)
摘要:def walk_dir(dir,fileinfo,topdown=True): for root, dirs, files in os.walk(dir, topdown): for name in files: print(os.path.join(na... 阅读全文
posted @ 2015-03-20 11:11 奔雷手 阅读(215) 评论(0) 推荐(0)
摘要:__VERSION__ = '1.0'import xlrd as rd;import xlwt as wt;import os;class ExcelOperation(): def readExcel(self): excelDir=os.getcwd()+"... 阅读全文
posted @ 2015-03-19 17:33 奔雷手 阅读(323) 评论(0) 推荐(0)
摘要:__VERSION__ = '1.0'import xlrd as rd;import xlwt as wt;import os;class ExcelOperation(): def readExcel(self): excelDir=os.getcwd()+"... 阅读全文
posted @ 2015-03-19 16:43 奔雷手 阅读(88) 评论(0) 推荐(0)
摘要:def getCurDir(): curDir=os.getcwd(); return curDir; 阅读全文
posted @ 2015-03-18 21:26 奔雷手 阅读(180) 评论(0) 推荐(0)
摘要:python中的Module是比较重要的概念。常见的情况是,事先写好一个.py文 件,在另一个文件中需要import时,将事先写好的.py文件拷贝 到当前目录,或者是在sys.path中增加事先写好的.py文件所在的目录,然后import。这样的做法,对于少数文件是可行的,但如果程序数目很 多,层级... 阅读全文
posted @ 2015-03-18 18:26 奔雷手 阅读(146) 评论(0) 推荐(0)
摘要:当你打开一个.py文件时,经常会在代码的最下面看到if __name__ == '__main__':,现在就来介 绍一下它的作用. 模块是对象,并且所有的模块都有一个内置属性 __name__。一个模块的 __name__ 的值取决于您如何应用模块。如果 import 一个模块,那么模块__nam... 阅读全文
posted @ 2015-03-17 22:24 奔雷手 阅读(130) 评论(0) 推荐(0)
摘要:1 import cPickle as p; 2 3 FCurDir="D:\\1.txt"; 4 MyWList=["A1","A2","A3"]; 5 6 #Write File 7 8 MyWFile=file(FCurDir,"w"); 9 p.dump(MyWList,My... 阅读全文
posted @ 2015-03-17 22:20 奔雷手 阅读(146) 评论(0) 推荐(0)
摘要:http://pypi.python.org/pypi/xlrd解压后,打开cmd切换到对应目录,去执行:D:\tmp\dev_tools\python\excel\xlrd-0.8.0\xlrd-0.8.0>setup.py install 阅读全文
posted @ 2015-03-16 20:36 奔雷手 阅读(1671) 评论(0) 推荐(0)