1. os.mkdir()和os.path.join()的区别
os.path.join("D:\","test.txt") 功能仅仅是连接的作用:结果是D:\test.txt
在我们往“test.txt”写东西,然后保存,在这个目录下会生成这个文件,但是如果你不写东西,那么执行这句话之后,在D盘的目录下是不会有这个文件名称的。
os.mkdir(os.path.join("D:\","test.txt")) 生成一个目录或文件名, 即使不在“test.txt”写东西,然后保存,也是会生成相应的文件/目录的。
2.numpy.random.permutation
作用:随机排列 list[]
3.python2.7 print 不换行的三种方法
方法一:
- import sys
- sys.stdout.write("go ")
- sys.stdout.write("home")
- sys.stdout.flush()
方法二:函数方式调用print函数
- from __future__ import print_function
- print('go ', end='')
- print('home', end='')
方法三:
- print 'go',
- print 'home'
这种方法如果你直接执行python执行命令,然后敲入命令,是不行的,但如果放到文件里面运行,是可以的
3.1 检测 python程序运行时间
3.1.1 检测 python 脚本的运行时间
$ time -p python timing_functions.py
结果:
Total time running random_sort: 1.3931210041 seconds
real 1.49
user 1.40
sys 0.08
3.1.2 检测 python函数运行时间,使用 time
import time
start = time.clock()
excute()
end = time.clock()
print ("read: %f s", (end - start))
结果:
read: 6.760052 s