随笔分类 -  Python

摘要:http://developer.51cto.com/art/201203/321041.htm 阅读全文
posted @ 2013-10-11 19:54 glose 阅读(194) 评论(0) 推荐(0) 编辑
摘要:1、连接数据库import os,sysPROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))sys.path.insert(0, os.path.join(PROJECT_ROOT, 'lib'))CONFIG_PATH = os.path.join(PROJECT_ROOT,'config.cfg')from sqlalchemy import create_enginefrom sqlalchemy.ext.declarative import declarative_baseimport Co 阅读全文
posted @ 2013-04-26 20:16 glose 阅读(4316) 评论(0) 推荐(0) 编辑
摘要:fromsqlalchemy.ext.declarativeimportdeclarative_basefromsqlalchemyimportColumn,Integer,StringfromsqlalchemyimportSequencefromsqlalchemy.ormimportsessionmakerBase=declarative_base()fromsqlalchemyimportcreate_engineengine=create_engine('sqlite:///:memory:',echo=True)classUser(Base):__tablename 阅读全文
posted @ 2013-04-26 10:12 glose 阅读(443) 评论(0) 推荐(0) 编辑
摘要:#!/usr/bin/pythontry: import jsonexcept ImportError: import simplejson as jsonimport sysif __name__=='__main__': compath=b"/LuoYun/conf/luoyun.conf" f=open(compath,"r") jsonstr="" for l in f.readlines(): if l[:5]=='JSON=': jsonstr=l[5:] jsonstr.strip() b 阅读全文
posted @ 2013-04-03 15:31 glose 阅读(216) 评论(0) 推荐(0) 编辑
摘要:import socketimport reimport sysimport getoptimport stringdef check_server(address,port): s=socket.socket() print "Attempting to connect to %s on port %s" % (address, port) try: s.connect((address,port)) print "Connected to %s on port %s" % (address, port) return True excep... 阅读全文
posted @ 2013-04-03 15:30 glose 阅读(342) 评论(0) 推荐(0) 编辑
摘要:import subprocessmachines=["10.0.4.1","10.0.4.2","10.0.4.3","10.0.4.4","10.0.4.5","10.0.4.6","10.0.4.7","10.0.4.8","10.0.4.9","10.0.4.10"]cmd = "hostname"for machine in machines: subprocess. 阅读全文
posted @ 2013-04-03 15:29 glose 阅读(384) 评论(0) 推荐(0) 编辑
摘要:import getoptimport sysdef usage(): print(''' this is help message -h --help show help info -i --input the input file or directory -g --grep grep words -t --time modify time -v --verbose show verbose information ''') passdef main(): try: opts,args=getopt.getopt(sys.argv[1:],& 阅读全文
posted @ 2013-04-03 10:54 glose 阅读(691) 评论(0) 推荐(0) 编辑
摘要:python本身自带的SimpleHTTPServer模块,可以快速的在本机上建立一个临时的web server。执行命令如下:python -m SimpleHTTPServer,这样一个web server就开放了,默认端口是8000,如果你想更换端口则可以这样使用python -m SimpleHTTPServer 8888。在浏览器打上http://xx.xx.xx.xx:8000/就能访问到python所运行的当前目录了,想传什么就下吧,方便又 快捷。python轻松搭建自己的web服务器, 参考连接http://blog.163.com/jackylau_v/blog/static 阅读全文
posted @ 2012-11-27 10:51 glose 阅读(1095) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示