摘要:
根据简明教程所解释:.pyc是在运行了一边程序的情况下才编译出来的。当你第二次使用该程序的时候,即可提高效率,因为所需要的函数已经编译完成。这个就是简明教程上说的,根据以上理解了下。这个概念值得记录。以前一直都不知道PYC是用来干嘛的,现在知道了。。。还有,它有个称呼叫:字节编译文件。。 阅读全文
摘要:
Python的循环打印感觉总有点怪怪的,和Perl有点区别。。不过它有它的好处吧。回头特地开个文章细总结下。。#!/usr/bin/pythonfor i in range(1,5): print ielse: print "The end" 阅读全文
摘要:
根据简明教程上学习,感觉总有点错误。好像哪有问题。上面有些案例根本就编译不过去。。纳闷。。#!/usr/bin/pythonnumber=30while 1: guess=int(raw_input("Ender an integer:")) if guess==number: print "yes" elif guess<number: print "no" else: print "end!"else: print "Done" 阅读全文
摘要:
根据学习来做一些简单的实验,顺带复习下。。#!/usr/bin/pythonnumber=23guess=int(raw_input("Enter an integer:"))if guess==number: print "guess=number!"elif guess<number: print "no"else: print "guess>number" 阅读全文
摘要:
#!/usr/bin/python#coding=utf-8#类的调用class tests:#定义一个tests的类 def __init__(self,start): #设置自身属性 self.state=start def mested(self,label): #设置调用方法 print(label,self.state) #输出结果 self.state+=1 #自身加一F=tests(0) #调用的是__init__,意义在于把start的值赋予给self.stateprint F.mested('kater') #调用方法... 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312 def tracer(func,*pargs,**kargs): print('calling:',func.__name__) return func(*pargs,**kargs)def func(a,b,c,d): return a+b+c+dprint(tracer(func,1,2,c=3,d=4))print(tracer(func,3,4,c=5,d=6)) 阅读全文
摘要:
#!/usr/bin/pythonimport urllib2import re def downURL(url,filename): print url print filename try: fp = urllib2.urlopen(url) except: print 'download exception' return 0 op = open(filename,"wb") while 1: s = fp.read() if not s: break ... 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312class tester: def __init__(self,start): self.state=start;# def mested(self,label):# print(label,self.state);# self.state+=1; def __call__(self,label): print(label,self.state); self.state+=1; 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312x=99;def times(x,y): return x+y;def panduan(dke,dk2): if(dke>dk2): return dke; else: return dk2;def inserters(seq1,seq2): res=[]; for x in seq1: if x not in seq2: res.append(x); return res;def inserters2(seq1,seq2): ... 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312res=[];linx=[];f=open('/root/access.log.2');for line in f.readlines(): line.rstrip(); log_home=line.split(); ip=log_home[0]; date=log_home[3].replace('[',''); point=log_home[5].replace('"',''); path=log_home[6]; offer=log_ho 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312items=['aaa',111, (3.4) ,2.03];tests=[(3.4),112];for key in tests: if key in items: print "yes"; else: print "NO";res=[];for key in items: if key not in tests: res.append(key);print res; 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312 if not 1: print('trues');else: print('fuck');bk='skc'; if(bk=='skl'): print 'NOok';elif(bk=='skc'): print 'OK!';else: print 'fuck'; branch={'span':10,'jack':20,'black':30};print (b 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312 while True: raply=raw_input('Enter type:'); if raply == 'stop': print('bye'); break; elif not raply.isdigit(): if (raply.isalpha()): print(raply.upper()); else: num=int(raply); print(num **2); 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312 while True: reply=raw_input('Enter text:'); if reply=='stop': break; try: num=int(reply); except: print('Bad!'*8); else: print(int(reply)**2);print('bye'); 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312 f=open('/var/log/apache2/access.log','r');log=f.readline().rstrip();log_home=log.split();print log_home;ip=log_home[0];date=log_home[3].replace('[','');point=log_home[5].replace('"','');path=log_home[6];offer=log_ho 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312 S='pallyer';print S.replace('all', 'bok');line='aa bb cc dd';col=line.split();print col;print line.startswith('a');print line.endswith('d'); 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312 class Worker: def __init__(self,name,pay): self.name=name; self.pay=pay; def lastName(self): return self.name.split()[0]; def giveRaise(self,percent): self.pay*=(1.0+percent); bob=Worker('ken', 5000000);print bob.lastName();... 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312 f=open('bok.log','rw');#f.write('wocaonima');#f.write('haoba');print f.read();f.close(); 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312 L=[[1,2,3],[4,5,6],[7,8,9]];print L;print L[1];print L[1][0];print L[1][0:-1];col2=[row[1] for row in L];print col2;print [row[1]+1 for row in L];G=(sum(row) for row in L);print next(G);print next(G);print next(G);print list(map(sum,L));D={'book':'SKET' 阅读全文
摘要:
#!/usr/bin/python#coding=gb2312 import re;mker=re.match('hello(.*)world','hello python world');print mker.group(1);print mker.groups();L=[123,'fuck',1.23];print len(L);print L[0];print L[:-1];print L+[4,5,6];print L;L.append('woyao');print L;L.pop(2);print L;L.insert( 阅读全文