《懒人的PYTHON》由会员分享,可在线阅读,更多相关《懒人的PYTHON(19页珍藏版)》请在金锄头文库上搜索。
1、懒人的PYTHON smallfish能少敲就少敲点键盘的敲击次数有限手指辛苦程度阅读难度指数能少敲就少敲点f=open(a.txt)whileTrue:line=f.readline()ifnotline:breakprintlinef.close()withopen(a.txt)asf:line=f.readline()printline能少敲就少敲点ifvar1!=0:passifvar2!=None:passiflen(list1)0:passifdict1.has_key(a):passifnotvar1:passifnotvar2:passIfaindict1:pass能少敲就少敲
2、点dict1=name:smallfish,age:20printname:+dict1name+,age:+str(dict1age)printname:%s,age:%d%(dict1name,dict1age)printname:%(name)s,age:%(age)d%dict1能少敲就少敲点str1=abcdeprintstr1:3-abcprintstr13:-deprintstr1:-2-abcprintstr1:-1-edcba能少敲就少敲点list1=11,22,33,11,44,22list2=foreinlist1:ifenotinlist2:list2.append(e
3、)list3=list(set(list1)能少敲就少敲点list1=11,22,33,11,44,22list2=foreinlist1:ife%2=0:list2.append(e)list3=eforeinlist1ife%2=0能不重复就不重复时间宝贵重复劳动干点别的.能不重复就不重复能不重复就不重复easy_installxxxpipinstallxxx-esvn/git/hg.pipfreeze-listallpackagepipuninstallxx-uninstall能不重复就不重复$pipinstallpssh$pssh-hhost-iuname-a120:52:45SUCC
4、ESS127.0.0.1.20:08:53UTC2011i686GNU/Linux$cathost127.0.0.1pscp/prsync能不重复就不重复$pipinstallfabric$fabuname.输出略fromfabric.apiimport*env.hosts=127.0.0.1defuname():run(uname-a)能不重复就不重复$pipinstallsupervisor$catsupervisord.confprogram:hellocommand=python/home/smallfish/hello.pyautorstart=truestdout_log能不重复就
5、不重复$cathello.pyimportweburls=(/(.*),hello)app=web.application(urls,globals()classhello:defGET(self,name):returnhello:+nameif_name_=_main_:app.run()smallfishdesktop:$sudosupervisorctlstatushellohelloRUNNINGpid1008,uptime0:02:32smallfishdesktop:$sudosupervisorctlstophellohello:stoppedsmallfishdesktop:
6、$sudosupervisorctlstarthellohello:started能不重复就不重复能不重复就不重复db=MySQLdb.connect(.)cur=db.cursor()cur.execute(.)rs=cur.fetchall()printrsdb.close()$pipinstallweb.pyImportwebdb=web.database(dsn=mysql,)rs=db.select(table1)forrinrs:printr能不重复就不重复rs=db.select(“table2”,where=”id=1”,order=”idDESC”)rs=db.select(“xx”,limit=10,offset=20)db.update(“xx”,where=”id=10”,name=”aa”,xx=”dd”)db.delete(“xx”,where=”id=10”)rs=db.query(“selectxxfromxxxgroupbyddorderbyxx”)Over.THX!