随笔分类 -  Python

记录学习和使用python中遇到的问题
摘要: 阅读全文
posted @ 2013-11-22 17:03 小郭学路 阅读(129) 评论(0) 推荐(0) 编辑
摘要:例子12:ipython使用--pylab参数,默认加入matplotlib模块[root@typhoeus79 guosong]# ipython --pylabWARNING: IPython History requires SQLite, your history will not be savedPython 2.7.3 (default, Nov 27 2012, 17:47:24) Type "copyright", "credits" or "license" for more information.IPython 阅读全文
posted @ 2013-11-16 22:33 小郭学路 阅读(654) 评论(0) 推荐(0) 编辑
摘要:例子11-1:横坐标时间的处理from matplotlib.dates import datestr2num,DateFormatterimport matplotlib.dates as datesfig,ax=plt.subplots()formatter = DateFormatter('%... 阅读全文
posted @ 2013-11-15 20:39 小郭学路 阅读(5801) 评论(0) 推荐(0) 编辑
摘要:pandaspandasis an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for thePythonprogramming language一、安装1、pandasgit clone git://github.com/pydata/pandas.git2、RequirementsCpythonhttps://pypi.python.org/pypi/Cython/pytzhttps://pypi.pytho 阅读全文
posted @ 2013-11-14 21:31 小郭学路 阅读(1441) 评论(0) 推荐(0) 编辑
摘要:例子6、中文标签测试#!/usr/bin/env python2.7#-*- coding:utf-8 -*-import matplotlib.pyplot as plt import numpy as npimport matplotlib.font_manager as fmfontpath = '/usr/share/fonts/chinese/TrueType/ukai.ttf'myfont = fm.FontProperties(fname=fontpath)#定义一个myfont变量,myfont=matplotlib.font_manager.FontPrope 阅读全文
posted @ 2013-11-14 11:54 小郭学路 阅读(3887) 评论(0) 推荐(0) 编辑
摘要:1、简介Python的lists是非常的灵活以及易于使用。但是在处理科学计算相关大数量的时候,有点显得捉襟见肘了。Numpy提供一个强大的N维数组对象(ndarray),包含一些列同类型的元素,这点和python中lists不同。Python lists are extremely flexible and really handy, but when dealing with a largenumber of elements or to support scientific computing, they show their limits.One of the fundamental a 阅读全文
posted @ 2013-11-14 11:15 小郭学路 阅读(2599) 评论(0) 推荐(0) 编辑
摘要:小试牛刀在上一节已经安装好matplotlib模块,下面使用几个例子熟悉一下。对应的一些文档说明:http://matplotlib.org/1.3.1/api/pyplot_summary.html例子1:二维坐标——整数[root@typhoeus79 20131113]# ipythonIn [1]: import matplotlib.pyplot as pltIn [2]: x = range(6)In [3]: plt.plot(x,[xi*xi for xi in x])Out[3]: []In [4]: plt.savefig('test1.png')输出结果: 阅读全文
posted @ 2013-11-13 20:31 小郭学路 阅读(984) 评论(0) 推荐(0) 编辑
摘要:numpy1、下载安装源代码http://sourceforge.net/projects/numpy/files/NumPy/安装python2.7 setup.py install2、测试导入numpy模块,出现如下错误:[root@typhoeus79 numpy-1.8.0]# python2.7Python 2.7.3 (default, Nov 27 2012, 17:47:24) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2Type "help", "copyright", " 阅读全文
posted @ 2013-11-13 20:16 小郭学路 阅读(33245) 评论(0) 推荐(0) 编辑
摘要:fcntl 文件控制模块http://docs.python.org/2.7/library/fcntl.html#module-fcntlstruct 二进制文本处理模块http://docs.python.org/2.7/library/struct.html#module-structtermios [POSIX calls for tty I/O control接口]http://docs.python.org/2.7/library/termios.html#module-termios 阅读全文
posted @ 2013-11-08 16:53 小郭学路 阅读(135) 评论(0) 推荐(0) 编辑
摘要:hashlib在做一个授权管理系统,需要生产动态生成密码,故使用hashlib>>> import time>>> import hashlib>>> now = time.time()>>> md5_str = str(now)>>> >>> md5_str'1383811244.44'>>> token_temp = hashlib.md5(md5_str).hexdigest()>>> token_temp'13d2c75 阅读全文
posted @ 2013-11-07 16:00 小郭学路 阅读(203) 评论(0) 推荐(0) 编辑
摘要:argparse命令行参数解析模块,原optparse已经停止开发,建议替换为argparse在python2.7后默认加入parserArgumentParser默认解析来源sys.argv,也可以提供显示参数进行解析。构造参数中,通常只需关心description和epilog。前者显示程序标题,后者在帮助信息的尾部显示详细的版权、使用描述等。程序代码:[root@typhoeus79 20131105]# more test_argparse.py #!/usr/bin/env python26#-*- coding:utf-8 -*-from argparse import Argum 阅读全文
posted @ 2013-11-05 19:58 小郭学路 阅读(398) 评论(0) 推荐(0) 编辑
摘要:Process创建子进程执行指定的函数>>> from multiprocessing import Process,current_process>>> >>> def test(*args,**kwargs):... p = current_process()... print p.name,p.pid... print args... print kwargs... >>> >>> p = Process(target=test,args=(1,2),kwargs={"a":&q 阅读全文
posted @ 2013-11-04 16:41 小郭学路 阅读(1434) 评论(0) 推荐(0) 编辑
摘要:Thread先引入一个例子:>>> from threading import Thread,currentThread,activeCount>>> >>> def test(s):... print "ident:",currentThread().ident... print "count:",activeCount()... print s... >>> >>> Thread(target = test, args =('Hello',)). 阅读全文
posted @ 2013-10-28 21:38 小郭学路 阅读(15393) 评论(0) 推荐(0) 编辑
摘要:手动执行可以的,但是在crontab中却无法执行,在网上搜了一圈,给出的结论是将相对路径改成绝对路径。改了之后解决这个问题。是不是依赖某些环境变量,linux 里的 cron 只有几个基本的环境变量。改成:* * * * * source ~/.bashrc && /usr/bin/python3.... 阅读全文
posted @ 2013-10-23 13:20 小郭学路 阅读(491) 评论(0) 推荐(0) 编辑
摘要:官方文档:http://docs.python.org/2.7/library/time.html#module-time 阅读全文
posted @ 2013-10-18 16:58 小郭学路 阅读(160) 评论(0) 推荐(0) 编辑
摘要:1、getopt——C风格命令行解析http://docs.python.org/2.7/library/getopt.html#module-getoptgetopt.getopt(args, options[, long_options])先引入一个例子:>>> import getopt>>> >>> args = "-a -b -cfoo -d bar a1 a2".split() #将输入的参数转换成一个列表,通常在实例应用中args = sys.argv[1:]>>> args['- 阅读全文
posted @ 2013-10-18 11:05 小郭学路 阅读(976) 评论(0) 推荐(1) 编辑
摘要:{ "code": 0, // code为0表示成功,否则为1 "message": null, "data": { "syscpuidle": { "data": { "cpu": { // 整体cpu的使用情况 "cpuidle": 88.0, // Time spent in the idle task. (这些值都是百分比的数值) ... 阅读全文
posted @ 2013-10-17 19:55 小郭学路 阅读(797) 评论(0) 推荐(0) 编辑
该文被密码保护。
posted @ 2013-10-17 16:55 小郭学路 阅读(3) 评论(0) 推荐(0) 编辑
摘要:#!/usr/bin/env python26#-*- coding:utf-8-*-def test(): a = 10 b = 20 return a,b #返回一个元组atuple= test()a,b = test()print atupleprint atuple[0]print atuple[1] 阅读全文
posted @ 2013-10-17 11:54 小郭学路 阅读(267) 评论(0) 推荐(0) 编辑
摘要:作用域测试例子:>>> a = 10>>> def test(): ... a = 20 ... print a... >>> a10>>> test()20>>> a #执行test之后,a的值还是10,没有变10这里涉及作用域问题。作用域函数形参和内部变量都存储在locals名字空间中。>>> def test(a,*args,**kwargs):... s = "Hello test!"... print locals()... >>> tes 阅读全文
posted @ 2013-10-16 20:26 小郭学路 阅读(277) 评论(0) 推荐(0) 编辑