摘要: #转自:http://www.oschina.net/code/snippet_162893_24130#!/usr/bin/python# -*- coding: UTF-8 -*-# snakegameimport sysfrom PyQt4.QtCore import *from PyQt4.QtGui import *import randomclass Snake: def __init__(self): self.length = 4 self.posArray = [(3,0),(2,0),(1,0),(0,0)] self.isD... 阅读全文
posted @ 2013-08-31 13:38 神·鲸落 阅读(421) 评论(0) 推荐(0) 编辑
摘要: 转自:http://www.oschina.net/code/snippet_1174881_24083#!/usr/bin/python# -*- coding: UTF-8 -*-# -*- coding: utf-8 -*-"""Created on Sat Aug 24 15:46:11 2013@author: wangxiaotao"""import numpy as npimport matplotlib.pyplot as pltimport matplotlibF = np.arange(-50, 240, 0.1) 阅读全文
posted @ 2013-08-31 13:28 神·鲸落 阅读(525) 评论(0) 推荐(0) 编辑
摘要: 快速绘图¶使用pyplot模块绘图matplotlib的pyplot模块提供了和MATLAB类似的绘图API,方便用户快速绘制二维图表。我们先看一个简单的例子:05-matplotlib/matplotlib_simple_plot.py用pylab库快速绘图import numpy as npimport matplotlib.pyplot as plt ❶x = np.linspace(0, 10, 1000)y = np.sin(x)z = np.cos(x**2)plt.figure(figsize=(8,4)) ❷plt.plot(x,y,label="$sin( 阅读全文
posted @ 2013-08-31 13:02 神·鲸落 阅读(3139) 评论(0) 推荐(1) 编辑
摘要: import psycopsyco.full()转自:http://www.ibm.com/developerworks/cn/linux/sdk/python/charm-28/Python 对于您想让它做的事来说通常够快了。编程新手对于类似 Python 这样的解释型/字节编译型语言,将 90% 的关注点集中在执行速度方面,是相当幼稚的。在最新的硬件上,大多数非优化的 Python 程序运行的速度和所需要达到的速度一样快,而且,花费额外的编程工作以使应用程序运行得更快实在没什么意义。因此,在本文,我只对其它的百分之十感兴趣。有时,Python 程序(或用其它语言编写的程序)也会运行得极其缓 阅读全文
posted @ 2013-08-31 12:12 神·鲸落 阅读(805) 评论(0) 推荐(0) 编辑
摘要: """ PAMIE Build 3.0aBased on cPAMIE and PAM.py by RLMRevised: March 03, 2009Developers: Robert L. MarchettiDescription: This python class file allow you to write scripts to Automate the Internet Explorer Browser Client.This software is provided 'as-is', without any express or 阅读全文
posted @ 2013-08-31 00:42 神·鲸落 阅读(721) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python# -*- coding: UTF-8 -*-#递归def print_lol(the_list): for each_item in the_list: if isinstance(each_item,list): #判断each_item 是否为列表,如果是则递归 print_lol(each_item) else: print(each_item)mo=[['a','b','c'],'c','d','s',[1,2,3,4],'e',' 阅读全文
posted @ 2013-08-31 00:34 神·鲸落 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 先将命令提示符指向安装文件所在目录然后cmdpython setup.py install 阅读全文
posted @ 2013-08-31 00:29 神·鲸落 阅读(276) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python# -*- coding: UTF-8 -*-import matplotlib.pyplot as pltx=[i for i in range(-20,20)]y=[i**2 for i in x]# plt.plot(x,y)# plt.plot(x,y,color="red",linestyle="-.",marker="o") #linestyle="dashed"虚线 marker="o"表示标记为圆圈# plt.plot(x,y,"ro- 阅读全文
posted @ 2013-08-31 00:17 神·鲸落 阅读(359) 评论(0) 推荐(0) 编辑
摘要: 1 #!/usr/bin/python 2 # -*- coding: UTF-8 -*- 3 4 import matplotlib.pyplot as plt 5 import numpy as np 6 #To draw y =x^2 (-3<=x<=3) 7 x=[x for x in range(100)] 8 y = [ele**2 for ele in x] 9 z = [ele *2 for ele in x]10 # plt.plot(x,y,'ro-',label="y=x^2")#作图:y关于x的曲线 label是曲线标签 阅读全文
posted @ 2013-08-31 00:15 神·鲸落 阅读(284) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python# -*- coding: UTF-8 -*-##from Tkinter import Label,mainloop##Label(text="this is a label").pack() #pack() 用几何管理器来认识控件##mainloop()from Tkinter import*class App: def __init__(self,master): frame=Frame(master)#构造器通过创建一个Frame帧窗口部件,并且把它存储在一个frame的变量中 frame.pack() ... 阅读全文
posted @ 2013-08-31 00:10 神·鲸落 阅读(314) 评论(0) 推荐(0) 编辑
摘要: #encoding=utf-8##callable()判断对象是否可以被调用a=1def b(): passprint "callable(a)",callable(a)print "callable(b)",callable(b)##结果:##callable(a) False##callable(b) True 阅读全文
posted @ 2013-08-31 00:09 神·鲸落 阅读(244) 评论(0) 推荐(0) 编辑
摘要: #encoding=utf-8#isinstance(var_a,type_b)可以确定某个变量是否有某种类型#变量var_a是否有type_b的类型.返回booleana=8b="eight"c=8.0print isinstance(a,int)print isinstance(b,str)print isinstance(c,float)print isinstance(a,str) #变量a没有str类型 阅读全文
posted @ 2013-08-31 00:08 神·鲸落 阅读(248) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python# -*- coding: UTF-8 -*-#在新文件夹中创建一个名为setup.py的文件#包含有关发布的元数据.for distutils.core import setupsetup( name='nester', #名字 version="1.0.0", #版本号 py_modules=["nester"],#将模块的元数据与setup函数的参数关联 author="zaijie", author_email="474335983@qq.com", url 阅读全文
posted @ 2013-08-31 00:07 神·鲸落 阅读(283) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python# -*- coding: UTF-8 -*-import threadingimport timeclass timer(threading.Thread): def __init__(self,num,interval): threading.Thread.__init__(self) self.thread_num=num self.interval=interval self.thread_stop=False def run(self): while not self.... 阅读全文
posted @ 2013-08-31 00:02 神·鲸落 阅读(396) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/python# -*- coding: UTF-8 -*-# 异常 描述# Exception 所有内建异常# SystemExit 由sys.exit()产生# StandardError 除SystemExit外所有内建异常# ArithmeticError 所有运算异常# FloatingPointError 浮点数运算异常# OverflowError 数值溢出# ZeroDivisionError ... 阅读全文
posted @ 2013-08-31 00:01 神·鲸落 阅读(449) 评论(0) 推荐(0) 编辑