随笔分类 -  python note

asset of learning python
摘要:python doc:python standard library https://docs.python.org/3/library/index.html python2 -m pip install --upgrade pip --force-reinstall 安装easy_install 阅读全文
posted @ 2014-12-09 14:03 道以万计
摘要:import sysfuncName = sys._getframe().f_back.f_code.co_name #获取调用函数名lineNumber = sys._getframe().f_back.f_lineno #获取行号print sys._getframe().f_code.... 阅读全文
posted @ 2014-12-09 11:26 道以万计 阅读(16055) 评论(0) 推荐(2)
摘要:#!/bin/python#import platformdef TestPlatform(): print ("----------Operation System--------------------------") #Windows will be : (32bit, Windo... 阅读全文
posted @ 2014-12-08 15:52 道以万计 阅读(28892) 评论(0) 推荐(1)
摘要:see: http://www.cnblogs.com/sunada2005/p/3193300.html 一、可使用的第三方库 python中处理excel表格,常用的库有xlrd(读excel)表、xlwt(写excel)表、openpyxl(可读写excel表)等。xlrd读数据较大的exce 阅读全文
posted @ 2014-10-13 09:53 道以万计 阅读(34914) 评论(1) 推荐(1)
摘要:import argparse'''The following code is a Python program that takes a list of integers and produces either the sum or the max''' '''usage: argparse... 阅读全文
posted @ 2014-10-08 11:14 道以万计 阅读(712) 评论(0) 推荐(0)
摘要:http://blog.csdn.net/smilelance/article/details/65299501.Python正则式的基本用法import rep = re.compile(r'abc*')p.match(s)# 注意:match 只匹配 开头或结尾, 如果不想这样, 请用search# 也可以re.match(r'abc*', s)# 推荐第一种形式,compile用于加速1.1基本规则1.2重复1.2.1最小匹配与精确匹配1.3前向界定与后向界定1.4组的基本知识2.re模块的基本函数2.1使用compile加速2.2 match和searc 阅读全文
posted @ 2013-04-09 18:50 道以万计 阅读(283) 评论(0) 推荐(0)
摘要:1。 指代函数指针def xx(name): print name.upper()p = xxp('mike') 结果:MIKE2。 变量传递xx = 'Hello'p = xxprint p 结果:Hello3。使用eval二次解析xx = 'Hello'Hello = 'My happy day!'p = xxprint eval(p) 结果:My happy day!xx = 'Hello'def Hello(): print 'My happy day!' return 1p = xxpri 阅读全文
posted @ 2013-03-13 17:59 道以万计 阅读(253) 评论(0) 推荐(0)
摘要:#!/usr/local/bin/python2.7# encoding: utf-8 阅读全文
posted @ 2013-03-06 14:46 道以万计 阅读(133) 评论(0) 推荐(0)
摘要:变量作用域:LEGB L: local E: enclosing function locals G: global B: built-in 1。 内嵌的模块是全局作用域:顶层命名空间 2。 全局作用域的范围只限于单个文件 3。 每次对函数的调用都创建了一个新的本地作用域 4。 所有的变量名都可以归为 本地、全局、内置def func1(param=None): def func2(param2=param): if not param2: param2 = 'default' print param2 # Just... 阅读全文
posted @ 2013-02-28 13:50 道以万计 阅读(1111) 评论(0) 推荐(0)
摘要:test_module.py'''Created on Feb 28, 2013@author: agent'''import sysname = 42def func(path): print pathclass Klass: passprint 'done loading.'if __name__ == '__main__': passtest:import test_moduleprint test_module.__dict__.keys()print test_module.__file__print t 阅读全文
posted @ 2013-02-28 10:43 道以万计 阅读(183) 评论(0) 推荐(0)
摘要:# 1. import modulemodule.method()del module # get rid of the module name(name space)reload(module)# 2. import run.py dynamicallyimport imp, osm = imp.load_source('m', os.path.join(_casedir, 'run.py')) # 3.from module import methodmethod()# 4. import ctypesobj = ctypes.CDLL('XXX.d 阅读全文
posted @ 2013-02-28 10:37 道以万计 阅读(889) 评论(0) 推荐(0)
摘要:python3: https://docs.python.org/3/library/csv.html 阅读全文
posted @ 2013-02-22 17:00 道以万计 阅读(206) 评论(0) 推荐(0)
摘要:def test_variable_forin(): alist = ['a', 'bb', 'cc', 'dd'] count = 0 for i in alist: print i count += 1 if len(i) > 1: ... 阅读全文
posted @ 2013-02-20 16:49 道以万计 阅读(172) 评论(0) 推荐(0)
摘要:临时文件definition: import tempfile tempfile_name = tempfile.mktemp() # 创建名称唯一的临时文件供使用 temp1 = tempfile.TemporaryFile() # 注意:用TemporaryFile()创建的文件没有文件名 temp11= tempfile.TemporaryFile(mode='w+t') temp2 = tempfile.NamedTemporaryFile() # 尽管文件带有名字,但它仍然会在close后自动删除 temp... 阅读全文
posted @ 2013-02-07 10:37 道以万计 阅读(292) 评论(0) 推荐(0)
摘要:summary:import timecur_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))一、小应用1.python获取当前时间time.time() 获取当前时间戳 1180759620.859time.localtime() 当前时间的struct_time形式 (2007, 6, 2, 12, 47, 7, 5, 153, 0)time.ctime() 当前时间的字符串形式 ’Sat Mar 28 22:24:24 2009′ISOTIMEFORMAT=’%Y-%m-%d %X 阅读全文
posted @ 2013-02-07 10:24 道以万计 阅读(171) 评论(0) 推荐(0)