4

一个简单的python小脚本

 3 years ago
source link: http://blogbo.org/2016/12/05/A%20simple%20python%20demo/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
四公子的剑

This is my site, welcome you!

一个简单的python小脚本

由于自己开发用的是macBook,所有很多时候都是用终端命令行,在进行一些日常操作,前几日正好需要输入终端的某一条命令,反复进行下去,实现循环执行功能。

用git下载文件到本地文件夹,想实时监测到下载的进度-和感受网络情况是否还不错,就需要循环监测下载到本地的文件大小是多少。

很简短的一段代码:

#usr/bin/python
#coding:utf-8

import os #系统函数模块
import time #时间函数模块

x = 1
while x<= 100000:
currentMB = os.system("du sh *")
print "已经下载%rM了哦!"%currentMB
print "哎哟不错哦!第%d次循环..."%x
print "\n"
time.sleep(10) #每间隔10秒,执行一次,文件大小变化效果看的较明显。
x += 1

说明:”du sh” 命令是macOS自带的系统命令,用来查看当前文件夹下每个文件的存储大小; 保存python文件,以.py结尾,拷贝此文件到所需要的文件夹目录,执行 python xxxx.py 即可。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK