编写高质量代码改善python程序91个建议学习 第一章 建议1:理解pythonic的相关概念 狭隘的理解:它是高级动态的脚本编程语言,拥有很多强大的库,是解释从上往下执行的 特点: 美胜丑,显胜隐,简胜杂,杂胜乱,平胜陡,疏胜密 python定义 #python排序 def quicksort( ...
分类:
编程语言 时间:
2016-04-10 09:07:53
阅读次数:
187
#栈的实现,入栈判断是否Full,出栈判断是否EmptyclassStack():def__init__(st,size):st.stack=[];st.size=size;st.top=-1;defpush(st,content):ifst.Full():print"StackisFull!"else:st.stack.append(content)st.top=st.top+1defOut(st):ifst.Empty():print"StackisEmpty!"else..
分类:
其他好文 时间:
2016-04-09 17:08:48
阅读次数:
396
反射 代码示例:person.pydef run (a): print 'running %s'%adef eat(): print 'eating'def talk(): print 'taliking'player.py import persondef play(action): return ...
分类:
编程语言 时间:
2016-04-08 14:54:22
阅读次数:
184
import timedef hh(func): def wrapper(*args, **kwargs): start=time.clock() func(*args, **kwargs) end=time.clock() print 'time:%f'%(end - start) return ...
分类:
编程语言 时间:
2016-04-08 14:48:31
阅读次数:
184
def abc(test): print "hello %s"%testabc("brid")def say (a,*args): print a, argssay("hello","zha","ab")def say (a,**args): print a, argssay ("hello",na ...
分类:
编程语言 时间:
2016-04-08 14:46:16
阅读次数:
143
class myexception(Exception): def __init__(self,value): self.value = value self.message ='myexception error'def say(): #name='FreeMan' try: raise myex ...
分类:
编程语言 时间:
2016-04-08 14:38:01
阅读次数:
150
今天使用到了render(contentType: "text/javascript"),对于此问题,自己存在很不解,特此,做笔记,以待进一步研究,有幸的话,希望大家帮忙给解惑! class WriteController{ def showContent={ String content=topi ...
分类:
编程语言 时间:
2016-04-07 20:22:13
阅读次数:
235
在Python中如何自定义函数:其格式为 def 函数名(函数参数): 内容 交互模式下编写函数完毕按两次回车返回>>> pass作为函数为空函数的占位符(她的意思是什么都不做),也就是说没想好写什么函数,先用pass占位,然后先让程序跑起来; 数据类型检查可以用内置函数isinstance(obj ...
分类:
编程语言 时间:
2016-04-06 18:18:54
阅读次数:
179
备忘,其实是想知道该进程使用的内存状况。 首先要获取系统的内存信息: def memory_stat(): ''' return the memory info ''' mem = {} stat = {} f = open('/proc/meminfo') lines = f.readlines( ...
分类:
编程语言 时间:
2016-04-06 09:27:37
阅读次数:
157
第一步: 先定义三个类: class Animal: def __init__(self, name): self.name = name #这个方法的意思是,如果继承该类,就得自己写talk方法,如果不写,就抛出异常 def talk(self): raise NotImplementedErro... ...
分类:
编程语言 时间:
2016-04-05 12:32:29
阅读次数:
180