This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fib: | |
def __init__(self, max): | |
self.max = max | |
def __iter__(self): | |
self.a = 0 | |
self.b = 1 | |
return self | |
def next(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Fib implements Iterator{ | |
var $a = 0; | |
var $b = 1; | |
var $i = 0; | |
var $max = 100; | |
public function __construct($n=100){ | |
$this->max = $n; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cur_file_dir(): | |
# 获取脚本路径 | |
path = sys.path[0] | |
# 判断为脚本文件还是py2exe编译后的文件,如果是脚本文件,则返回的是脚本的目录,如果是py2exe编译后的文件,则返回的是编译后的文件路径 | |
if os.path.isdir(path): | |
return path | |
elif os.path.isfile(path): | |
return os.path.dirname(path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def my_date(unixtime, format='%m/%d/%Y %H:%M'): | |
d = datetime.datetime.fromtimestamp(unixtime) | |
return d.strftime(format) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == '__main__': | |
pid_file = cur_file_dir() + '/logstat.pid' | |
fp = open(pid_file, 'w') | |
try: | |
fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB) | |
except IOError: | |
# another instance is running | |
sys.exit(0) |
OlderNewer