随笔分类 - Python
摘要:Python3.3下测试通过获取文件大小使用os.path.getsize函数,参数是文件的路径获取文件夹大小importosfromos.pathimportjoin,getsizedefgetdirsize(dir):size=0.0forroot,dirs,filesinos.walk(dir):size+=sum([getsize(join(root,name))fornameinfiles])returnsizeif__name__==“__main__”:filesize=getdirsize(r'c:\windows') print(("Thereare
阅读全文
posted @ 2013-09-04 11:08
预见者
摘要:在python3.3环境下1.写一个简单地Python源文件,比如test.py,内容如下:import sys, osdef test(arg1, arg2):print "begin test..."fun1('1', '2')print arg1print arg2def fun1(arg1, arg2): print arg1 print arg2if __name__ == '__main__': test(*sys.argv[1:])2, 右键test.py->Edit with IDLE进入IDLE界面,R
阅读全文
posted @ 2013-09-04 11:04
预见者
摘要:http://www.vimer.cn/2010/12/%E5%9C%A8python%E4%B8%AD%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E4%BD%8D%E7%BD%AE%E6%89%80%E5%9C%A8%E7%9A%84%E8%A1%8C%E5%8F%B7%E5%92%8C%E5%87%BD%E6%95%B0%E5%90%8D.html对于python,这几天一直有两个问题在困扰我:1.python中没办法直接取得当前的行号和函数名。这是有人在论坛里提出的问题,底下一群人只是在猜测python为什么不像__file__一样提供__line__和__
阅读全文
posted @ 2013-09-04 11:01
预见者
摘要:importpymssqlclassMSSQL:"""对pymssql的简单封装pymssql库,该库到这里下载:http://www.lfd.uci.edu/~gohlke/pythonlibs/#pymssql使用该库时,需要在Sql Server Configuration Manager里面将TCP/IP协议开启用法:"""def__init__(self,host,user,pwd,db):self.host=hostself.user=userself.pwd=pwdself.db=dbdef__GetConnect(se
阅读全文
posted @ 2013-07-23 22:20
预见者
摘要:pymssql methodsset_max_connections(number)-- Sets maximum number of simultaneous database connections allowed to be open at any given time. Default is 25.get_max_connections()-- Gets current maximum number of simultaneous database connections allowed to be open at any given time.Connection(pymssqlCn
阅读全文
posted @ 2013-07-23 22:19
预见者
摘要:先来一个简单的例子吧:?12345678910importMySQLdbtry:conn=MySQLdb.connect(host='localhost',user='root',passwd='root',db='test',port=3306)cur=conn.cursor()cur.execute('select * from user')cur.close()conn.close()exceptMySQLdb.Error,e:print"Mysql Error %d: %s"%(e.ar
阅读全文
posted @ 2013-07-23 22:09
预见者
摘要:The following identifiers are used as reserved words, orkeywordsof the language, and cannot be used as ordinary identifiers. They must be spelled exactly as written here:False class finally is returnNone continue for lambda tryTrue def from ...
阅读全文
posted @ 2013-07-23 21:53
预见者

浙公网安备 33010602011771号