Skip to content

Instantly share code, notes, and snippets.

View wynnzen's full-sized avatar
🍊
Focusing

wynnzen wynnzen

🍊
Focusing
View GitHub Profile
@wynnzen
wynnzen / gist:1e3b89e770e5d1da7feb
Last active August 29, 2015 14:00
relative path
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
@wynnzen
wynnzen / gist:2143cda66e2cf735595f
Last active August 29, 2015 14:00
python terminal progress
import sys
import time
# Output example: [======= ] 75%
# width defines bar width
# percent defines current percentage
def progress(width, percent):
print "%s %d%%\r" % (('%%-%ds' % width) % (width * percent / 100 * '='), percent),
if percent >= 100:
@wynnzen
wynnzen / gist:8838b610521e197cfc3b
Created May 5, 2014 02:24
判断value是否是none
if type(value) == type(None):
@wynnzen
wynnzen / gist:10c585a86c18bd39c644
Created May 5, 2014 02:26
字符串转换成数字
import string
a="12345"
string.atoi(a) #转整型
b="123.678"
string.atof(b) #转浮点数
@wynnzen
wynnzen / gist:651823a0779b64c13530
Created May 5, 2014 02:37
判断文件是否存在,并删除
if os.path.exists("test.log"):
os.remove("test.log")
@wynnzen
wynnzen / gist:746b00a0d045e2d6869c
Created May 5, 2014 02:38
格式化浮点位数输出
float("%.2f" %value)
#1.正则
strip("\r\n") #方法2
"".join(s.strip()) #方法3
#方法3的原理
'''
Return a list of the words of the string s.
If the optional second argument sep is absent or None,
import os
import os.path
import time
def adbcheck():
if "\tdevice\n" in os.popen("adb devices").read():
print "connected"
else:
while True:
print "phone is not connected,please check phone adb interface!"
@wynnzen
wynnzen / gist:ab4d0daf8346e9cb15d2
Last active August 29, 2015 14:01
判断一个activity是否运行
def judgeactivity():
actinfo =os.popen("adb shell dumpsys activity").readlines()
for i in actinfo:
if i.find("mFocusedActivity: ActivityRecord") > -1:
if i.find(r"com.googlecode.android_scripting/com.example.com") > -1:
return True
else:
return False
@wynnzen
wynnzen / setup.py
Created May 13, 2014 01:46
setup的demo
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from distutils.core import setup
try:
from distutils.command.build_py import build_py_2to3 as build_py
except ImportError:
# 2.x
from distutils.command.build_py import build_py