Python 学习

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[]


>>> np.random.permutation(10)
array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6])
>>> np.random.permutation([1, 4, 9, 12, 15])
array([15,  1,  9,  4, 12])
>>> arr = np.arange(9).reshape((3, 3))
>>> np.random.permutation(arr)
array([[6, 7, 8],
       [0, 1, 2],
       [3, 4, 5]])

        

3.python2.7 print 不换行的三种方法

方法一:

Python代码   收藏代码
  1. import sys  
  2.   
  3. sys.stdout.write("go ")  
  4. sys.stdout.write("home")  
  5.   
  6. sys.stdout.flush()  

 

 方法二:函数方式调用print函数

Python代码   收藏代码
  1. from __future__ import print_function  
  2.   
  3. print('go ', end='')  
  4. print('home', end='')  

 

方法三:

 

Python代码   收藏代码
  1. print 'go',   
  2. print 'home'  

 这种方法如果你直接执行python执行命令,然后敲入命令,是不行的,但如果放到文件里面运行,是可以的


3.检测Python程序运行时间、CPU和内存占用的方法

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
















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值