Skip to content

Instantly share code, notes, and snippets.

# coding: utf-8
from thread import start_new_thread
X =1
def worker():
while 1:
global X
X *= 2
import dst
import a_1 # 1不能直接做变量,所以import 1是不行的。
import b_2
# 这里分两种情况,a_1中有一个主函数main,则运行main,如果没有主函数,a_1中直接就是逻辑代码,那么不需要运行任何东西,import a_1的时候,a_1的代码就会直接运行
a_1.main()
@laonger
laonger / python 100000000 loops
Created November 27, 2013 12:27
python 100000000 loops
>>> def a():
... s = time.time()
... for i in xrange(0, 100000000):
... pass
... print time.time() -s
...
>>> def b():
... s = time.time()
... i = 0
... while i < 100000000:
def getMaxpage():
page=2
dir_url="http://aa.wordpress.com/2013/06/page/"+str(page)
while getPageFlag(dir_url):
page=page+1
dir_url="http://fashioncoolture.com.br/2013/06/page/"+str(page)#这个要更新的
print page
@laonger
laonger / gist:5781396
Last active December 18, 2015 12:18
一个已排好序的数组,求其中两个元素(a和b),使得(a-b)的平方最小(要求复杂度尽可能低)
def a(l):
c, n = l[-1] - l[-2], 0
r = len(l) -2
while n <= len(l) -3:
cc = l[n+1] - l[n]
if cc < c:
r, c = n, cc
n = n +1
return r, r+1
@laonger
laonger / python func call
Created January 2, 2013 11:31
python实例方法的调用问题
#!/usr/bin/python
# encoding: utf-8
class Foo(object):
def __init__(self):
self._func = None
def callDerivedFunc(self):
self._func() # wrong #这里实际上等于:Bar.hello(), hello是一个实例方法,需要传递一个实例才能调用。所以报错,应该改成:self._func(self)
method = self._func