Fall-back from the nopython compilation path to the object mode compilation

出现此提示的原因是用@jit标注的函数内存在非数值运算语句。

比如下例中,time()函数和print()函数都不能出现在foo()函数中。正确写法为:

1
2
3
4
5
6
7
8
9
10
11
12
13
import numba as nb
import time
 
@nb.jit
def foo(x, y):
	s = 0
	for i in range(x, y):
		s += i
	return s
 
tt = time.time()
print(foo(1, 100000000))
print('Time used: {} secs'.format(time.time() - tt))

美化输出xml或json

xml

1
2
3
from xml.dom.minidom import *
with open('d:/xml.txt', 'r') as f:
    print(parseString(f.read()).toprettyxml())

json

1
python -m json.tool d:\json.txt

下载文件

1
2
3
4
import requests
resp = requests.get('http://file.url', headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'})
with open("aa.dat", "wb") as f:
    f.write(resp.content)