02 2013 档案

摘要:def secondsToTime(secs): hours = float(secs / (60 * 60)) divisorForMinutes = secs % (60 * 60) minutes = float(divisorForMinutes / 60) divisorForSeconds = divisorForMinutes % 60 seconds = math.ceil(divisorForSeconds) obj = { 'h':hours, 'm':minutes, 's':seconds } return ... 阅读全文
posted @ 2013-02-28 20:52 践道者 阅读(265) 评论(0) 推荐(0)
摘要:node.js处理都是异步的var fs = require("fs");fs.readFile("a.txt", 'utf8', function(error, file){ if(error) throw error; console.log("我读完文件了"); console.log(file)});console.log("我不会被阻塞的"); js的模拟sleep函数,function sleep(milliSeconds){ var startTime = new Date().get 阅读全文
posted @ 2013-02-20 16:03 践道者 阅读(285) 评论(0) 推荐(0)
摘要:一、修改server.jsvar http = require("http");var url = require("url"); //导入内置url模块function start(route){ function onRequest(request, response){ var pathname = url.parse(request.url).pathname; //提取url console.log("Request received."); console.log("Request for " + pa 阅读全文
posted @ 2013-02-20 11:48 践道者 阅读(1556) 评论(0) 推荐(0)
摘要:在第一篇笔记中,了解到,使用node.js 内置模块的方法:var http = require("http");创建自己的模块的方法其实就是将其功能代码导出到请求这个模块的脚本。server.js代码如下,var http = require("http");function start(){ function onRequest(request, response){ console.log("Request received.") response.writeHead(200, {"Content-Type" 阅读全文
posted @ 2013-02-20 11:18 践道者 阅读(364) 评论(0) 推荐(0)
摘要:var http = require("http");http.createServer(function(request, response){ response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello,World"); response.end();}).listen(8888);保存文件为server.js, 在命令行里运行代码node server.js在浏览器地址栏输入 http://localhost:8 阅读全文
posted @ 2013-02-20 10:47 践道者 阅读(288) 评论(0) 推荐(0)
摘要:while Verbox == False: print 'False'else: print 'True' 阅读全文
posted @ 2013-02-18 14:31 践道者 阅读(4809) 评论(0) 推荐(0)
摘要:解释器options:1.1 –d 提供调试输出1.2 –O 生成优化的字节码(生成.pyo文件)1.3 –S 不导入site模块以在启动时查找python路径1.4 –v 冗余输出(导入语句详细追踪)1.5 –m mod 将一个模块以脚本形式运行1.6 –Q opt 除法选项(参阅文档)1.7 –c cmd 运行以命令行字符串心事提交的python脚本-d 提供调度输出,其意思是如果代码里有__debug__的时候才会有效,如,if __debug__: print 'debug'-O生成优化的字节码,生成pyo后缀文件,此选项会关闭所有__debug__调试信息,但不能关闭 阅读全文
posted @ 2013-02-18 10:36 践道者 阅读(5086) 评论(0) 推荐(0)
摘要:import timeimport threading#当还剩下一百个产品时,则不进行消费,待生产者生产#当生产了一千个产品时,则不进行生产,待消费者消费product = 0 #产品初始化时为0lock = threading.Condition()class Producer(threading.Thread): def __init__(self, lock): self._lock = lock threading.Thread.__init__(self) def run(self): global product ... 阅读全文
posted @ 2013-02-17 16:05 践道者 阅读(2882) 评论(0) 推荐(0)
摘要:_VERBOSE = Falseif __debug__: class _Verbose(object): def __init__(self, verbose=None): if verbose is None: verbose = _VERBOSE self.__verbose = verbose def _note(self, format, *args): if self.__verbose: format = format %... 阅读全文
posted @ 2013-02-17 09:07 践道者 阅读(318) 评论(0) 推荐(0)
摘要:在研究python内置类库Queue源代码时发现full方法连续使用两个逻辑运算符,方法如下: def full(self): self.mutex.acquire() n = 0 < self.maxsize == self._qsize() self.mutex.release() return n经实践,n = 0 < self.maxsize == self._qsize()的意思详细分解即为,if 0 < self.maxsize && self.maxsize == self._qsize(): return Truereturn False可以一 阅读全文
posted @ 2013-02-16 15:25 践道者 阅读(2703) 评论(0) 推荐(0)